/* Army Memorandum Generator - application chrome.
   The memo preview itself is styled by js/preview.js so its geometry stays exact. */

:root {
  --bg: #ecede6;
  --panel: #ffffff;
  --panel-2: #f4f5ef;
  --ink: #1b1e16;
  --ink-2: #454a3c;
  --muted: #6d7361;
  --line: #d2d5c8;
  --line-strong: #b9bdae;
  --accent: #3b4826;        /* deep olive: primary actions */
  --accent-hover: #4a5a30;
  --accent-ink: #ffffff;
  --brass: #9a7b2c;         /* focus ring, eyebrows, small emphasis */
  --brass-soft: #f1e8cf;
  --ok: #3b6b3a;
  --warn: #9d6410;
  --warn-soft: #fbefd7;
  --err: #a13a2c;
  --err-soft: #f8e1dc;
  --info: #2f5b86;
  --info-soft: #e1ebf5;
  --shadow: 0 1px 2px rgba(20, 24, 12, .06), 0 8px 24px -16px rgba(20, 24, 12, .25);
  --radius: 8px;
  --radius-sm: 5px;
  --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14160f; --panel: #1d2017; --panel-2: #24281d; --ink: #e6e7dc; --ink-2: #c4c7b7; --muted: #8e937f;
    --line: #363b2d; --line-strong: #4a5040; --accent: #a7b86a; --accent-hover: #b9c97e; --accent-ink: #14160f;
    --brass: #d3b566; --brass-soft: #33301f; --ok: #8fc48a; --warn: #e0a84a; --warn-soft: #3a2e14; --err: #e88a7c; --err-soft: #3d1f1a;
    --info: #86b2e0; --info-soft: #1d2b3a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -16px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14160f; --panel: #1d2017; --panel-2: #24281d; --ink: #e6e7dc; --ink-2: #c4c7b7; --muted: #8e937f;
  --line: #363b2d; --line-strong: #4a5040; --accent: #a7b86a; --accent-hover: #b9c97e; --accent-ink: #14160f;
  --brass: #d3b566; --brass-soft: #33301f; --ok: #8fc48a; --warn: #e0a84a; --warn-soft: #3a2e14; --err: #e88a7c; --err-soft: #3d1f1a;
  --info: #86b2e0; --info-soft: #1d2b3a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -16px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; margin-right: auto; }
.brand h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.brand .sub { color: var(--muted); font-size: 12.5px; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink); cursor: pointer; line-height: 1.2;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.small { padding: 4px 8px; font-size: 12.5px; }
.btn.icon { padding: 4px 7px; min-width: 28px; justify-content: center; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .55; cursor: default; }

/* -------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: minmax(360px, 520px) minmax(0, 1fr); gap: 20px; padding: 18px 16px 40px; max-width: 1480px; margin: 0 auto; }
.workbench { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stage { min-width: 0; }
.stage-inner { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 66px); }
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .stage-inner { position: static; }
}

/* ---------------------------------------------------------------- cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > summary, .card-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; list-style: none; user-select: none;
  border-bottom: 1px solid transparent;
}
.card[open] > summary { border-bottom-color: var(--line); }
.card > summary::-webkit-details-marker { display: none; }
.card > summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
.card[open] > summary::after { transform: rotate(45deg); }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--brass); }
.card-title { font-weight: 600; font-size: 14px; }
.card-note { color: var(--muted); font-size: 12px; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 12px; }

/* --------------------------------------------------------------- fields */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; align-items: baseline; gap: 6px; }
.field .ref { color: var(--muted); font-weight: 400; font-size: 11.5px; margin-left: auto; }
.hint { color: var(--muted); font-size: 12px; }
input[type="text"], input[type="date"], select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--panel); color: var(--ink);
}
textarea { resize: vertical; min-height: 60px; line-height: 1.4; }
textarea.grow { min-height: 38px; overflow: hidden; resize: none; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 520px) { .row, .row.three { grid-template-columns: 1fr; } }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.check input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg label { padding: 6px 10px; cursor: pointer; font-size: 13px; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--ink); font-weight: 600; }
.seg label:has(input:checked) { background: var(--brass-soft); }
.profile-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.profile-bar select { flex: 1 1 160px; width: auto; }

/* ----------------------------------------------------- paragraph editor */
.para-list { display: flex; flex-direction: column; gap: 6px; }
.para-row { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 8px; align-items: start; }
.para-row .badge {
  display: inline-flex; justify-content: center; align-items: center; height: 34px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.para-row[data-level="2"] { padding-left: 16px; }
.para-row[data-level="3"] { padding-left: 32px; }
.para-row[data-level="4"] { padding-left: 32px; }
.para-row .tools { display: flex; gap: 3px; }
.para-row.flagged textarea { border-color: var(--warn); }
.para-help { font-size: 12px; color: var(--muted); }
kbd { font: 11.5px/1 var(--font-ui); padding: 2px 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--panel-2); }

/* ---------------------------------------------------------------- issues */
.issues { display: flex; flex-direction: column; gap: 6px; }
.issue { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: start; padding: 7px 9px; border-radius: var(--radius-sm); font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--line); }
.issue .pill { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; border-radius: 999px; }
.issue.error { background: var(--err-soft); border-color: transparent; } .issue.error .pill { background: var(--err); color: #fff; }
.issue.warn { background: var(--warn-soft); border-color: transparent; } .issue.warn .pill { background: var(--warn); color: #fff; }
.issue.info { background: var(--info-soft); border-color: transparent; } .issue.info .pill { background: var(--info); color: #fff; }
.issue .ref { color: var(--muted); white-space: nowrap; font-size: 11.5px; }
.issues-empty { color: var(--ok); font-size: 13px; display: flex; gap: 6px; align-items: center; }

/* ---------------------------------------------------------------- stage */
.stage-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.stage-bar .meta { color: var(--muted); font-size: 12.5px; }
.stage-bar .spacer { flex: 1; }
.preview-wrap { overflow: auto; max-height: calc(100vh - 150px); padding: 4px 2px 12px; }
@media (max-width: 980px) { .preview-wrap { max-height: none; } }
.status { font-size: 12.5px; color: var(--muted); min-height: 1.4em; }
.status.ok { color: var(--ok); } .status.err { color: var(--err); }

/* ------------------------------------------------------------- dialogs */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); padding: 0; max-width: min(560px, 94vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 12, 6, .45); }
dialog .dlg { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 16px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }
.list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.list-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { color: var(--muted); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.privacy { display: flex; gap: 8px; align-items: flex-start; padding: 10px 14px; font-size: 12.5px; color: var(--ink-2); background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); }
.privacy strong { color: var(--ink); }
.seal-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 24px; }
.seal-thumb { width: 44px; height: 44px; border: 1px dashed var(--line-strong); border-radius: 50%; object-fit: contain; background: #fff; }
.dlg-text { margin: 0; color: var(--ink-2); }

/* ------------------------------------------------------------ templates */
.tpl-banner { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--brass-soft); border: 1px solid var(--line); }
.tpl-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.tpl-fields .field.wide { grid-column: 1 / -1; }
@media (max-width: 520px) { .tpl-fields { grid-template-columns: 1fr; } }
.req { color: var(--err); font-weight: 700; }
.field.missing input, .field.missing textarea, .field.missing select { border-color: var(--err); }
.locked input, .locked textarea, .para-row.locked textarea { background: var(--panel-2); color: var(--ink-2); }
.para-row.locked .tools { visibility: hidden; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
