/* ResearchPie Admin. Mirrors the Mac app: the Color.Theme palette, Avenir
   type scale, sand sidebar, white cards, and capsule buttons. Follows the
   system appearance, like the app. */

:root {
  color-scheme: light dark;
  --sand: #E7D3AB;        /* appBackground1 */
  --sand-deep: #DAC08D;   /* appBackground2 */
  --cream: #F8F1E5;       /* appBackground3 */
  --card: #FFFFFF;        /* appBackground4 */
  --ink: #333030;         /* typography1 */
  --ink-2: #5F5959;       /* typography2 */
  --ink-3: #9C9696;       /* typography3 */
  --ink-4: #CECACA;       /* typography4 */
  --accent: #CC444B;      /* accentColor1 */
  --accent-2: #E68B89;    /* accentColor2 */
  --accent-soft: #F0BCBC; /* accentColor4 */
  --positive: #3F7A57;
  --caution: #9A6218;
  --line: color-mix(in srgb, var(--ink-4) 70%, transparent);
  --focus: color-mix(in srgb, var(--accent) 35%, transparent);
  --font-book: "Avenir-Book", "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  --font-roman: "Avenir-Roman", "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  --font-medium: "Avenir-Medium", "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  --font-heavy: "Avenir-Heavy", "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sand: #2C251C;
    --sand-deep: #3B3023;
    --cream: #191715;
    --card: #24211E;
    --ink: #F5EEE6;
    --ink-2: #CEC4BA;
    --ink-3: #9F968E;
    --ink-4: #665F59;
    --accent: #E05A62;
    --accent-2: #F08F92;
    --accent-soft: #593137;
    --positive: #8CC5A4;
    --caution: #E2BB77;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--cream); }
body { margin: 0; min-width: 320px; min-height: 100vh; overflow-x: hidden; background: var(--cream); color: var(--ink); font-family: var(--font-book); font-size: 15px; line-height: 1.45; font-synthesis: none; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-family: var(--font-heavy); font-weight: 800; letter-spacing: 0; }
strong, b { font-family: var(--font-medium); font-weight: 500; }
button, input, select, textarea { font-family: var(--font-roman); font-size: inherit; }
button { color: inherit; }
svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: fixed; z-index: 100; top: 10px; left: 10px; padding: 10px 16px; border-radius: 999px; background: var(--card); color: var(--accent); transform: translateY(-150%); }
.skip-link:focus { transform: none; }
.eyebrow, .dialog-eyebrow { margin: 0; color: var(--ink-2); font-size: 13px; text-transform: capitalize; }

/* Sign-in gate */
.gate { display: grid; width: min(440px, calc(100% - 36px)); min-height: 100vh; align-content: center; justify-items: center; margin: auto; text-align: center; }
.gate-logo img { display: block; width: 88px; height: 88px; margin-bottom: 18px; }
.gate h1 { margin-bottom: 8px; font-size: 28px; line-height: 1.2; }
.gate > p { max-width: 360px; margin: 0 0 24px; color: var(--ink-2); font-size: 16px; }

