/* ============================================================
   App component library — enterprise-SaaS design system.
   Depends on css/tokens.css (load tokens first, this second).
   Replaces the legacy corporate-ui.css skin. Class-driven, no
   !important, works in light and dark.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-3); }

/* ---- typography scale ---- */
.h-display { font-size: 21px; line-height: 1.25; font-weight: 620; letter-spacing: -.02em; }
.h-title { font-size: 16px; font-weight: 620; letter-spacing: -.012em; }
.h-panel { font-size: 14px; font-weight: 620; letter-spacing: -.01em; }
.eyebrow { font-size: 10.5px; font-weight: 640; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 560; letter-spacing: -.004em; cursor: pointer;
  transition: background .14s, border-color .14s, box-shadow .14s, opacity .14s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn svg { width: 15px; height: 15px; opacity: .8; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: inset 0 1px 0 rgba(255,255,255,.14); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.primary svg { opacity: 1; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; gap: 5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-inset); border-color: transparent; }
.btn.danger { color: var(--neg); }
.btn.danger:hover { background: var(--neg-wash); border-color: color-mix(in srgb, var(--neg) 30%, var(--border)); }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn[disabled]:hover { background: var(--surface); border-color: var(--border); }

.icon-btn {
  width: 32px; height: 32px; border-radius: var(--r-sm); flex: none;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-3);
  display: grid; place-items: center; cursor: pointer; transition: all .14s;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.plain { border-color: transparent; background: transparent; }
.icon-btn.plain:hover { background: var(--surface-inset); }

/* ---- form controls ---- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 580; color: var(--ink-2); letter-spacing: -.003em; }
.field-hint { font-size: 12px; color: var(--ink-3); }
.input, .select, textarea.input {
  width: 100%; height: 36px; padding: 0 11px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: 13.5px; transition: border-color .14s, box-shadow .14s;
}
textarea.input { height: auto; padding: 9px 11px; line-height: 1.5; resize: vertical; }
.input::placeholder { color: var(--ink-4); }
.input:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2379828f' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px;
}

/* ---- pills / badges / chips ---- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 3px 9px; border-radius: var(--r-pill); letter-spacing: -.004em;
  background: var(--surface-inset); color: var(--ink-2); border: 1px solid transparent;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.ok { color: var(--pos); background: var(--pos-wash); }
.pill.ok .dot { box-shadow: 0 0 0 3px color-mix(in srgb, var(--pos) 18%, transparent); }
.pill.warn { color: var(--warn); background: var(--warn-wash); }
.pill.neg { color: var(--neg); background: var(--neg-wash); }
.pill.brand { color: var(--accent-ink); background: var(--accent-wash); }
.pill.neutral { color: var(--ink-3); background: var(--surface-inset); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 520;
  padding: 3px 8px; border-radius: var(--r-sm); background: var(--surface-inset);
  color: var(--ink-2); border: 1px solid var(--border);
}
.tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 5px; color: var(--pos); background: var(--pos-wash);
}
.tag.warn { color: var(--warn); background: var(--warn-wash); }
.tag.neutral { color: var(--ink-3); background: var(--surface-inset); }

/* ---- cards / panels ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-card); }
.card-pad { padding: var(--s5) var(--s6); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: var(--s4) var(--s5) var(--s1); }
.panel-head .note { font-size: 11.5px; color: var(--ink-4); }

/* ---- stat tiles ---- */
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 15px 16px; box-shadow: var(--shadow-card); }
.tile .k { font-size: 11px; font-weight: 580; color: var(--ink-3); }
.tile .v { font-size: 24px; font-weight: 640; letter-spacing: -.025em; margin-top: 6px; }
.tile .d { font-size: 11.5px; margin-top: 3px; color: var(--ink-4); }
.tile .d.up { color: var(--pos); }

