/* ============================================================================
   IceBox base component language — token-driven, reskins Bootstrap 5 + adds
   bespoke components. Works in light + dark. Honors reduced-motion.
   Load order: tokens.css → base.css → theme-{module}.css
   ============================================================================ */

/* ---- Bridge Bootstrap 5 variables to our tokens (reskins legacy screens) ---- */
:root {
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--on-surface);
  --bs-body-font-family: var(--font-body);
  --bs-border-color: var(--border);
  --bs-primary: var(--primary);
  --bs-primary-rgb: 17,90,164;
  --bs-link-color: var(--primary);
  --bs-link-hover-color: var(--primary-hover);
  --bs-emphasis-color: var(--on-surface-strong);
  --bs-secondary-color: var(--muted);
  --bs-tertiary-bg: var(--surface-2);
  --bs-card-bg: var(--surface);
  --bs-card-border-color: var(--border);
  --bs-border-radius: var(--r-md);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--on-surface);
  font-family: var(--font-body);
  font-feature-settings: "cv02","cv03","cv04";
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4,h5,.display-font { font-family: var(--font-display); color: var(--on-surface-strong); letter-spacing:-.01em; }

/* Tabular figures everywhere numbers matter */
.table, .stat-value, .num, td.text-end, .mono, input[type=number] { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }

/* ---- Focus visibility (accessibility) ---- */
a:focus-visible, button:focus-visible, .btn:focus-visible, .form-control:focus-visible,
.form-select:focus-visible, [tabindex]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
  border-color: var(--primary);
}

/* ---- Buttons ---- */
.btn { --bs-btn-border-radius: var(--r-sm); font-weight:600; border:1px solid transparent; transition:transform .08s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); }
.btn-outline-primary { color: var(--primary); border-color: var(--border-strong); background: var(--surface); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-outline-secondary { color: var(--on-surface); border-color: var(--border-strong); background: var(--surface); }
.btn-outline-secondary:hover { background: var(--surface-sunken); color: var(--on-surface); border-color:var(--border-strong); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-danger  { background: var(--danger);  border-color: var(--danger); }
.btn[disabled], .btn:disabled { opacity:.5; }
.btn .spinner { width:1em; height:1em; border:2px solid currentColor; border-right-color:transparent; border-radius:50%; display:inline-block; animation:ib-spin .6s linear infinite; vertical-align:-2px; margin-right:.4em; }
@keyframes ib-spin { to { transform: rotate(360deg); } }

/* ---- Cards / surfaces ---- */
.card { background: var(--surface); border:1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-sm); }
.card-header { background: var(--surface); border-bottom:1px solid var(--border); color: var(--on-surface-strong); font-weight:600; }
.bg-white { background: var(--surface) !important; }
.border, .border-top, .border-bottom { border-color: var(--border) !important; }
.text-muted { color: var(--muted) !important; }

/* ---- Tables ---- */
.table { --bs-table-bg: transparent; --bs-table-color: var(--on-surface); color:var(--on-surface); }
.table > :not(caption) > * > * { border-bottom-color: var(--border); }
.table thead th { background: var(--surface-2); color: var(--muted); font-size:var(--fs-xs); text-transform:uppercase; letter-spacing:.04em; font-weight:600; border-bottom:1px solid var(--border); position:sticky; top:0; }
.table-hover > tbody > tr:hover > * { background: var(--surface-2); }
th[aria-sort] { cursor:pointer; }
th[aria-sort="ascending"]::after { content:" ▲"; color:var(--primary); }
th[aria-sort="descending"]::after { content:" ▼"; color:var(--primary); }

/* ---- Forms ---- */
.form-control, .form-select {
  background: var(--surface); color: var(--on-surface);
  border:1px solid var(--border-strong); border-radius: var(--r-sm);
  min-height: 42px;
}
.form-control::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
.form-label { font-weight:600; font-size:var(--fs-sm); color:var(--on-surface-strong); margin-bottom:.35rem; }
.form-text, .form-hint { color: var(--muted); font-size: var(--fs-xs); }
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--fs-xs); margin-top:.3rem; display:block; }
.req::after { content:" *"; color: var(--danger); }

/* ---- Badges / status chips ---- */
.badge { font-weight:600; border-radius: var(--r-pill); }
.chip { display:inline-flex; align-items:center; gap:.4em; padding:.25em .7em; border-radius:var(--r-pill); font-size:var(--fs-xs); font-weight:700; letter-spacing:.02em; }
.chip-dot::before { content:""; width:.5em; height:.5em; border-radius:50%; background:currentColor; }
.chip-success{ background:var(--success-soft); color:var(--success); }
.chip-warn{ background:var(--warn-soft); color:var(--warn); }
.chip-danger{ background:var(--danger-soft); color:var(--danger); }
.chip-info{ background:var(--info-soft); color:var(--info); }
.chip-primary{ background:var(--primary-soft); color:var(--primary); }
.chip-muted{ background:var(--surface-sunken); color:var(--muted); }