/* Sidebar */
.sidebar { position: fixed; z-index: 50; inset: 0 auto 0 0; display: flex; width: 252px; flex-direction: column; padding: 20px 12px 14px; overflow-y: auto; background: var(--sand); }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 10px 14px; color: var(--ink); text-decoration: none; }
.brand img { display: block; width: 36px; height: 36px; }
.brand > span { display: grid; line-height: 1.15; }
.brand b { color: var(--accent); font-family: var(--font-heavy); font-size: 18px; font-weight: 800; }
.brand small { color: var(--ink-2); font-size: 13px; }
.sidebar nav { flex: 1; }
.sidebar nav > p { margin: 18px 12px 6px; color: var(--ink-2); font-family: var(--font-medium); font-size: 12px; }
.nav { display: flex; width: 100%; min-height: 38px; align-items: center; gap: 11px; margin: 2px 0; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--ink); cursor: pointer; font-size: 15px; text-align: left; }
.nav svg { width: 18px; height: 18px; flex: none; color: var(--ink-2); }
.nav:hover { background: color-mix(in srgb, var(--sand-deep) 55%, transparent); }
.nav.active { background: var(--sand-deep); font-family: var(--font-medium); }
.nav.active svg { color: var(--accent); }
.environment { display: flex; align-items: center; gap: 8px; margin: 14px 12px 6px; color: var(--ink-2); font-size: 13px; }
.environment i { width: 8px; height: 8px; border-radius: 50%; background: var(--positive); }
.environment.is-local i { background: var(--caution); }
.profile { display: grid; grid-template-columns: 34px minmax(0, 1fr) 18px; align-items: center; gap: 10px; padding: 10px 8px 2px; border: 0; border-top: 1px solid color-mix(in srgb, var(--ink) 12%, transparent); background: transparent; color: var(--ink); cursor: pointer; text-align: left; }
.profile > span:nth-child(2) { display: grid; min-width: 0; }
.profile strong, .profile small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile strong { font-size: 14px; }
.profile small { color: var(--ink-2); font-size: 12px; text-transform: capitalize; }
.profile svg { width: 17px; height: 17px; color: var(--ink-2); }
.profile:hover svg { color: var(--accent); }
.avatar { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; background: var(--accent); color: #fff; font-family: var(--font-medium); font-size: 13px; }

/* Workspace */
.workspace { min-height: 100vh; margin-left: 252px; }
.topbar { position: sticky; z-index: 30; top: 0; display: flex; height: 60px; align-items: center; gap: 12px; padding: 0 clamp(20px, 4vw, 48px); background: color-mix(in srgb, var(--cream) 92%, transparent); backdrop-filter: blur(16px); }
.topbar-title { font-size: 15px; }
.topbar #refresh { margin-left: auto; }
.menu { display: none !important; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--ink-2); cursor: pointer; font-size: 18px; line-height: 1; }
.icon-button svg { width: 18px; height: 18px; }
.icon-button:hover { background: var(--sand); color: var(--ink); }

.button { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; gap: 7px; padding: 0 18px; border: 0; border-radius: 999px; cursor: pointer; font-family: var(--font-medium); font-size: 15px; white-space: nowrap; transition: background 120ms ease, transform 120ms ease; }
.button svg { width: 16px; height: 16px; }
.button:active:not(:disabled) { transform: scale(.98); }
.button:disabled { opacity: .5; cursor: wait; }
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }
.button.secondary { background: var(--sand); color: var(--ink); }
.button.secondary:hover:not(:disabled) { background: var(--sand-deep); }
.text-button { padding: 4px 0; border: 0; background: transparent; color: var(--accent); cursor: pointer; font-family: var(--font-medium); font-size: 14px; }

main { max-width: 1240px; margin: 0 auto; padding: 16px clamp(20px, 4vw, 48px) 80px; }
.view { animation: view-in 160ms ease both; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; margin-bottom: 24px; }
.heading h1 { font-size: 28px; line-height: 1.2; }
.heading > div > p { margin: 6px 0 0; color: var(--ink-2); font-size: 16px; }
.range { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; }
.range select { min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink); font-size: 14px; }
.note { margin: -8px 0 18px; color: var(--ink-2); font-size: 14px; }

.notice { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; padding: 12px 16px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-size: 14px; }
.notice span { flex: 1; color: var(--ink); }
.notice button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 18px; }

