/* ==========================================================================
   IMEIFlow design system — one stylesheet, no CDN, no build step.
   Sections: tokens · base · shell (sidebar/topbar) · content blocks · tables ·
   forms · buttons · badges · misc · charts · flash · public site · responsive ·
   print helpers.
   Classes are the ones listed in CONTRACT.md section 5; the only extras are the
   four shell hooks marked "shell extra" below (brand, nav toggle, topbar right,
   flash close) plus the sort arrow — they are used by base.html alone.
   ========================================================================== */

:root {
  --accent: #2f6df6;
  --accent-dark: #1d4ed8;
  --accent-soft: rgba(47, 109, 246, .18);
  --ok: #12a150;
  --warn: #d97706;
  --bad: #dc2626;
  --info: #0284c7;

  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e3e8ef;
  --line-strong: #cbd5e1;
  --bg: #f5f7fa;
  --surface: #ffffff;

  --side-bg: #0f172a;
  --side-bg-2: #16233b;
  --side-ink: #cbd5e1;
  --side-ink-mute: #8494ad;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 30px rgba(15, 23, 42, .12);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.28rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 10px; }
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); font-size: .86em; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: #eef2f7;
  border: 1px solid var(--line);
  font-size: .78rem;
  color: var(--ink-2);
}

/* ---------------------------------------------------------------- shell */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: 244px;
  background: var(--side-bg);
  color: var(--side-ink);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 40;
}

