/* ============================================================
   USP&E Signatures — admin portal design system
   Segoe-first (native to the M365 world this tool lives in),
   USP&E blue accent, light/dark via tokens only.
   ============================================================ */

:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-alt: #f4f7fb;
  --sunken: #e8edf4;
  --border: #d9e1ea;
  --border-strong: #c2cedb;
  --text: #16212e;
  --text-2: #45566b;
  --muted: #6b7c92;
  --accent: #0f6cbd;
  --accent-hover: #0c5aa0;
  --accent-soft: #e3eef8;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-soft: #fbeae9;
  --ok: #0a7c42;
  --ok-soft: #e3f3ea;
  --warn: #9a6700;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-1: 0 1px 2px rgba(22, 33, 46, 0.05);
  --shadow-2: 0 1px 3px rgba(22, 33, 46, 0.06), 0 8px 24px rgba(22, 33, 46, 0.07);
  --topbar-h: 58px;
  --sidebar-w: 288px;
  --font: 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-display: 'Segoe UI Variable Display', 'Segoe UI', system-ui, sans-serif;
  --mono: 'Cascadia Code', 'Cascadia Mono', Consolas, 'SF Mono', ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #171e27;
    --surface-alt: #1d2733;
    --sunken: #0c1117;
    --border: #2a3644;
    --border-strong: #3a4a5d;
    --text: #e7edf4;
    --text-2: #a9b8c9;
    --muted: #7d8fa3;
    --muted: #7d8fa3;
    --accent: #4ea1f0;
    --accent-hover: #6cb2f4;
    --accent-soft: #14283c;
    --accent-text: #0a1017;
    --danger: #f97066;
    --danger-soft: #351b19;
    --ok: #4ade80;
    --ok-soft: #12291b;
    --warn: #eac54f;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-2: 0 1px 3px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
h1 { font-size: 17px; font-weight: 600; }
h2 { font-size: 14px; font-weight: 600; }

p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); }
.ok { color: var(--ok); }
[hidden] { display: none !important; }

/* ------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-h);
  padding: 0 20px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 20px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.brand img { width: 26px; height: 26px; display: block; }
.brand .divider { color: var(--border-strong); font-weight: 400; }
.brand .product { color: var(--text-2); font-weight: 500; }

.mainnav { display: flex; gap: 2px; height: 100%; }
.mainnav a {
  display: flex;
  align-items: center;
  padding: 0 16px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.mainnav a:hover { color: var(--text); background: var(--surface-alt); }
.mainnav a[aria-current='true'] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: 12.5px; margin-right: 4px; }

/* ------------------------------------------------ shell */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: 1fr;   /* the row itself fills the shell, not just its content */
  flex: 1 0 auto;            /* shell grows to fill the viewport below the top bar */
  min-height: calc(100vh - var(--topbar-h));
  align-items: stretch;      /* sidebar + content both run the full height of the row */
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 10px 6px;
}
.sidebar-gap { height: 14px; }

.navitem {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.navitem:hover { background: var(--surface-alt); }
.navitem[aria-current='true'] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.navitem .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navitem .count {
  font-size: 11.5px;
  color: var(--muted);
  background: var(--sunken);
  border-radius: 999px;
  padding: 1px 8px;
  font-variant-numeric: tabular-nums;
}
.navitem[aria-current='true'] .count { background: color-mix(in srgb, var(--accent) 14%, transparent); color: inherit; }

main.content { padding: 22px 26px 60px; min-width: 0; }
#view-templates .card-body input[type='text'],
#view-templates .card-body input[type='search'],
#view-templates textarea.code { max-width: 900px; }
/* Use the full page width; only the template editor's own text inputs are
   capped (below) so long lines stay readable. */
.content-inner { max-width: none; width: 100%; }

/* ------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 18px; }
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }

/* ------------------------------------------------ forms */

label { display: block; font-weight: 600; font-size: 12.5px; color: var(--text-2); margin: 14px 0 5px; }
label:first-child { margin-top: 0; }

input[type='text'], input[type='search'], textarea, select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  transition: border-color 0.12s, background 0.12s;
}
input:hover, textarea:hover { border-color: var(--border-strong); }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input:focus, textarea:focus { background: var(--surface); }

textarea.code {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  min-height: 300px;
  resize: vertical;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  tab-size: 2;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.actions.tight { margin-top: 0; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-alt); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border-strong)); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }

/* ------------------------------------------------ badges & pills */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--sunken);
  color: var(--muted);
  vertical-align: 1px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.badge.published, .badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.default { background: var(--accent-soft); color: var(--accent); }
.badge.draft { background: var(--sunken); color: var(--warn); }
.badge.plain::before { display: none; }

/* ------------------------------------------------ tables */

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
table.data td { font-variant-numeric: tabular-nums; }
table.data tbody tr:last-child td { border-bottom: 0; }
.rowlink tbody tr { cursor: pointer; }
.rowlink tbody tr:hover { background: var(--surface-alt); }
.rowlink tbody tr[aria-selected='true'] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.table-scroll { max-height: 480px; overflow-y: auto; border-radius: 0 0 var(--radius) var(--radius); }

/* ------------------------------------------------ tokens grid */

.tokens { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 6px; }
.tokens button {
  font: inherit;
  text-align: left;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  cursor: pointer;
  color: inherit;
  transition: border-color 0.12s;
}
.tokens button:hover { border-color: var(--accent); }
.tokens code { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.tokens span { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ------------------------------------------------ signature preview */

.preview {
  background: #ffffff;
  color: #1f2937;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  overflow-x: auto;
  max-width: 720px;   /* an email signature is ~650px wide; frame it, don't stretch it */
}
.preview:empty::after { content: '— nothing to preview —'; color: #9aa5b1; font-size: 12.5px; }

/* ------------------------------------------------ misc */

.list { list-style: none; margin: 0; padding: 0; }
.gate-wrap { display: grid; place-items: center; min-height: calc(100vh - var(--topbar-h)); padding: 24px; }
.gate { max-width: 400px; text-align: center; padding: 36px; }
.gate img { width: 52px; height: 52px; margin-bottom: 14px; }
.gate h1 { margin-bottom: 6px; }
.gate p { color: var(--muted); margin-bottom: 20px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  padding: 11px 15px;
  font-size: 13px;
}
.toast.bad { border-left-color: var(--danger); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  box-shadow: var(--shadow-1);
}
.kpi .n { font-family: var(--font-display); font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); flex-direction: row; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ------------------------------------------------ task pane & static pages (Outlook add-in) */

.pane { background: var(--bg); }
.pane-body { padding: 16px; max-width: 760px; }
.pane-body .actions { margin: 14px 0; }

/* ------------------------------------------------ collapsible sections */
details.fold { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
details.fold:first-of-type { border-top: 0; padding-top: 0; }
details.fold > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  user-select: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 10px;
  transition: transform 0.12s;
}
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > summary + * { margin-top: 10px; }

/* Compact placeholder chips */
.tokens.compact { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.tokens.compact button { padding: 4px 8px; }
.tokens.compact code { font-size: 11px; }
.tokens.compact span { display: none; }
.tokens.compact button:hover span {
  display: block;
  position: absolute;
  margin-top: 2px;
  background: var(--text);
  color: var(--surface);
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 11px;
  white-space: nowrap;
  z-index: 5;
}
.tokens.compact button { position: relative; }
