/* ============================================================
   base.css — design tokens, resets, typography, utilities
   ============================================================ */

:root {
  /* UI Studio Design System Tokens (Defaults) */
  --bg: #eef1f6;
  --panel: #ffffff;
  --panel2: #f6f8fb;
  --text: #18212f;
  --muted: #64708a;
  --line: #dde3ee;
  --accent: #1f5fbf;
  --accent-t: #ffffff;
  --accent2: #0f9d8f;
  --heading-color: var(--primary, var(--accent, #1f5fbf));
  --menupath-bg: var(--primary, var(--accent, #1f5fbf));
  --menupath-text: var(--accent-t, #ffffff);
  --menupath-border: color-mix(in srgb, var(--primary, var(--accent, #1f5fbf)) 82%, black);
  --menupath-current: var(--accent-t, #ffffff);
  --menupath-sep: color-mix(in srgb, var(--accent-t, #ffffff) 70%, transparent);
  --balloon-bg: #0f172a;
  --balloon-text: #f8fafc;
  --balloon-border: rgba(255, 255, 255, 0.15);
  --balloon-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.35), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
  --head: #eef2fa;
  --hover: #eaf1ff;
  --alt: #fafbfd;
  --good: #2fbf71;
  --warn: #f0a020;
  --bad: #e5484d;
  /* Executive Dashboard & CMYK Ink Tokens */
  --key: #1f2a44;
  --c: #0a8fc2;
  --m: #d02a73;
  --y: #e0a000;
  --ok: #1f8f5f;
  --grid: #e6e9ef;
  --ink: var(--key);
  --sf: var(--panel, #ffffff);
  --tx: var(--text, #18212f);
  --mu: var(--muted, #5d667a);
  --ln: var(--line, #dde3ee);
  --toolbar-bg: var(--head, #eef2fa);
  --toolbar-text: var(--text, #18212f);
  --toolbar-border: var(--line, #dde3ee);
  --topbar-bg: var(--panel, #ffffff);
  --topbar-text: var(--text, #18212f);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --hfont: var(--font);
  --upper: none;
  --track: 0;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.08);
  --bg-img: none;
  --brk: none;
  color-scheme: light;

  /* Density Default Tokens (Formal) */
  --py: 6px;
  --px: 12px;
  --fs: 13px;
  --gap: 12px;

  /* Corner Radius Default Token (Soft) */
  --r: 8px;

  /* Neutrals (mapped to Studio Tokens) */
  --surface: var(--panel, #ffffff);
  --surface-2: var(--panel2, #f8fafc);
  --border: var(--line, #dfe5ee);
  --border-strong: var(--line, #c7d0dd);
  --text-muted: var(--muted, #61707f);
  --text-faint: #8b98a7;

  /* Brand */
  --primary: var(--accent, #1f5fbf);
  --primary-dark: #17488f;
  --primary-soft: var(--hover, #e8f0fc);

  /* Status */
  --danger: var(--bad, #c62f2f);
  --danger-soft: #fdeaea;
  --warning: var(--warn, #b07207);
  --warning-soft: #fdf3e2;
  --success: var(--good, #1c7c47);
  --success-soft: #e6f5ec;
  --info: #2266aa;
  --info-soft: #e7f0fb;

  /* Sidebar */
  --sidebar-bg: #16233a;
  --sidebar-bg-2: #1d2d49;
  --sidebar-text: #c3cede;
  --sidebar-active: #27406b;
  --sidebar-width: 264px;
  --sidebar-width-collapsed: 64px;

  /* Header */
  --header-height: 56px;

  /* Misc (Geometry & Typography) */
  --radius: var(--r, 8px);
  --radius-sm: calc(var(--r, 8px) * 0.6);
  --radius-lg: calc(var(--r, 8px) * 1.4);
  --shadow-sm: var(--shadow, 0 1px 2px rgba(16, 30, 54, 0.08));
  --shadow-md: 0 6px 18px rgba(16, 30, 54, 0.12);
  --shadow-panel: -8px 0 32px rgba(16, 30, 54, 0.18);
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Z-index scale */
  --z-header: 100;
  --z-sidebar: 90;
  --z-overlay: 200;
  --z-panel: 210;
  --z-dropdown: 300;
  --z-modal: 400;
  --z-dialog: 400;
  --z-toast: 500;

  /* Extended tokens (component layer) */
  --surface-1: var(--panel, #ffffff);
  --surface-3: var(--head, #eef1f6);
  --surface-4: var(--hover, #e2e8f0);
  --text-2: var(--text, #3f4c5a);
  --primary-400: #4b83e0;
  --primary-50: var(--alt, #f2f7ff);
  --primary-100: #dce8fb;
  --primary-700: #17488f;
  --border-soft: var(--line, #eaeff5);
  --placeholder: #98a3b1;
  --topbar-height: var(--header-height);
  --sidebar-width-drawer: var(--sidebar-width);
  --font-weight-bold: 700;
}

/* Density Scale Overrides */
:root[data-density="compact"],
[data-density="compact"] {
  --py: 2px;
  --px: 8px;
  --fs: 12px;
  --gap: 8px;
}

:root[data-density="formal"],
[data-density="formal"] {
  --py: 6px;
  --px: 12px;
  --fs: 13px;
  --gap: 12px;
}

:root[data-density="easy"],
[data-density="easy"] {
  --py: 12px;
  --px: 16px;
  --fs: 14.5px;
  --gap: 18px;
}

/* Corner Radius Scale Overrides */
:root[data-radius="sharp"],
[data-radius="sharp"] {
  --r: 0px;
  --radius: 0px;
  --radius-sm: 0px;
  --radius-lg: 0px;
}

:root[data-radius="soft"],
[data-radius="soft"] {
  --r: 9px;
  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
}

/* Monospace shorthand used across forms/tables */
:root { --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }

/* [hidden] must beat component display rules (flex/grid) */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: var(--fs);
  letter-spacing: var(--track);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-img);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; color: var(--heading-color, var(--primary, var(--accent, #1f5fbf))); }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

code, .mono { font-family: var(--font-mono); font-size: 0.92em; }

/* ---------- Utility classes ---------- */
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Focus visibility (keyboard nav) ---------- */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-radius: 3px;
}

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-active::before,
.badge-inactive::before,
.badge-locked::before,
.badge-normal::before,
.badge-consolidation::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-active { background: var(--success-soft); color: var(--success); }
.badge-inactive { background: #eef1f5; color: var(--text-muted); }
.badge-locked { background: var(--danger-soft); color: var(--danger); }
.badge-normal { background: var(--info-soft); color: var(--info); }
.badge-consolidation { background: var(--warning-soft); color: var(--warning); }
.badge-plain::before { display: none; }

/* .chip is defined in forms.css (chip + removable chip__remove) */

/* ---------- Spinner ---------- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.center-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  color: var(--text-muted);
  text-align: center;
}
.center-state .state-icon { font-size: 34px; opacity: 0.5; }