.side-brand {                       /* shell extra */
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.side-brand .mono { font-size: 1.06rem; font-weight: 700; color: #fff; letter-spacing: -.01em; }
.side-brand .small { color: var(--side-ink-mute); }

.side-nav { display: flex; flex-direction: column; padding: 10px 8px 24px; }

.side-group {
  padding: 14px 10px 6px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--side-ink-mute);
  font-weight: 700;
}

.side-link {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--side-ink);
  font-size: .9rem;
  text-decoration: none;
}
.side-link:hover { background: var(--side-bg-2); color: #fff; text-decoration: none; }
.side-link.active { background: var(--accent); color: #fff; font-weight: 600; }

.main { flex: 1; min-width: 0; margin-left: 244px; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-right {                     /* shell extra */
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.nav-toggle { display: none; }       /* shell extra */

.content { padding: 18px; width: 100%; max-width: 1440px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.page-head h1 { margin: 0; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}
.card-title { font-weight: 700; font-size: .96rem; }
.card-body { padding: 16px; }
.card-body > :last-child { margin-bottom: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.stat-label { font-size: .8rem; color: var(--ink-2); font-weight: 600; }
.stat-sub { font-size: .76rem; color: var(--muted); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }

.kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.kv:last-child { border-bottom: 0; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline-item { position: relative; padding: 0 0 14px 12px; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: -20px; top: 6px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline-item:last-child { padding-bottom: 0; }

.empty {
  text-align: center;
  padding: 26px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fcfdff;
}

/* helpers used by the feature modules next to the contract classes */
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.card-actions > :last-child:not(:first-child) { margin-left: auto; }
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.empty .card-title { margin-bottom: 4px; }
.empty p { margin-bottom: 10px; }

/* ---------------------------------------------------------------- tables */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.table th, table.table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}
table.table th {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  background: #fbfcfe;
}
table.table th a { color: var(--muted); text-decoration: none; }
table.table th a:hover { color: var(--accent-dark); }
table.table tbody tr:hover { background: #f8fafc; }
table.table td.wrap, table.table th.wrap { white-space: normal; min-width: 180px; }
.sort-arrow { font-size: .7rem; }    /* shell extra */

.table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 0;
}
.table-actions > :last-child { margin-left: auto; }

.bulk-bar {
  display: none;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--accent);
  background: #f2f6ff;
  border-radius: var(--radius);
}
.bulk-bar.active, .bulk-bar[data-active="1"] { display: flex; }

/* ---------------------------------------------------------------- filters */
.filters {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}
.filters-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters-row .field { min-width: 140px; flex: 0 1 auto; }
.filters-row .input, .filters-row .select { min-width: 140px; }

/* ---------------------------------------------------------------- forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-grid .field.wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: .8rem; font-weight: 600; color: var(--ink-2); }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
  outline-offset: 0;
}
.input:disabled, .select:disabled { background: #f1f5f9; color: var(--muted); }
.input[type="checkbox"] { width: auto; }

.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form .input, .inline-form .select { width: auto; min-width: 120px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--ink-2); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  background: #eef2f7;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: #e3e9f1; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 10px; font-size: .8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  line-height: 1.5;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-ok { background: #e7f7ee; color: #0f7a3d; border-color: #bfe8d1; }
.badge-warn { background: #fdf3e3; color: #a35c05; border-color: #f6dcae; }
.badge-bad { background: #fdeaea; color: #b91c1c; border-color: #f6c7c7; }
.badge-info { background: #e8f4fd; color: #0369a1; border-color: #bfe0f5; }
.badge-mute { background: #eef2f7; color: #475569; border-color: #dbe3ec; }

/* ---------------------------------------------------------------- flash */
.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: .9rem;
}
.flash-ok { border-color: #bfe8d1; background: #eefaf3; color: #0f7a3d; }
.flash-err { border-color: #f6c7c7; background: #fdeaea; color: #b91c1c; }
.flash-info { border-color: #bfe0f5; background: #eef7fe; color: #0369a1; }
.flash-close {                       /* shell extra */
  margin-left: auto;
  background: none;
  border: 0;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  opacity: .7;
  padding: 2px 4px;
}
.flash-close:hover { opacity: 1; }

/* ---------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.tab {
  padding: 8px 12px;
  border-radius: 8px 8px 0 0;
  color: var(--ink-2);
  font-size: .88rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  border-bottom: 0;
}
.tab:hover { background: #eef2f7; text-decoration: none; }
.tab.active { background: var(--surface); border-color: var(--line); color: var(--accent-dark); margin-bottom: -1px; }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; height: auto; max-height: 230px; display: block; }
.donut { width: 180px; height: 180px; display: block; margin: 0 auto; }

/* ---------------------------------------------------------------- print helpers */
.no-print { }
.print-only { display: none; }

/* ==========================================================================
   Public site
   ========================================================================== */
.pub { background: var(--surface); color: var(--ink); }
.pub h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); letter-spacing: -.02em; }
.pub h2 { font-size: clamp(1.25rem, 2.4vw, 1.7rem); }

.pub-nav {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.pub-nav strong { font-size: 1.05rem; letter-spacing: -.01em; }
.pub-nav a { color: var(--ink-2); font-size: .9rem; text-decoration: none; }
.pub-nav a:hover { color: var(--accent-dark); }
.pub-nav .hero-actions { margin-left: auto; }
.pub-nav .btn { font-size: .85rem; }

.hero {
  max-width: 940px;
  margin: 0 auto;
  padding: 60px 24px 40px;
  text-align: center;
}
.hero p { color: var(--muted); font-size: 1.05rem; max-width: 760px; margin: 0 auto 18px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: center; }
.hero .hero-actions { margin-bottom: 12px; }

.pub-section { max-width: 1160px; margin: 0 auto; padding: 40px 24px; }
.pub-section > p.muted { max-width: 760px; margin-bottom: 22px; }
.pub-section > .hero-actions { justify-content: flex-start; }

.pub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 18px; }
.feature {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow);
}
.feature h3 { font-size: .98rem; margin-bottom: 6px; }
.feature p { color: var(--muted); font-size: .9rem; margin: 0 0 8px; }
.feature ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); font-size: .88rem; }
.feature li { margin-bottom: 4px; }
.feature .hero-actions { justify-content: flex-start; }

.price-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 18px; align-items: start; }
.price-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.price-card .stat-value { font-size: 1.7rem; }
.price-card ul { margin: 8px 0 12px; padding-left: 18px; color: var(--ink-2); font-size: .87rem; }
.price-card li { margin-bottom: 4px; }
.price-card .hero-actions { justify-content: flex-start; margin-top: auto; }
.price-card.featured { border-color: var(--accent); box-shadow: var(--shadow-lg); }
.price-card.featured .card-title::after { content: " · most popular"; color: var(--accent-dark); font-size: .78rem; font-weight: 600; }

.faq-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 10px;
}
.faq-item summary { cursor: pointer; font-weight: 600; font-size: .95rem; }
.faq-item summary::marker { color: var(--accent); }
.faq-item[open] summary { margin-bottom: 8px; }
.faq-item p { color: var(--muted); font-size: .9rem; margin: 0; }

.cta-band {
  background: var(--side-bg);
  color: #fff;
  text-align: center;
  padding: 56px 24px;
  margin-top: 24px;
}
.cta-band h2 { color: #fff; }
.cta-band p { color: #c7d2e2; }
.cta-band .btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .45); }
.cta-band .btn-ghost:hover { background: rgba(255, 255, 255, .12); }

.pub-footer { background: #f8fafc; border-top: 1px solid var(--line); color: var(--muted); }
.pub-footer .feature { background: transparent; border: 0; box-shadow: none; padding: 0; }
.pub-footer .feature h3 { font-size: .92rem; color: var(--ink); }
.pub-footer a { color: var(--ink-2); }

/* ==========================================================================
   Responsive — mobile drawer under 900px, usable tables at 380px
   ========================================================================== */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .sidebar {
    width: 264px;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: none;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(15, 23, 42, .45); }
  .main { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .content { padding: 14px; }
  .topbar { padding: 10px 12px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .pub-nav { gap: 10px; padding: 10px 14px; overflow-x: auto; }
  .pub-nav .hero-actions { margin-left: 0; }
  .hero { padding: 36px 16px 26px; }
  .pub-section { padding: 28px 16px; }
  .page-head { align-items: flex-start; }
  .page-actions { width: 100%; }
  .filters-row .field { min-width: 100%; }
  .filters-row .input, .filters-row .select { min-width: 100%; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 420px) {
  table.table th, table.table td { padding: 7px 8px; font-size: .82rem; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .btn { padding: 8px 11px; }
}
