/* ==========================================================================
   CRCertMgr design system — layered over Pico.css
   Layout: fixed dark sidebar (desktop) / slide-over drawer (mobile)
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  --brand: #4f46e5;
  --brand-strong: #4338ca;
  --brand-soft: rgba(79, 70, 229, 0.10);
  --ok: #059669;   --ok-soft: rgba(16, 185, 129, 0.13);
  --warn: #b45309; --warn-soft: rgba(245, 158, 11, 0.15);
  --bad: #dc2626;  --bad-soft: rgba(239, 68, 68, 0.12);
  --sidebar-bg: #0f172a;
  --sidebar-fg: #94a3b8;
  --sidebar-w: 232px;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);

  --pico-font-size: 15px;
  --pico-border-radius: 8px;
}

/* Pico primary → brand indigo (light + dark) */
:root,
:root:not([data-theme="dark"]),
[data-theme="light"],
[data-theme="dark"] {
  --pico-primary: var(--brand);
  --pico-primary-background: var(--brand);
  --pico-primary-border: var(--brand);
  --pico-primary-hover: var(--brand-strong);
  --pico-primary-hover-background: var(--brand-strong);
  --pico-primary-hover-border: var(--brand-strong);
  --pico-primary-focus: rgba(79, 70, 229, 0.30);
  --pico-primary-underline: rgba(79, 70, 229, 0.50);
  --pico-primary-inverse: #ffffff;
}
[data-theme="dark"] {
  --pico-primary: #818cf8;
  --pico-primary-hover: #a5b4fc;
  --pico-primary-underline: rgba(129, 140, 248, 0.5);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --pico-primary: #818cf8;
    --pico-primary-hover: #a5b4fc;
    --pico-primary-underline: rgba(129, 140, 248, 0.5);
  }
}

[x-cloak] { display: none !important; }
body { margin: 0; }

/* ---------- app shell ---------- */
.app { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  z-index: 50;
  padding: 0.4rem 0.65rem 0.9rem;
}
.sidebrand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.95rem 0.55rem 0.9rem;
  color: #f8fafc;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.sidebrand:hover { color: #fff; text-decoration: none; }
.sidebrand .ic { width: 21px; height: 21px; color: #818cf8; }

.sidenav { display: flex; flex-direction: column; gap: 2px; }
.navitem {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  color: var(--sidebar-fg);
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.navitem:hover { color: #e2e8f0; background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.navitem.active { color: #fff; background: var(--brand); }
.navitem .ic { width: 17px; height: 17px; flex: none; opacity: 0.9; }

.sidefoot { margin-top: auto; }
.sidefoot form { margin: 0; }
.navitem-btn {
  width: 100%;
  background: none;
  border: 0;
  margin: 0;
  cursor: pointer;
  box-shadow: none;
  text-align: left;
}
.navitem-btn:hover { color: #fecaca; background: rgba(239, 68, 68, 0.12); }
.sidemeta {
  padding: 0.55rem 0.7rem 0;
  color: #475569;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
}

.content {
  margin-left: var(--sidebar-w);
  padding: 1.5rem 2rem 3.5rem;
  max-width: 1480px;
}
.content-plain { margin: 0 auto; max-width: 860px; padding: 2rem 1rem; }

/* mobile top bar + drawer */
.mobilebar { display: none; }
.scrim { display: none; }
@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open { transform: none; }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.5);
    z-index: 40;
  }
  .mobilebar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--sidebar-bg);
    color: #f8fafc;
    padding: 0.55rem 0.9rem;
  }
  .navtoggle {
    width: auto;
    margin: 0;
    padding: 0.3rem 0.45rem;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    color: #e2e8f0;
    box-shadow: none;
    line-height: 0;
  }
  .navtoggle .ic { width: 19px; height: 19px; }
  .mobile-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 700;
    font-size: 0.95rem;
  }
  .mobile-brand .ic { width: 17px; height: 17px; color: #818cf8; }
  .content { margin-left: 0; padding: 1rem 0.9rem 2.5rem; }
}

/* ---------- headings & toolbar ---------- */
.content h3 { margin-bottom: 1rem; font-size: 1.35rem; }
.content h4 { margin: 1.6rem 0 0.7rem; font-size: 1.05rem; }
.content h6 { margin: 1.1rem 0 0.5rem; font-size: 0.85rem; text-transform: uppercase;
              letter-spacing: 0.05em; color: var(--pico-muted-color); }

.toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .grow, .grow { flex: 1 1 auto; margin-bottom: 0; }
.toolbar h3 { margin-bottom: 0; }
.inline { display: inline; margin: 0; }
.narrow { max-width: 46rem; }

/* buttons */
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; width: auto; margin-bottom: 0; }
form.inline button { width: auto; margin-bottom: 0; }
.btn-link { font-size: 0.83rem; font-weight: 500; }
[role="button"], button { font-weight: 500; }

