/* public/theme.css
 *
 * Shared theme + layout for the security-dashboard panels
 * (/, /machines, /logs, /keys, /sites) on
 * security.everthread.live. Loaded by SHELL() in src/server.mjs.
 *
 * Goals (launch-spec section 11 / t_0bf559c8):
 *   - Sidebar nav (left), top-bar w/ tier badge + company name (right).
 *   - Metric cards on /.
 *   - Responsive at <=960px (sidebar collapses to top tabs).
 *   - Accessibility: visible focus, prefers-reduced-motion, AA contrast,
 *     semantic landmarks (header/nav/main), skip link.
 *   - Loading / empty / error / expired-access states are class-driven
 *     (.is-loading, .is-empty, .is-error, .is-expired).
 *
 * Layered: tokens -> reset -> shell layout -> panel primitives -> states
 * -> responsive. Keep the file <10 KB raw so it ships in <2 KB gzip.
 */

@import url("https://fonts.googleapis.com/css2?family=Schibsted+Grotesk:wght@600;700&family=Public+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500&display=swap");

/* ---------- Tokens (CSS variables): EverThread "Steady" ---------- */
:root {
  color-scheme: light;
  --bg:            #F6F7F9;
  --bg-elev:       #ffffff;
  --bg-elev-2:     #EEF2F6;
  --border:        #E3E8EF;
  --border-strong:    #D6DDE6;
  --fg:            #14202E;
  --fg-strong:     #14202E;
  --fg-muted:      #4F5D6E;
  --accent:        #C2410C;
  --accent-hover:  #A8380A;
  --ok:            #1C6B43;
  --warn:          #8A4B00;
  --err:           #A1251B;
  --stop:          #A1251B;
  --navy:          #0F2540;
  --navy-2:        #173356;
  --navy-line:     #22406A;
  --on-navy:       #C9D4E3;

  --radius:        8px;
  --radius-lg:     14px;
  --shadow:        0 1px 2px rgba(15,37,64,.06), 0 8px 24px rgba(15,37,64,.08);

  --pad-sm:        6px;
  --pad:           14px;
  --pad-lg:        20px;

  --font-mono:     "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-sans:     "Public Sans", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --font-display:  "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;

  --shell-sidebar-w: 220px;
  --shell-topbar-h:  52px;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 var(--font-sans);
  color: var(--fg);
  background: var(--bg);
  min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0; color: var(--fg-strong); font-weight: 600; }
h1, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 16px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--fg-muted); margin-bottom: 10px; }
h3 { font-size: 14px; }
p { margin: 0 0 10px; }
a { color: var(--accent); text-decoration: none; }
a:hover, a:focus-visible { color: var(--accent-hover); text-decoration: underline; }
button {
  font: inherit;
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 8px 16px;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color .12s ease;
}
button:hover, button:focus-visible { background: var(--accent-hover); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.stop { background: var(--stop); }
button.warn { background: var(--warn); }
button.ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}
button.ghost:hover { background: var(--bg-elev-2); }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=search], textarea, select {
  font: inherit;
  background: #fff;
  color: var(--fg);
  border: 1px solid #8492A6;
  padding: 8px 10px;
  border-radius: var(--radius);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 70px; font-family: var(--font-mono); font-size: 13px; }
code, pre { font-family: var(--font-mono); font-size: 12px; }
pre { background: var(--bg); border: 1px solid var(--border); padding: 10px; border-radius: var(--radius); overflow: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--pad) 0; }

/* ---------- Accessibility helpers ---------- */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius);
  z-index: 100;
}
.skip-link:focus { left: 8px; }
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Shell layout (sidebar + topbar + main) ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--shell-sidebar-w) 1fr;
  grid-template-rows: var(--shell-topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}
