/* Copyright 2026 My Digital Sovereignty Ltd. All rights reserved. Proprietary and confidential; unauthorised copying, use or distribution is prohibited. */

/* email-decision-record-policy.css — the owner console's Policy tab
   (public/js/email-decision-record-policy.js draws every element styled here; the shell page
   public/email-decision-record.html links this file after navigation.css).

   Requires village-tokens.css loaded first: every colour, size, radius, shadow and duration is a
   token reference, so light, dark and AUTO themes all work with no [data-theme] selector here
   (village-components.css's own rule). Shapes follow the v-btn / v-input / v-card / v-badge
   patterns in village-components.css; the tab's JS emits plain elements without those classes,
   so the same shapes are applied by the tab's own class names instead.

   States are never colour alone: the chosen template card gets a heavier border AND a drawn tick;
   an error gets a bar at its left edge AND bold weight; the agent-drafted label is a pill with a
   dot AND its own words. Keyboard focus is a visible ring on every control. */

/* ---- The tab itself: a readable measure, side gutters down to 360px -------------------- */
#edr-policy-tab {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 var(--s-4) var(--s-7);
  overflow-wrap: anywhere;
}
#edr-policy-tab > h2 { font: var(--text-h1); margin: var(--s-5) 0 var(--s-3); }
#edr-policy-tab section { margin: var(--s-6) 0 0; }
#edr-policy-tab section > h2 { font: var(--text-h2); margin: 0 0 var(--s-3); }
#edr-policy-tab h3 { font: var(--text-h3); margin: var(--s-4) 0 var(--s-2); }
#edr-policy-tab p { margin: 0 0 var(--s-3); }
#edr-policy-tab ul { list-style: none; margin: 0; padding: 0; }

/* ---- Buttons: the v-btn shape. Cards are buttons too, so they are excluded here ---------- */
#edr-policy-tab button:not(.edr-policy-template-card) {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  min-height: 40px; padding: var(--s-2) var(--s-4);
  border-radius: var(--r-md);
  font-weight: 600; font-size: 15px;
  background: var(--raised);
  border: 1px solid var(--border-strong);
  color: var(--text);
  margin: var(--s-2) var(--s-2) var(--s-2) 0;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
#edr-policy-tab button:not(.edr-policy-template-card):hover { background: var(--sunken); }
#edr-policy-tab button:not(.edr-policy-template-card):focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}
/* The one primary action in each step */
.edr-policy-starter > button,
.edr-policy-suggestion > button,
.edr-policy-preview-button,
.edr-policy-adopt-button {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: var(--on-accent) !important;
}
.edr-policy-starter > button:hover,
.edr-policy-suggestion > button:hover,
.edr-policy-preview-button:hover,
.edr-policy-adopt-button:hover { background: var(--accent-hover) !important; border-color: var(--accent-hover) !important; }
#edr-policy-tab button[disabled] { opacity: .5; cursor: not-allowed; }
@media (pointer: coarse) {
  #edr-policy-tab button:not(.edr-policy-template-card) { min-height: 44px; }
}

/* ---- Step A: the starter box (describe what you want) ----------------------------------- */
.edr-policy-starter {
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin: 0 0 var(--s-5);
}
.edr-policy-starter > label {
  display: block;
  font: var(--text-small); font-weight: 600;
  margin: 0 0 var(--s-2);
}
.edr-policy-starter textarea {
  display: block; width: 100%;
  min-height: 96px; padding: 10px 14px;
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font: inherit; font-size: 15px;
  resize: vertical;
  margin: 0 0 var(--s-2);
}
.edr-policy-starter textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--accent); }

/* The suggestion panel: a raised card with the accent bar, the same shape as v-card--accent */
.edr-policy-suggestion {
  background: var(--raised);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-lg);
  box-shadow: var(--e-1);
  padding: var(--s-4);
  margin: var(--s-3) 0 0;
}
.edr-policy-suggestion > strong {
  display: block;
  font: var(--text-h3);
  margin: 0 0 var(--s-2);
}
.edr-policy-suggestion > strong:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.edr-policy-suggestion > p { margin: 0 0 var(--s-2); }