/* Attention and overall status */
.attention, .overall-status { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; padding: 16px 18px; border-radius: 14px; background: var(--card); }
.attention > span, .overall-status > span:first-child { display: grid; width: 32px; height: 32px; flex: none; place-items: center; border-radius: 50%; background: color-mix(in srgb, var(--positive) 16%, transparent); color: var(--positive); font-family: var(--font-heavy); font-size: 14px; }
.attention.warning > span, .overall-status.warning > span:first-child { background: var(--accent); color: #fff; }
.attention > div, .overall-status > div { flex: 1; }
.attention strong { font-size: 16px; }
.overall-status h2 { font-size: 18px; }
.attention p, .overall-status p { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }

/* Metrics and panels */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.metric { padding: 18px 20px; border-radius: 14px; background: var(--card); }
.metric > span { color: var(--ink-2); font-size: 14px; }
.metric strong { display: block; margin: 6px 0 2px; font-family: var(--font-heavy); font-size: 28px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.metric small { color: var(--ink-3); font-size: 13px; }
.two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.panel, .card { border-radius: 14px; background: var(--card); }
.panel { padding: 22px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.panel-heading.padded { padding: 22px 22px 6px; }
.panel-heading h2, .card h2 { font-size: 18px; }
.panel-heading p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.activity { margin-top: 10px; }
.activity-item { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.activity-item:last-child { border-bottom: 0; }
.activity-icon { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; background: var(--sand); color: var(--ink); font-family: var(--font-medium); font-size: 13px; }
.activity-item p { margin: 0; font-size: 15px; }
.activity-item small { color: var(--ink-3); font-size: 13px; }

/* Schools table */
.summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.summary > div { display: grid; gap: 2px; padding: 16px 18px; border-radius: 14px; background: var(--card); }
.summary span { color: var(--ink-2); font-size: 14px; }
.summary strong { font-family: var(--font-heavy); font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.summary small { color: var(--ink-3); font-size: 13px; }
.table-panel { padding: 0; overflow: hidden; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.field-search { display: flex; width: min(320px, 100%); min-height: 36px; align-items: center; gap: 8px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--cream); color: var(--ink-3); }
.field-search svg { width: 16px; height: 16px; flex: none; }
.field-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 14px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 12px 18px 10px; border-bottom: 1px solid var(--line); color: var(--ink-2); font-family: var(--font-medium); font-size: 13px; font-weight: 500; text-align: left; white-space: nowrap; }
td { padding: 12px 18px; border-bottom: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; vertical-align: middle; }
td > small { display: block; color: var(--ink-3); font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--sand) 22%, transparent); }
td strong { color: var(--ink); }
.table-title { display: grid; min-width: 180px; gap: 1px; }
.table-title strong { font-size: 15px; }
.table-title small { color: var(--ink-3); font-size: 12px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border: 0; border-radius: 999px; background: var(--sand); color: var(--ink-2); font-family: var(--font-medium); font-size: 13px; text-transform: capitalize; white-space: nowrap; }
button.badge { cursor: pointer; }
button.badge:hover { box-shadow: inset 0 0 0 1px currentColor; }
.badge::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; }
.badge.active, .badge.operational, .badge.published, .badge.required, .badge.completed, .badge.paid { background: color-mix(in srgb, var(--positive) 14%, transparent); color: var(--positive); }
.badge.scheduled, .badge.preview, .badge.draft, .badge.trialing, .badge.pending { background: var(--sand); color: var(--ink-2); }
.badge.warning, .badge.past_due, .badge.unpaid, .badge.degraded, .badge.paused, .badge.investigating, .badge.identified, .badge.monitoring { background: color-mix(in srgb, var(--caution) 16%, transparent); color: var(--caution); }
.badge.revoked, .badge.failed, .badge.major_outage, .badge.partial_outage, .badge.suspended { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.warning-text { display: block; color: var(--accent); font-family: var(--font-medium); font-size: 12px; }
.empty { margin: 0; padding: 36px; color: var(--ink-3); font-size: 15px; text-align: center; }

/* Analytics */
.funnel, .bars { display: grid; gap: 10px; margin-top: 18px; }
.funnel-row { display: flex; width: var(--width); min-width: 45%; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 12%, var(--card)); font-size: 14px; }
.funnel-row strong { font-family: var(--font-heavy); font-size: 16px; }
.bar { display: grid; grid-template-columns: 140px minmax(0, 1fr) 72px; align-items: center; gap: 12px; font-size: 14px; }
.bar > span { overflow: hidden; color: var(--ink-2); text-overflow: ellipsis; white-space: nowrap; }
.bar > div { height: 8px; overflow: hidden; border-radius: 999px; background: var(--sand); }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.bar b { color: var(--ink-2); font-size: 13px; text-align: right; }

/* Policies and releases */
.card-list { display: grid; gap: 12px; }
.card { padding: 22px; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card h2 { margin-top: 8px; }
.card h2 small { color: var(--ink-3); font-family: var(--font-book); font-size: 15px; font-weight: 400; }
.card > p { margin: 6px 0 16px; color: var(--ink-2); font-size: 15px; }
.meta { display: flex; flex-wrap: wrap; gap: 12px 32px; }
.meta span { display: grid; gap: 1px; }
.meta small { color: var(--ink-3); font-size: 13px; }
.meta strong { font-size: 15px; }
.card-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.rollout { margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: var(--cream); }
.rollout > div:first-child { display: flex; justify-content: space-between; font-size: 14px; }
.rollout small { color: var(--ink-3); font-size: 13px; overflow-wrap: anywhere; }
.progress { height: 8px; margin: 8px 0; overflow: hidden; border-radius: 999px; background: var(--sand); }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

/* Service status */
.components, .incidents { margin-top: 10px; }
.component, .incident { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.component:last-child, .incident:last-child { border-bottom: 0; }
.component > div, .incident > div { display: grid; gap: 1px; }
.component strong, .incident strong { font-size: 15px; }
.component small, .incident small { color: var(--ink-3); font-size: 13px; }

/* Dialog */
dialog { width: min(640px, calc(100vw - 28px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto; border: 0; border-radius: 16px; background: var(--card); color: var(--ink); box-shadow: 0 24px 70px rgba(30, 22, 16, .3); }
dialog::backdrop { background: rgba(30, 22, 16, .45); }
dialog[open] { animation: dialog-in 160ms ease both; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.dialog-heading { display: flex; gap: 18px; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); }
.dialog-heading > div { flex: 1; }
.dialog-heading h2 { margin: 2px 0 4px; font-size: 22px; }
.dialog-heading p:last-child { margin: 0; color: var(--ink-2); font-size: 14px; }
.dialog-heading .icon-button { background: var(--sand); }
.dialog-body { display: grid; gap: 14px; padding: 20px 24px; }
.dialog-body > .eyebrow { margin-top: 6px; color: var(--ink); font-family: var(--font-heavy); font-size: 15px; text-transform: none; }
.form-field { display: grid; gap: 6px; font-family: var(--font-medium); font-size: 14px; }
.form-field input, .form-field select, .form-field textarea { width: 100%; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; outline: 0; background: var(--cream); color: var(--ink); font-family: var(--font-roman); font-size: 15px; }
.form-field textarea { min-height: 90px; padding: 10px 14px; resize: vertical; line-height: 1.5; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.form-field small { color: var(--ink-3); font-family: var(--font-book); font-size: 13px; line-height: 1.4; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-check > span { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.form-check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.form-note { margin: 0; padding: 12px 14px; border-radius: 10px; background: var(--sand); color: var(--ink); font-size: 14px; line-height: 1.5; }
.impact { margin: 0 24px; padding: 10px 14px; border-radius: 10px; background: var(--cream); color: var(--ink-2); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 20px; }

/* Toast */
.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; display: flex; width: min(380px, calc(100vw - 30px)); align-items: flex-start; gap: 10px; padding: 14px; border-radius: 14px; background: var(--ink); color: var(--cream); box-shadow: 0 14px 40px rgba(0, 0, 0, .22); animation: view-in 180ms ease; }
.toast > span { display: grid; width: 24px; height: 24px; flex: none; place-items: center; border-radius: 50%; background: var(--positive); color: #fff; font-size: 13px; }
.toast > div { display: grid; flex: 1; gap: 2px; }
.toast strong { font-size: 15px; }
.toast p { margin: 0; color: color-mix(in srgb, var(--cream) 80%, transparent); font-size: 14px; }
.toast button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 18px; }

@media (max-width: 1080px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform 180ms ease; }
  .sidebar.open { transform: none; box-shadow: 18px 0 48px rgba(0, 0, 0, .22); }
  .scrim { position: fixed; z-index: 45; inset: 0; background: rgba(30, 22, 16, .4); }
  .workspace { margin-left: 0; }
  .menu { display: grid !important; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 590px) {
  .topbar { padding-inline: 16px; }
  main { padding-inline: 16px; }
  .heading { align-items: flex-start; flex-direction: column; }
  .heading > .button, .range { width: 100%; }
  .range select { flex: 1; }
  .metrics, .summary { grid-template-columns: 1fr; }
  .bar { grid-template-columns: 100px minmax(0, 1fr) 64px; }
  .form-row { grid-template-columns: 1fr; }
  .dialog-heading, .dialog-body { padding-inline: 18px; }
  .impact { margin-inline: 18px; }
  .dialog-actions { padding-inline: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