.shell-sidebar {
  grid-area: sidebar;
  background: var(--navy);
  border-right: 1px solid var(--navy);
  padding: var(--pad) 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.shell-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 var(--pad) var(--pad);
  border-bottom: 1px solid var(--navy-line);
  margin-bottom: var(--pad-sm);
}
.shell-brand-mark {
  width: 28px; height: 28px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 34 34' fill='none'%3E%3Ccircle cx='17' cy='17' r='14.5' stroke='%23F2783A' stroke-width='2.5' stroke-dasharray='4.5 3.2' stroke-linecap='round'/%3E%3Cpath d='M11 17.5l4 4 8-9' stroke='%23fff' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  display: inline-block;
  flex: none;
}
.shell-brand-text { font-family: var(--font-display); font-weight: 700; color: #fff; font-size: 18px; letter-spacing: -.01em; }
.shell-brand-sub { color: var(--on-navy); font-size: 11px; }
.shell-nav {
  display: flex;
  flex-direction: column;
  padding: 0 8px;
  gap: 2px;
}
.shell-nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--on-navy);
  padding: var(--pad-sm) 10px 4px;
}
.shell-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--on-navy);
  font-size: 14px;
}
.shell-nav a:hover, .shell-nav a:focus-visible {
  background: var(--navy-2);
  text-decoration: none;
  color: #fff;
}
.shell-nav a:focus-visible { outline-color: #F2783A; }
.shell-nav a[aria-current="page"] {
  background: var(--accent);
  color: #fff;
}
.shell-nav a[aria-current="page"]:hover { background: var(--accent-hover); }
.shell-nav .nav-icon {
  width: 16px; height: 16px;
  flex: none;
  opacity: .85;
}
.shell-topbar {
  grid-area: topbar;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--pad);
  padding: 0 var(--pad-lg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.shell-topbar-title { font-weight: 600; color: var(--fg-strong); }
.shell-topbar-spacer { flex: 1; }
.shell-topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--fg-muted);
}
.shell-main {
  grid-area: main;
  padding: var(--pad-lg);
  max-width: 1280px;
  width: 100%;
}

/* ---------- Tier badge ---------- */
.tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-elev-2);
  color: var(--fg-strong);
  border: 1px solid var(--border);
}
.tier-badge.tier-starter,
.tier-badge.tier-free { background: var(--bg-elev-2); color: var(--fg-muted); }
.tier-badge.tier-pro  { background: #E6EDF6; color: var(--navy-2); border-color: #C9D6E6; }
.tier-badge.tier-none { background: #FCE6E3; color: var(--err); border-color: #F3C1BB; }
.tier-badge .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

/* ---------- Panel / card primitives ---------- */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--pad-lg);
  margin-bottom: var(--pad);
  box-shadow: var(--shadow);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pad);
  margin-bottom: var(--pad);
}
.panel-header h2 { margin: 0; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Metric grid (used on / dashboard) */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--pad);
  margin-bottom: var(--pad-lg);
}
.metric {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
  box-shadow: var(--shadow);
}
.metric .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--fg-muted);
}
.metric .value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--fg-strong);
  line-height: 1.1;
}
.metric .delta {
  font-size: 12px;
  color: var(--fg-muted);
}
.metric .delta.up    { color: var(--ok); }
.metric .delta.down  { color: var(--err); }
.metric .delta.flat  { color: var(--fg-muted); }
.metric .trend {
  margin-top: auto;
  font-size: 12px;
  color: var(--fg-muted);
}

/* Pills, status */
.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  text-transform: lowercase;
}
.pill.started, .pill.passing, .pill.active, .pill.open, .pill.high {
  background: #E4F3EA; color: var(--ok); border-color: #B5DCC4;
}
.pill.stopped, .pill.failed, .pill.closed, .pill.resolved, .pill.medium {
  background: var(--bg-elev-2); color: var(--fg-muted); border-color: var(--border-strong);
}
.pill.failing, .pill.paused, .pill.expired, .pill.error, .pill.critical {
  background: #FCE6E3; color: var(--err); border-color: #F3C1BB;
}
.pill.warning, .pill.past_due, .pill.low {
  background: #FDF1DE; color: var(--warn); border-color: #F1D3A6;
}
.pill.info {
  background: #E6EDF6; color: var(--navy-2); border-color: #C9D6E6;
}