/* ---- Step A: the compile box and its result (EDR 7.2 slice 9) ---------------------------- */
.edr-policy-compile-fields {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0 var(--s-4);
}
.edr-policy-compile-fields > .edr-policy-field { margin: 0 0 var(--s-2); min-width: 0; }
.edr-policy-compile-result h3 { margin: var(--s-4) 0 var(--s-2); }
.edr-policy-compile-card > strong { font-weight: 700; }
#edr-policy-tab .edr-policy-compile-list {
  list-style: disc;
  padding: 0 0 0 var(--s-5);
  margin: 0 0 var(--s-3);
}
.edr-policy-compile-list > li { margin: 0 0 var(--s-1); }
.edr-policy-compile-probe {
  display: inline-block;
  margin: 0 0 0 var(--s-2);
  padding: 1px 8px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--on-accent-soft);
  font: var(--text-small); font-weight: 600; font-size: 13px;
}
.edr-policy-compile-refusal { margin: 0 0 var(--s-3); }
.edr-policy-considered-list > li {
  border-top: 1px solid var(--border);
  padding: var(--s-3) 0;
}
.edr-policy-considered-list > li:first-child { border-top: 0; }
.edr-policy-considered-list .edr-policy-checkbox { align-items: flex-start; margin: 0 0 var(--s-2); }
.edr-policy-considered-list .edr-policy-checkbox input[type="checkbox"] { margin-top: 2px; }
/* The cited entry sits under its tick box, indented past the box so the two read as one item */
.edr-policy-citation {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-1);
  margin: 0 0 0 calc(20px + var(--s-2));
  font: var(--text-small);
}
.edr-policy-citation-prefix { color: var(--muted); }
.edr-policy-citation > strong { font-weight: 600; }
.edr-policy-citation-source { overflow-wrap: anywhere; }
a.edr-policy-citation-source { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
a.edr-policy-citation-source:hover { color: var(--accent-hover); }
a.edr-policy-citation-source:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
/* Range review item 2: every cited entry, listed on its own, above the tick list */
.edr-policy-related-list { list-style: none; padding: 0; margin: 0 0 var(--s-3); }
.edr-policy-related-list > li { border-top: 1px solid var(--border); padding: var(--s-3) 0; }
.edr-policy-related-list > li:first-child { border-top: 0; }
.edr-policy-related-list .edr-policy-citation { margin-left: 0; }
.edr-policy-considered-list { list-style: none; padding: 0; }
.edr-policy-considered-source {
  display: block;
  margin: 0 0 0 calc(20px + var(--s-2));
  font: var(--text-small);
  color: var(--muted);
}

/* ---- Step A: the template cards (role=radio buttons in a role=radiogroup) --------------- */
.edr-policy-template-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--s-3);
  margin: 0 0 var(--s-3);
}
.edr-policy-template-card {
  position: relative;
  display: flex; flex-direction: column; gap: var(--s-2);
  min-width: 0;
  text-align: left;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e-1);
  padding: var(--s-4) calc(var(--s-4) + 28px) var(--s-4) var(--s-4);
  color: var(--text);
  font: var(--text-body);
  transition: box-shadow var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.edr-policy-template-card:hover { box-shadow: var(--e-2); border-color: var(--border-strong); }
.edr-policy-template-card:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.edr-policy-template-card > strong { font-weight: 700; font-size: 17px; line-height: 1.3; }
.edr-policy-template-card > span { color: var(--muted); font: var(--text-small); }

/* The radio mark: an empty ring on every card, a filled disc with a drawn tick on the chosen one */
.edr-policy-template-card::before {
  content: "";
  position: absolute; top: var(--s-4); right: var(--s-4);
  width: 22px; height: 22px;
  border: 2px solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--raised);
}
.edr-policy-template-card::after {
  content: "";
  display: none;
  position: absolute; top: calc(var(--s-4) + 6px); right: calc(var(--s-4) + 6px);
  width: 10px; height: 6px;
  border-left: 2px solid var(--on-accent);
  border-bottom: 2px solid var(--on-accent);
  transform: rotate(-45deg);
}
.edr-policy-template-card.is-selected,
.edr-policy-template-card[aria-checked="true"] {
  border: 2px solid var(--accent);
  /* 1px more border on every side, 1px less padding: the card does not move when chosen */
  padding: calc(var(--s-4) - 1px) calc(var(--s-4) + 27px) calc(var(--s-4) - 1px) calc(var(--s-4) - 1px);
  box-shadow: var(--e-2);
}
.edr-policy-template-card.is-selected > strong,
.edr-policy-template-card[aria-checked="true"] > strong { color: var(--accent); }
.edr-policy-template-card.is-selected::before,
.edr-policy-template-card[aria-checked="true"]::before {
  top: calc(var(--s-4) - 1px); right: calc(var(--s-4) - 1px);
  background: var(--accent); border-color: var(--accent);
}
.edr-policy-template-card.is-selected::after,
.edr-policy-template-card[aria-checked="true"]::after {
  display: block;
  top: calc(var(--s-4) + 5px); right: calc(var(--s-4) + 5px);
}

/* The agent-drafted label: the v-badge--warn shape (soft fill, AA text, dot), never italic */
.edr-policy-authorship,
.edr-policy-citation-label {
  display: inline-flex; align-items: flex-start; gap: 6px;
  align-self: flex-start;
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: var(--warn-soft);
  color: var(--warn);
  font: var(--text-small); font-weight: 600; font-size: 13px; font-style: normal;
  line-height: 1.35;
}
.edr-policy-authorship::before,
.edr-policy-citation-label::before {
  content: "";
  flex: none;
  margin-top: 5px; /* on the first line when the label wraps, not floating between two */
  width: 7px; height: 7px;
  border-radius: var(--r-full);
  background: currentColor;
}