/* ---- table ---- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; font-weight: 640; letter-spacing: .02em; text-transform: uppercase; color: var(--ink-4); padding: 9px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num, .table th.num { text-align: right; }

/* ---- empty state ---- */
.empty { text-align: center; padding: 44px 24px; border: 1px dashed var(--border); border-radius: var(--r-lg); background: var(--surface); color: var(--ink-3); }
.empty .empty-icon { width: 40px; height: 40px; margin: 0 auto 14px; border-radius: var(--r-md); background: var(--surface-inset); color: var(--ink-3); display: grid; place-items: center; }
.empty .empty-icon svg { width: 20px; height: 20px; }
.empty h2 { font-size: 15px; font-weight: 620; color: var(--ink); }
.empty p { font-size: 13px; max-width: 46ch; margin: 6px auto 0; }
.empty .empty-actions { margin-top: 16px; display: inline-flex; gap: 8px; }

/* ---- skeleton loading ---- */
.skeleton { position: relative; overflow: hidden; background: var(--surface-inset); border-radius: 6px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skeleton::after { animation: none; } }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-pop); padding: 11px 16px; font-size: 13px; font-weight: 520;
  display: flex; align-items: center; gap: 9px; z-index: 90; max-width: 90vw;
}
.toast .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.toast.ok .dot { background: var(--pos); } .toast.err .dot { background: var(--neg); }

/* ---- modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: color-mix(in srgb, #0a0e15 52%, transparent);
  backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 100; padding: 24px;
}
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); max-width: 560px; width: 100%; max-height: 86vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; }

/* ---- info tip ---- */
.info-tip { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--border-strong); color: var(--ink-4); font-size: 9.5px; font-weight: 700; font-style: normal; cursor: help; position: relative; vertical-align: middle; margin-left: 3px; }
.info-tip:hover { color: var(--accent); border-color: var(--accent); }
.info-tip:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); width: max-content; max-width: 260px; padding: 8px 10px; background: var(--ink); color: var(--surface); font-size: 11.5px; font-weight: 500; line-height: 1.4; border-radius: var(--r-sm); box-shadow: var(--shadow-pop); z-index: 60; white-space: normal; text-align: left; letter-spacing: 0; }

/* ---- entrance animation ---- */
.rise { opacity: 0; transform: translateY(8px); animation: rise .5s cubic-bezier(.2,.7,.3,1) forwards; }
.rise:nth-child(1){animation-delay:.02s} .rise:nth-child(2){animation-delay:.07s}
.rise:nth-child(3){animation-delay:.12s} .rise:nth-child(4){animation-delay:.17s} .rise:nth-child(5){animation-delay:.22s}
@keyframes rise { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .rise { animation: none; opacity: 1; transform: none; } }

/* ============================================================
   App shell — persistent left sidebar + content, used on every page.
   ============================================================ */
.app { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand .glyph { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); }
.brand .glyph svg { width: 17px; height: 17px; }
.brand .wm { font-size: 10px; font-weight: 650; letter-spacing: .11em; text-transform: uppercase; color: var(--ink-3); }
.brand .pn { font-size: 14.5px; font-weight: 640; letter-spacing: -.01em; margin-top: -1px; }

.nav-group { padding: 6px 12px; }
.nav-label { font-size: 10.5px; font-weight: 640; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); padding: 8px 11px 5px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 11px; border: 0; background: none; text-align: left; border-radius: var(--r-sm); font-family: inherit; font-size: 13.5px; font-weight: 520; color: var(--ink-2); cursor: pointer; position: relative; transition: background .12s, color .12s; }
.nav-item svg { width: 16px; height: 16px; opacity: .75; flex: none; }
.nav-item:hover { background: var(--surface-inset); color: var(--ink); }
.nav-item.active { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-item.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 2.5px; border-radius: 3px; background: var(--accent); }
.nav-item .badge-mini { margin-left: auto; font-size: 11px; color: var(--ink-4); font-variant-numeric: tabular-nums; }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.side-foot .who { margin-left: 2px; font-size: 12px; line-height: 1.3; }
.side-foot .who b { font-weight: 600; display: block; font-size: 12.5px; }
.side-foot .who span { color: var(--ink-4); font-size: 11px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 14px 26px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 80%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; }
.topbar .crumb { font-size: 12.5px; color: var(--ink-3); }
.topbar .crumb b { color: var(--ink); font-weight: 600; }
.spacer { flex: 1; }
.canvas { padding: 24px 26px 48px; display: flex; flex-direction: column; gap: 18px; width: 100%; max-width: 1200px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .side .nav-group { display: none; }
  .canvas { padding: 18px 16px 40px; }
}