/* Tables */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
  background: var(--bg);
  position: sticky; top: 0;
}
tbody tr:hover { background: var(--bg); }
tbody tr:last-child td { border-bottom: 0; }

/* Utility */
.muted   { color: var(--fg-muted); }
.ok      { color: var(--ok); }
.warn    { color: var(--warn); }
.err     { color: var(--err); }
.row     { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row.nowrap > * { flex: 0 0 auto; }
.spacer  { flex: 1; }
.cluster { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hidden  { display: none !important; }
hr.sep   { margin: var(--pad-lg) 0; }
pre.log  { background: var(--bg); border: 1px solid var(--border); padding: 10px; border-radius: var(--radius); max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-all; font-size: 11px; }

/* ---------- State classes (loading / empty / error / expired) ---------- */
/* Loading state: visible while async data is in flight */
.is-loading {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.is-loading-block {
  padding: var(--pad-lg);
  text-align: center;
  color: var(--fg-muted);
}

/* Empty state */
.empty-state {
  padding: var(--pad-lg);
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--fg-muted);
  background: var(--bg-elev);
}
.empty-state h3 {
  color: var(--fg-strong);
  margin-bottom: 6px;
}
.empty-state .muted { margin-bottom: var(--pad); }

/* Error state */
.error-state {
  padding: var(--pad);
  border-radius: var(--radius);
  background: #FCE6E3;
  border: 1px solid #F3C1BB;
  color: var(--err);
}
.error-state h3 {
  color: var(--err);
  margin-bottom: 6px;
}

/* Expired access: distinct visual treatment so it is recognizable */
.expired-access {
  max-width: 520px;
  margin: var(--pad-lg) auto;
  padding: var(--pad-lg);
  background: var(--bg-elev);
  border: 1px solid #F3C1BB;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  text-align: center;
}
.expired-access .icon {
  font-size: 36px;
  margin-bottom: var(--pad-sm);
}
.expired-access h2 {
  color: var(--err);
  margin-bottom: var(--pad-sm);
  font-size: 18px;
  text-transform: none;
  letter-spacing: 0;
}

/* Lifecycle banners (within /sites panel) */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  border: 1px solid var(--border);
}
.banner.info    { background: #E6EDF6; border-color: #C9D6E6; color: var(--fg); }
.banner.warn    { background: #FDF1DE; border-color: #F1D3A6; color: var(--fg); }
.banner.err     { background: #FCE6E3; border-color: #F3C1BB; color: var(--err); }
.banner .label  { font-weight: 700; margin-right: 6px; }

/* ---------- Responsive (collapse to stacked layout at <=960px) ---------- */
@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--shell-topbar-h) auto 1fr;
    grid-template-areas:
      "topbar"
      "sidebar"
      "main";
  }
  .shell-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--navy);
    padding: var(--pad-sm) 0;
    flex-direction: column;
  }
  .shell-brand { display: none; }
  .shell-nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 0 var(--pad-sm);
    gap: 4px;
  }
  .shell-nav a {
    flex: none;
    padding: 6px 12px;
    font-size: 13px;
  }
  .shell-nav-section { display: none; }
  .shell-main { padding: var(--pad); }
  .metrics { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .metric .value { font-size: 22px; }
  .shell-topbar-meta { font-size: 12px; }
}
@media (max-width: 640px) {
  .shell-topbar { padding: 0 var(--pad); gap: 8px; }
  .shell-topbar-title { font-size: 14px; }
  .shell-topbar-meta .meta-long { display: none; }
  table { font-size: 12px; }
  th, td { padding: 7px 8px; }
}

/* ---------- Print ---------- */
@media print {
  .shell-sidebar, .shell-topbar { display: none; }
  .shell { grid-template-columns: 1fr; grid-template-areas: "main"; }
  .panel { box-shadow: none; border-color: #000; }
  body { background: #fff; color: #000; }
}