/* ---- Notes, errors, success, the live policy sentence ----------------------------------- */
.edr-policy-note { color: var(--muted); font: var(--text-small); }
.edr-policy-error {
  color: var(--danger);
  font-weight: 600;
  border-left: 3px solid var(--danger);
  padding: var(--s-1) 0 var(--s-1) var(--s-3);
  margin: var(--s-2) 0 var(--s-3);
}
.edr-policy-error:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.edr-policy-success {
  color: var(--success);
  font-weight: 600;
  border-left: 3px solid var(--success);
  padding: var(--s-1) 0 var(--s-1) var(--s-3);
}
.edr-policy-live-region,
.edr-policy-adopter-preview {
  background: var(--accent-soft);
  color: var(--on-accent-soft);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin: 0 0 var(--s-4);
}
.edr-policy-live-region:empty { display: none; }

/* ---- Steps B and C: fields, the v-input shape ------------------------------------------- */
.edr-policy-field {
  display: flex; flex-direction: column; gap: 6px;
  margin: 0 0 var(--s-4);
}
.edr-policy-field > span { font: var(--text-small); font-weight: 600; }
.edr-policy-field input:not([type="checkbox"]),
.edr-policy-field select {
  width: 100%; height: 44px;
  padding: 0 14px;
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font: inherit; font-size: 15px;
}
.edr-policy-field input:focus-visible,
.edr-policy-field select:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--accent); }
.edr-policy-field input::placeholder { color: var(--muted); opacity: 1; }
.edr-policy-checkbox {
  flex-direction: row; align-items: center; gap: var(--s-2);
  font: var(--text-body);
}
.edr-policy-checkbox input[type="checkbox"] {
  width: 20px; height: 20px; flex: none; margin: 0;
  accent-color: var(--accent);
}
.edr-policy-checkbox input[type="checkbox"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.edr-policy-owner-typed-row {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-3) var(--s-4) 0;
  margin: 0 0 var(--s-3);
  min-width: 0;
}
.edr-policy-owner-typed-row > legend { font-weight: 600; padding: 0 var(--s-2); }

/* Preview results: each example says its outcome in words; the bar and badge only echo it */
.edr-policy-example-list { margin: var(--s-3) 0 var(--s-4); }
.edr-policy-example {
  background: var(--raised);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin: 0 0 var(--s-2);
}
.edr-policy-example > strong { display: inline-block; margin: 0 var(--s-2) var(--s-1) 0; }
.edr-policy-example > p { margin: var(--s-1) 0 0; color: var(--muted); font: var(--text-small); }
.edr-policy-example-outcome {
  display: inline-flex; align-items: center;
  padding: 2px 10px;
  border-radius: var(--r-full);
  font: var(--text-small); font-weight: 600; font-size: 13px;
  background: var(--sunken); color: var(--muted);
}
.edr-policy-example-sent { border-left-color: var(--success); }
.edr-policy-example-sent .edr-policy-example-outcome { background: var(--success-soft); color: var(--success); }
.edr-policy-example-waits { border-left-color: var(--warn); }
.edr-policy-example-waits .edr-policy-example-outcome { background: var(--warn-soft); color: var(--warn); }
.edr-policy-example-refused { border-left-color: var(--danger); }
.edr-policy-example-refused .edr-policy-example-outcome { background: var(--danger-soft); color: var(--danger); }

/* ---- Versions and approvers ------------------------------------------------------------- */
.edr-policy-adoption-row,
.edr-policy-approver-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2);
  padding: var(--s-3) 0;
  border-top: 1px solid var(--border);
}
.edr-policy-adoption-row:first-child,
.edr-policy-approver-row:first-child { border-top: 0; }
.edr-policy-approver-row > span { flex: 1 1 160px; min-width: 0; }
#edr-policy-tab .edr-policy-approver-revoke { margin: 0; min-height: 36px; padding: var(--s-1) var(--s-3); }

/* ---- Narrow screens ----------------------------------------------------------------------- */
@media (max-width: 560px) {
  #edr-policy-tab > h2 { font-size: 24px; }
  .edr-policy-template-cards { grid-template-columns: 1fr; }
  .edr-policy-compile-fields { grid-template-columns: minmax(0, 1fr); }
  .edr-policy-citation { margin-left: 0; }
  #edr-policy-tab button:not(.edr-policy-template-card):not(.edr-policy-approver-revoke) { width: 100%; margin-right: 0; }
}

/* ---- Reduced motion: no hover lift, matching village-components.css ----------------------- */
@media (prefers-reduced-motion: reduce) {
  .edr-policy-template-card:hover { box-shadow: var(--e-1); }
}