/* ---- Alerts ---- */
.alert { border:1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); color: var(--on-surface); }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb,var(--success) 30%,transparent); color: var(--success); }
.alert-danger  { background: var(--danger-soft);  border-color: color-mix(in srgb,var(--danger) 30%,transparent);  color: var(--danger); }
.alert-info    { background: var(--info-soft);    border-color: color-mix(in srgb,var(--info) 30%,transparent);    color: var(--info); }

/* ---- Stat cards ---- */
.stat-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--r-lg); box-shadow:var(--shadow-sm); }
.stat-icon { width:46px;height:46px;border-radius:var(--r-md);display:grid;place-items:center;font-size:1.3rem; background:var(--primary-soft); color:var(--primary); }
.stat-value { font-family:var(--font-display); font-weight:700; font-size:var(--fs-2xl); color:var(--on-surface-strong); line-height:1.1; }
.stat-label { color:var(--muted); font-size:var(--fs-sm); }

/* ---- Skeleton + empty states ---- */
.skeleton { background:linear-gradient(90deg,var(--surface-2) 25%,var(--surface-sunken) 37%,var(--surface-2) 63%); background-size:400% 100%; animation:ib-shimmer 1.4s ease infinite; border-radius:var(--r-sm); }
@keyframes ib-shimmer { 0%{background-position:100% 0} 100%{background-position:0 0} }
.empty-state { text-align:center; padding:var(--sp-10) var(--sp-6); color:var(--muted); }
.empty-state .ic { width:44px;height:44px;margin:0 auto var(--sp-3); color:var(--muted); opacity:.7; }

/* ---- App shell chrome (shared by admin modules) ---- */
.ib-shell { display:flex; min-height:100dvh; }
.ib-sidebar { width:260px; flex-shrink:0; background:var(--sidebar-bg,var(--surface)); border-right:1px solid var(--border); position:sticky; top:0; height:100dvh; overflow-y:auto; z-index:var(--z-nav); }
.ib-brand { padding:var(--sp-5) var(--sp-4); display:flex; align-items:center; gap:.6rem; color:var(--sidebar-on,var(--on-surface-strong)); font-family:var(--font-display); font-weight:800; }
.ib-brand .mark { width:30px;height:30px;border-radius:9px;display:grid;place-items:center;background:var(--primary);color:var(--on-primary); }
.ib-brand small { display:block; font-weight:500; font-size:var(--fs-xs); opacity:.7; letter-spacing:.02em; }
.ib-navsec { padding:var(--sp-4) var(--sp-4) var(--sp-1); font-size:var(--fs-xs); text-transform:uppercase; letter-spacing:.08em; color:var(--sidebar-muted,var(--muted)); opacity:.8; }
.ib-navlink { display:flex; align-items:center; gap:.65rem; margin:2px var(--sp-2); padding:.6rem .75rem; border-radius:var(--r-sm); color:var(--sidebar-link,var(--on-surface)); font-size:var(--fs-sm); font-weight:500; text-decoration:none; }
.ib-navlink:hover { background:var(--sidebar-hover,var(--surface-2)); color:var(--sidebar-on,var(--on-surface-strong)); }
.ib-navlink.active { background:var(--primary); color:var(--on-primary); }
.ib-navlink svg { width:18px;height:18px;flex-shrink:0; }
.ib-main { flex:1; min-width:0; display:flex; flex-direction:column; }
.ib-topbar { position:sticky; top:0; z-index:var(--z-sticky); background:color-mix(in srgb,var(--surface) 88%, transparent); backdrop-filter:blur(10px); border-bottom:1px solid var(--border); padding:.7rem 1.25rem; display:flex; align-items:center; justify-content:space-between; gap:1rem; }
.ib-content { padding:var(--sp-6); max-width:1440px; width:100%; }
.ib-iconbtn { width:38px;height:38px;border-radius:var(--r-sm);border:1px solid var(--border-strong);background:var(--surface);color:var(--on-surface);display:grid;place-items:center;cursor:pointer; }
.ib-iconbtn:hover { background:var(--surface-2); }

/* ---- Mobile sidebar ---- */
.ib-overlay { display:none; position:fixed; inset:0; background:var(--scrim); z-index:calc(var(--z-nav) - 1); }
@media (max-width: 991.98px){
  .ib-sidebar{ position:fixed; left:0; top:0; transform:translateX(-100%); transition:transform .25s var(--ease); box-shadow:var(--shadow-lg); }
  .ib-sidebar.open{ transform:none; }
  .ib-overlay.open{ display:block; }
  .ib-content{ padding:var(--sp-4); }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after { animation-duration:.001ms !important; animation-iteration-count:1 !important; transition-duration:.001ms !important; }
}
