/* Mailosh components, built only from tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs)/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.015em; line-height: 1.25; }
p { margin: 0; }
code { font: 500 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
[data-logo] svg, .brand svg { width: 100%; height: 100%; }
.avatar svg { width: 16px; height: 16px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  flex: 0 0 256px; width: 256px;
  display: flex; flex-direction: column; gap: 2px;
  padding: 22px 16px 16px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.main { flex: 1 1 auto; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1480px; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; font-weight: 600; font-size: 18px; letter-spacing: -0.02em; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; overflow: hidden; flex-shrink: 0; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-section {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; font-size: var(--fs-sm); font-weight: 500; color: var(--subtle);
  list-style: none; cursor: pointer; user-select: none;
}
.nav-section::-webkit-details-marker { display: none; }
.nav-section svg { width: 14px; height: 14px; transition: transform .15s; }
details:not([open]) > .nav-section svg { transform: rotate(-90deg); }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 40px; padding: 0 10px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  font-size: var(--fs-md); font-weight: 500; color: var(--ink-2);
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); stroke-width: 1.8; }
.nav-link:hover { background: var(--surface-3); }
.nav-link[aria-current="page"] { background: var(--raised); border-color: var(--line); box-shadow: var(--shadow-raised); color: var(--ink); font-weight: 600; }
.nav-link[aria-current="page"] svg { color: var(--ink); }
.nav-link .count { margin-left: auto; font-size: var(--fs-xs); color: var(--muted); font-weight: 500; }
.sidebar-foot { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.usage { padding: 14px; border-radius: var(--r); background: var(--surface-3); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; font-size: var(--fs-sm); color: var(--muted); }
.usage strong { color: var(--ink); font-weight: 600; }
.meter { height: 6px; border-radius: var(--pill); background: var(--line); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: var(--pill); background: var(--cobalt); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 14px 6px 0; border-top: 1px solid var(--line); }
.user-card .who { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.user-card .name { font-weight: 600; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-badge { align-self: flex-start; padding: 1px 8px; border-radius: var(--pill); background: var(--yellow); color: #3D2E00; font-size: 11px; font-weight: 600; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; flex-basis: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; }
  .sidebar .nav-group { flex-direction: row; flex-wrap: wrap; }
  .sidebar .nav-group + .nav-group { margin-top: 0; }
  .sidebar .nav-section, .sidebar-foot .usage { display: none; }
  .brand { padding-bottom: 10px; }
  .main { padding: 20px 16px 40px; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.page-head h1 { font-size: var(--fs-xl); }
.page-head .sub { color: var(--muted); font-size: var(--fs); margin-top: 4px; }
.page-head .sub strong { color: var(--ink); font-weight: 500; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.dot-sep { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--subtle); margin: 0 8px; vertical-align: middle; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  font: 600 var(--fs) / 1 var(--font); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--cobalt); color: var(--on-cobalt); }
.btn-primary:hover { background: var(--cobalt-hover); }
.btn-dark { background: var(--ink); color: var(--bg); }
.btn-soft { background: var(--cobalt-soft); color: var(--cobalt-soft-ink); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger); color: #FFFFFF; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: var(--fs-sm); }
.btn-lg { min-height: 46px; padding: 0 22px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.link { color: var(--cobalt); font-weight: 500; }
.link:hover { text-decoration: underline; }
.icon-btn { width: 34px; height: 34px; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.danger { color: var(--danger); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.hint { font-size: var(--fs-xs); color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: 400 var(--fs) var(--font);
}
.textarea { padding: 10px 12px; min-height: 96px; resize: vertical; line-height: 1.55; }
.input::placeholder, .textarea::placeholder { color: var(--subtle); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--cobalt); box-shadow: 0 0 0 3px var(--cobalt-soft); }
.input-pill { background: var(--surface-3); }
.field.error .input { border-color: var(--danger); }
.field.error .hint { color: var(--danger-ink); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 24px; border-radius: var(--pill); background: var(--line); position: relative; transition: background .15s; flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #FFFFFF; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--cobalt); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--cobalt); outline-offset: 2px; }

/* Segmented control: a bordered group, like a toolbar. */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); overflow: hidden; }
.seg button, .seg a { min-height: 36px; padding: 0 14px; border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--muted); font: 500 var(--fs) var(--font); cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.seg > :first-child, .seg label:first-child button { border-left: 0; }
.seg button[aria-pressed="true"], .seg a[aria-current="true"] { background: var(--surface-2); color: var(--ink); }
.seg svg { width: 16px; height: 16px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: var(--r-xs); font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; }
.badge-cobalt { background: var(--cobalt-soft); color: var(--cobalt-soft-ink); }
.badge-ink { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge-win { background: var(--yellow); color: #3D2E00; }
.badge-warn { background: var(--yellow-soft); color: var(--yellow-ink); }
.badge-ok { background: var(--success-soft); color: var(--success-ink); }
.badge-danger { background: var(--danger-soft); color: var(--danger-ink); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 20px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: var(--fs-lg); }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.stat { padding: 18px 20px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.stat .k { font-size: var(--fs-md); font-weight: 500; color: var(--ink-2); }
.stat .v { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .d { font-size: var(--fs-sm); color: var(--muted); }
.stat-hero .v { color: var(--cobalt); }
@media (max-width: 640px) { .stats > * { grid-column: auto !important; } }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs); min-width: 640px; }
.table th { text-align: left; font-size: var(--fs-sm); font-weight: 500; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 13px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-3); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .t-title { font-weight: 500; }
.table .t-sub { font-size: var(--fs-xs); color: var(--muted); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 44px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .art { width: 56px; height: 56px; border-radius: var(--r); background: var(--tile); color: var(--on-tile); display: flex; align-items: center; justify-content: center; margin-bottom: 4px; }
.empty .art svg { width: 24px; height: 24px; }
.empty h3 { font-size: var(--fs-lg); }
.empty p { color: var(--muted); max-width: 380px; }

/* ---------- Misc ---------- */
.avatar { width: 32px; height: 32px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: var(--fs-sm); flex-shrink: 0; }
.avatar-lg { width: 40px; height: 40px; font-size: var(--fs-md); background: var(--success-soft); color: var(--success-ink); border: 0; }
.row { display: flex; align-items: center; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
.kbd { display: inline-flex; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line); font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; border-radius: var(--r-sm); background: var(--surface-2); font-size: var(--fs-sm); font-weight: 500; }
.progress-steps { display: flex; gap: 8px; }
.progress-steps span { flex: 1; height: 5px; border-radius: var(--pill); background: var(--line); }
.progress-steps span.done { background: var(--cobalt); }