/* ---------- cards ---------- */
article {
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
article > header {
  --pico-card-sectioning-background-color: transparent;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: -1.1rem -1.2rem 0.9rem;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
  font-size: 0.95rem;
}
article > footer {
  background: transparent;
  margin: 0.9rem -1.2rem -1.1rem;
  padding: 0.6rem 1.2rem;
  border-top: 1px solid var(--pico-muted-border-color);
}
.grid { align-items: start; gap: 1rem; }
.grid > article { margin-bottom: 0; }

/* ---------- KPI stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}
.stats article { margin: 0; padding: 0.8rem 1rem; text-align: left; }
.stats h2 {
  margin: 0;
  font-size: 1.65rem;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stats small {
  display: block;
  margin-top: 0.1rem;
  color: var(--pico-muted-color);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- tables ---------- */
figure {
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--radius);
  background: var(--pico-card-background-color);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  margin-bottom: 1.1rem;
}
figure > table { margin: 0; }
table.compact { font-size: 0.85rem; }
table.compact td, table.compact th { padding: 0.45rem 0.7rem; vertical-align: middle; }
thead th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--pico-muted-color);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--brand) 4%, transparent); }
article table { box-shadow: none; }
article tbody tr:hover { background: transparent; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline; }
.row-gone { opacity: 0.55; }

/* ---------- badges, dots, tags ---------- */
.badge {
  display: inline-block;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.badge-green   { background: var(--ok-soft);   color: var(--ok); }
.badge-amber   { background: var(--warn-soft); color: var(--warn); }
.badge-red     { background: var(--bad-soft);  color: var(--bad); }
.badge-unknown { background: var(--pico-muted-border-color); color: var(--pico-muted-color); }

.dot { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; }
.dot-green { background: #10b981; box-shadow: 0 0 0 3px var(--ok-soft); }
.dot-red   { background: #ef4444; box-shadow: 0 0 0 3px var(--bad-soft); }
.dot-grey  { background: #94a3b8; }

.tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.05rem 0.45rem;
  margin: 0 0.12rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 999px;
  color: var(--pico-muted-color);
  white-space: nowrap;
}
.tag-acme { border-color: color-mix(in srgb, var(--ok) 45%, transparent); color: var(--ok); }

.txt-red { color: var(--bad); }
.txt-amber { color: var(--warn); }
.muted { color: var(--pico-muted-color); }
.mono { font-family: var(--pico-font-family-monospace); font-size: 0.82em; }
.small { font-size: 0.85rem; }
.wrap { word-break: break-all; white-space: normal; }

/* dark-theme lightening for soft badges/text */
[data-theme="dark"] .badge-green, [data-theme="dark"] .tag-acme { color: #34d399; }
[data-theme="dark"] .badge-amber, [data-theme="dark"] .txt-amber { color: #fbbf24; }
[data-theme="dark"] .badge-red, [data-theme="dark"] .txt-red { color: #f87171; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .badge-green,
  html:not([data-theme="light"]) .tag-acme { color: #34d399; }
  html:not([data-theme="light"]) .badge-amber,
  html:not([data-theme="light"]) .txt-amber { color: #fbbf24; }
  html:not([data-theme="light"]) .badge-red,
  html:not([data-theme="light"]) .txt-red { color: #f87171; }
}

/* ---------- flash messages ---------- */
.flash {
  padding: 0.6rem 0.95rem;
  border-radius: var(--radius);
  margin-bottom: 0.8rem;
  font-size: 0.88rem;
  border: 1px solid;
}
.flash-ok    { background: var(--ok-soft);  border-color: color-mix(in srgb, var(--ok) 35%, transparent);  color: inherit; }
.flash-error { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); color: inherit; }

/* ---------- job log ---------- */
.joblog {
  background: #0b1220;
  color: #c9ddf5;
  border: 1px solid #1e293b;
  border-radius: var(--radius);
  max-height: 65vh;
  overflow: auto;
  font-size: 0.79rem;
  line-height: 1.55;
  padding: 0.9rem 1rem;
  white-space: pre-wrap;
}

/* ---------- misc components ---------- */
.pubkey-cell textarea { font-size: 0.72rem; font-family: var(--pico-font-family-monospace); }
.targets article { margin: 0; }
.targets label { font-weight: normal; margin-bottom: 0.3rem; }
.totp-qr svg { background: #fff; padding: 8px; border-radius: 8px; max-width: 220px; height: auto; }
#filter { margin-bottom: 0; }
#statusFilter { width: auto; margin-bottom: 0; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--pico-primary); }
details summary { font-size: 0.9rem; }

/* ==========================================================================
   Pre-authentication pages (login / first-run setup) — no navigation at all
   ========================================================================== */
.auth-body { background: var(--pico-background-color); }
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  place-content: center;
  grid-template-columns: minmax(0, 400px);
  padding: 1.2rem;
  background:
    radial-gradient(1100px 550px at 15% -10%, rgba(79, 70, 229, 0.14), transparent 60%),
    radial-gradient(900px 500px at 110% 115%, rgba(16, 185, 129, 0.10), transparent 60%);
}
.auth-inner { width: 100%; max-width: 400px; }
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 1.3rem;
}
.auth-logo {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.35);
}
.auth-logo svg { width: 26px; height: 26px; }
.auth-wordmark { font-size: 1.15rem; font-weight: 700; letter-spacing: 0.02em; }
.auth-card {
  padding: 1.7rem 1.7rem 1.4rem;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(2, 6, 23, 0.10), var(--shadow-sm);
  margin-bottom: 0;
}
.auth-title { font-size: 1.25rem; margin-bottom: 0.15rem; }
.auth-sub { color: var(--pico-muted-color); font-size: 0.85rem; margin-bottom: 1.2rem; }
.auth-submit { width: 100%; margin-top: 0.3rem; }
@media (max-width: 480px) {
  .auth-card { padding: 1.3rem 1.1rem 1rem; }
}
