/* ============================================================
   ERP IN ABC — Industrial Press Design System
   Single shared stylesheet. All 16 pages + index.html inherit.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* ===== Palette ===== */
  --paper:        #f5f1e8;   /* canvas — warm paper */
  --paper-2:      #ece7d7;   /* hover / striping */
  --paper-3:      #e0dac6;   /* deeper stripe */
  --canvas:       #fbfaf5;   /* card surface (lighter than paper) */

  --ink:          #14130f;   /* primary text, dark sidebar */
  --ink-2:        #1f1d18;   /* hovered ink */
  --ink-3:        #2b2820;   /* divider on dark */

  --ash:          #6b665b;   /* secondary text */
  --ash-2:        #918b7e;   /* tertiary text */
  --ash-3:        #b8b2a2;   /* placeholder text */

  --rule:         #d8d2c0;   /* hairline rule */
  --rule-soft:    #e8e3d3;   /* soft rule */
  --rule-hair:    #efebde;   /* faintest rule */

  --rust:         #c5400a;   /* PRIMARY accent — ink pigment */
  --rust-2:       #e85a2a;   /* lighter rust hover */
  --rust-soft:    #f4e2d6;   /* tint surface */
  --rust-deep:    #8a2d07;   /* hover for filled */

  --moss:         #2f5d3a;   /* success */
  --moss-soft:    #dde8d8;
  --moss-deep:    #1f4127;

  --amber:        #9c7714;   /* warning */
  --amber-soft:   #f0e6c4;

  --signal:       #8a1f1f;   /* error / overdue */
  --signal-soft:  #efd5d5;

  --steel:        #4a5560;   /* cool neutral (info) */
  --steel-soft:   #e0e5ea;

  /* ===== Type ===== */
  --ff-sans: 'Geist', 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --ff-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

  /* ===== Space ===== */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 28px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-20: 80px;
  --sp-24: 96px;

  /* ===== Radius ===== */
  --r-1: 2px;
  --r-2: 4px;
  --r-3: 6px;
  --r-4: 8px;
  --r-5: 10px;
  --r-6: 12px;
  --r-8: 16px;
  --r-pill: 9999px;

  /* aliases for legacy class names (so 16 pages don't break) */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 12px;
  --r-xxl: 14px;
  --r-xxxl: 16px;
  --r-feature: 18px;
  --r-full: 9999px;

  /* legacy color aliases — kept so old pages still resolve, mapped to new palette */
  --brand-yellow: var(--rust);
  --brand-yellow-deep: var(--rust-deep);
  --yellow-light: var(--rust-soft);
  --yellow-dark: var(--rust-deep);
  --surface-yellow: var(--rust-soft);
  --brand-blue: var(--steel);
  --blue-450: var(--steel);
  --blue-pressed: var(--ink);
  --surface-blue: var(--steel-soft);
  --brand-coral: var(--rust);
  --coral-light: var(--rust-soft);
  --coral-dark: var(--rust-deep);
  --brand-rose: var(--rust-soft);
  --rose-light: var(--rust-soft);
  --brand-pink: var(--rust-soft);
  --brand-teal: var(--moss);
  --teal-light: var(--moss-soft);
  --moss-dark: var(--moss-deep);
  --brand-orange-light: var(--rust-soft);
  --brand-red: var(--signal-soft);
  --brand-red-dark: var(--signal);
  --success-accent: var(--moss);
  --warning: var(--amber);
  --danger: var(--signal);

  --surface: var(--paper-2);
  --surface-soft: var(--paper);
  --hairline: var(--rule);
  --hairline-soft: var(--rule-soft);
  --hairline-strong: var(--rule);

  --ink-deep: var(--ink);
  --charcoal: var(--ink);
  --slate: var(--ash);
  --stone: var(--ash);
  --muted: var(--ash-2);
  --on-dark: var(--paper);
  --on-dark-muted: var(--ash-2);
  --footer-bg: var(--ink);

  /* ===== Shadow (rarely used — flat by default) ===== */
  --shadow-1: 0 1px 0 var(--rule-soft);
  --shadow-2: 0 1px 0 var(--rule);
  --shadow-3: 0 2px 0 var(--rule);
  --shadow-4: 0 4px 12px rgba(20, 19, 15, 0.06);
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--ff-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: var(--rust); text-decoration: none; }
a:hover { text-decoration: none; color: var(--rust-deep); }

::selection { background: var(--ink); color: var(--paper); }

/* Scrollbars — minimal */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: var(--ash-2); }

/* ============================================================
   Typography utility classes
   ============================================================ */
.t-hero        { font-size: 64px; font-weight: 500; line-height: 1.02; letter-spacing: -0.025em; }
.t-display-lg  { font-size: 48px; font-weight: 500; line-height: 1.05; letter-spacing: -0.02em; }
.t-h1          { font-size: 32px; font-weight: 500; line-height: 1.1; letter-spacing: -0.015em; }
.t-h2          { font-size: 24px; font-weight: 500; line-height: 1.18; letter-spacing: -0.01em; }
.t-h3          { font-size: 20px; font-weight: 500; line-height: 1.25; letter-spacing: -0.005em; }
.t-h4          { font-size: 17px; font-weight: 500; line-height: 1.3; }
.t-h5          { font-size: 15px; font-weight: 600; line-height: 1.35; }
.t-subtitle    { font-size: 15px; font-weight: 400; line-height: 1.5; color: var(--ash); }
.t-body        { font-size: 14px; font-weight: 400; line-height: 1.55; }
.t-body-m      { font-size: 14px; font-weight: 500; line-height: 1.55; }
.t-body-sm     { font-size: 13px; font-weight: 400; line-height: 1.5; }
.t-body-sm-m   { font-size: 13px; font-weight: 500; line-height: 1.5; }
.t-caption     { font-size: 12px; font-weight: 400; line-height: 1.4; color: var(--ash); }
.t-caption-b   { font-size: 12px; font-weight: 500; line-height: 1.4; }
.t-micro       { font-size: 11px; font-weight: 500; line-height: 1.4; }
.t-micro-u     { font-size: 10px; font-weight: 600; line-height: 1.4; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ash); font-family: var(--ff-mono); }
.t-mono        { font-family: var(--ff-mono); }

.text-ink      { color: var(--ink) !important; }
.text-steel    { color: var(--ash) !important; }
.text-coral-dark { color: var(--rust-deep) !important; }
.text-success  { color: var(--moss) !important; }
.text-warning  { color: var(--amber) !important; }
.text-danger   { color: var(--signal) !important; }
.text-muted    { color: var(--ash-2) !important; }

/* Tabular numerals — for finance numbers */
.num, .kpi-value, .tbl .num, .ff-mono { font-variant-numeric: tabular-nums; }

/* ============================================================
   Spacing utilities
   ============================================================ */
.mt-0 { margin-top: 0 !important; }   .mb-0 { margin-bottom: 0 !important; }
.mt-1 { margin-top: 4px; }            .mb-1 { margin-bottom: 4px; }
.mt-2 { margin-top: 8px; }            .mb-2 { margin-bottom: 8px; }
.mt-3 { margin-top: 12px; }           .mb-3 { margin-bottom: 12px; }
.mt-4 { margin-top: 16px; }           .mb-4 { margin-bottom: 16px; }
.mt-5 { margin-top: 20px; }           .mb-5 { margin-bottom: 20px; }
.mt-6 { margin-top: 24px; }           .mb-6 { margin-bottom: 24px; }
.mt-8 { margin-top: 32px; }           .mb-8 { margin-bottom: 32px; }
.p-2 { padding: 8px; }
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }

/* ============================================================
   Layout primitives
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  background: var(--ink);
  color: var(--paper);
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 0;
}
.sidebar::-webkit-scrollbar-thumb { background: var(--ink-3); }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--ash); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 22px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--ink-3);
}
.sidebar-logo-mark {
  width: 36px; height: 36px;
  background: var(--rust);
  color: var(--paper);
  font-family: var(--ff-sans);
  font-weight: 600;
  font-size: 16px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center; justify-content: center;
  letter-spacing: -0.01em;
  position: relative;
}
.sidebar-logo-mark::after {
  content: ""; position: absolute; right: -2px; bottom: -2px;
  width: 8px; height: 8px; background: var(--paper); border-radius: 9999px;
}
.sidebar-logo-text {
  display: flex; flex-direction: column;
  gap: 2px;
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--paper);
  line-height: 1.2;
}
.sidebar-logo-text small {
  font-family: var(--ff-mono);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ash-2);
}

.nav-section { margin-bottom: 14px; }
.nav-section-title {
  font-family: var(--ff-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ash-2);
  padding: 6px 10px;
  margin-bottom: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 400;
  color: rgba(245, 241, 232, 0.7);
  border-radius: var(--r-2);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition: color 140ms ease, background 140ms ease;
  line-height: 1.3;
}
.nav-item:hover {
  color: var(--paper);
  background: rgba(255, 255, 255, 0.04);
  text-decoration: none;
}
.nav-item.active {
  color: var(--paper);
  background: rgba(255, 255, 255, 0.06);
  border-left-color: var(--rust);
  font-weight: 500;
}
.nav-icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}
.nav-item.active .nav-icon { color: var(--rust-2); opacity: 1; }

.main {
  min-width: 0;
  overflow-x: hidden;
  background: var(--paper);
}

.topbar {
  height: 56px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.breadcrumb {
  font-size: 13px;
  color: var(--ash);
  display: flex;
  align-items: center;
  gap: 6px;
}
.breadcrumb b { color: var(--ink); font-weight: 600; }
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-search {
  background: transparent;
  border: 0;
  outline: none;
  font-family: var(--ff-sans);
  font-size: 13px;
  color: var(--ink);
  width: 240px;
}
.input-search::placeholder { color: var(--ash-2); }
.topbar > div.input-search,
.topbar div[class*="input-search"] {
  background: var(--paper-2);
  border-radius: var(--r-3);
  padding: 0 12px;
  height: 32px;
  border: 1px solid transparent;
  transition: border-color 140ms ease;
}
.topbar div[class*="input-search"]:focus-within { border-color: var(--rule); background: var(--canvas); }

.btn-icon {
  width: 32px; height: 32px;
  background: transparent;
  border: 0;
  border-radius: var(--r-3);
  display: inline-flex;
  align-items: center; justify-content: center;
  color: var(--ash);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}
.btn-icon:hover { background: var(--paper-2); color: var(--ink); }

.avatar {
  width: 32px; height: 32px;
  border-radius: 9999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center; justify-content: center;
  cursor: pointer;
  letter-spacing: 0.04em;
}

.content {
  padding: 28px 32px;
  max-width: 1480px;
  min-width: 0;
}

/* ============================================================
   Page header
   ============================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header h1 {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  letter-spacing: -0.015em;
}
.page-header p {
  color: var(--ash);
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.5;
}
.page-header .actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-family: var(--ff-sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  border-radius: var(--r-3);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 80ms ease;
  white-space: nowrap;
  letter-spacing: 0.005em;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.btn-primary:hover { background: var(--ink-2); border-color: var(--ink-2); color: var(--paper); text-decoration: none; }

.btn-secondary {
  background: var(--canvas);
  color: var(--ink);
  border-color: var(--rule);
}
.btn-secondary:hover { border-color: var(--ink); background: var(--canvas); color: var(--ink); text-decoration: none; }

.btn-yellow,
.btn-accent {
  background: var(--rust);
  color: var(--paper);
  border-color: var(--rust);
}
.btn-yellow:hover,
.btn-accent:hover { background: var(--rust-deep); border-color: var(--rust-deep); color: var(--paper); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--paper-2); color: var(--ink); text-decoration: none; }

.btn-link {
  display: inline;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--rust);
  font-family: inherit;
  font-size: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  line-height: 1.3;
}
.btn-link:hover { color: var(--rust-deep); text-decoration: none; }

.btn-sm { padding: 5px 10px; font-size: 12px; gap: 4px; }
.btn-lg { padding: 12px 22px; font-size: 14px; }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--canvas);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-5);
  padding: 20px;
  min-width: 0;
}

.card-feature,
.card-feature-yellow,
.card-feature-blue,
.card-feature-teal,
.card-feature-coral,
.card-feature-rose,
.card-feature-orange,
.card-feature-rosegray {
  background: var(--canvas);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-5);
  padding: 20px;
  min-width: 0;
  position: relative;
}
/* Tiny color stamp top-left — printer's mark */
.card-feature::before,
.card-feature-yellow::before,
.card-feature-blue::before,
.card-feature-teal::before,
.card-feature-coral::before,
.card-feature-rose::before,
.card-feature-orange::before,
.card-feature-rosegray::before {
  content: "";
  position: absolute;
  top: -1px; left: 20px;
  width: 28px; height: 3px;
  background: var(--ash-2);
  border-radius: 0 0 2px 2px;
}
.card-feature-yellow::before  { background: var(--rust); }
.card-feature-blue::before    { background: var(--steel); }
.card-feature-teal::before    { background: var(--moss); }
.card-feature-coral::before   { background: var(--rust-2); }
.card-feature-rose::before    { background: var(--rust-soft); }
.card-feature-orange::before  { background: var(--amber); }
.card-feature-rosegray::before { background: var(--ash); }

/* ============================================================
   KPI cards
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--canvas);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-5);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  position: relative;
}
.kpi-mark {
  width: 28px; height: 28px;
  display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: var(--r-3);
  margin-bottom: 8px;
}
.kpi-label {
  font-family: var(--ff-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ash);
}
.kpi-value {
  font-size: 28px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.kpi-trend {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 400;
  color: var(--ash);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.kpi-trend.up { color: var(--moss); }
.kpi-trend.down { color: var(--signal); }

/* ============================================================
   Grid utilities
   ============================================================ */
.grid { display: grid; gap: 12px; min-width: 0; }
.grid-2  { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid-3  { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4  { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-12 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* ============================================================
   Flex utilities
   ============================================================ */
.flex { display: flex; min-width: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; min-width: 0; gap: 8px; }
.flex-gap-2 { display: flex; gap: 8px; align-items: center; }
.flex-gap-3 { display: flex; gap: 12px; align-items: center; }

/* ============================================================
   Inputs
   ============================================================ */
.input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-family: var(--ff-sans);
  font-size: 13px;
  color: var(--ink);
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: var(--r-3);
  outline: none;
  transition: border-color 140ms ease, background 140ms ease;
}
.input::placeholder { color: var(--ash-2); }
.input:focus { border-color: var(--ink); background: var(--canvas); }
.input.input-search { padding-left: 32px; background-position: 10px center; background-repeat: no-repeat; }

/* Inline search icon prefix via pseudo on wrapper */
[class*="input-search"] { position: relative; }

/* ============================================================
   Tables
   ============================================================ */
.table-wrap {
  background: var(--canvas);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-5);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

table.tbl {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl thead th {
  text-align: left;
  font-family: var(--ff-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ash);
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  white-space: nowrap;
}
.tbl tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule-hair);
  vertical-align: middle;
  color: var(--ink);
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background 120ms ease; }
.tbl tbody tr:hover { background: var(--paper-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .center { text-align: center; }
.tbl tbody tr.row-selected { background: var(--rust-soft); }
.tbl tbody tr.row-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--rust);
}

/* ============================================================
   Tabs (filter pills)
   ============================================================ */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 3px;
  background: var(--paper-2);
  border-radius: var(--r-3);
  width: fit-content;
  max-width: 100%;
}
.tab {
  padding: 6px 12px;
  font-family: var(--ff-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ash);
  background: transparent;
  border: 0;
  border-radius: var(--r-2);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
  white-space: nowrap;
  letter-spacing: 0.005em;
}
.tab:hover { color: var(--ink); }
.tab-active {
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--rule);
}

/* ============================================================
   Filter pills (standalone)
   ============================================================ */
.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: var(--ff-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
  white-space: nowrap;
}
.filter-pill:hover { border-color: var(--ink); }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-family: var(--ff-sans);
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--r-2);
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid transparent;
  white-space: nowrap;
  letter-spacing: 0.005em;
}
.badge-yellow,
.badge-rust   { background: var(--rust-soft); color: var(--rust-deep); border-color: rgba(197, 64, 10, 0.18); }
.badge-blue,
.badge-steel  { background: var(--steel-soft); color: var(--steel); border-color: rgba(74, 85, 96, 0.18); }
.badge-coral  { background: var(--rust-soft); color: var(--rust-deep); border-color: rgba(197, 64, 10, 0.18); }
.badge-teal,
.badge-moss   { background: var(--moss-soft); color: var(--moss-deep); border-color: rgba(47, 93, 58, 0.18); }
.badge-rose   { background: var(--rust-soft); color: var(--rust-deep); border-color: rgba(197, 64, 10, 0.12); }
.badge-green  { background: var(--moss-soft); color: var(--moss-deep); border-color: rgba(47, 93, 58, 0.18); }
.badge-orange { background: var(--amber-soft); color: var(--amber); border-color: rgba(156, 119, 20, 0.2); }
.badge-dot {
  display: inline-block;
  width: 6px; height: 6px; border-radius: 9999px;
}

.status-warning  { background: var(--amber-soft); color: var(--amber); border-color: rgba(156, 119, 20, 0.2); }
.status-due      { background: var(--steel-soft); color: var(--steel); border-color: rgba(74, 85, 96, 0.2); }
.status-overdue  { background: var(--signal-soft); color: var(--signal); border-color: rgba(138, 31, 31, 0.2); }
.status-ok       { background: var(--moss-soft); color: var(--moss-deep); border-color: rgba(47, 93, 58, 0.2); }

/* ============================================================
   Progress
   ============================================================ */
.progress {
  height: 4px;
  background: var(--paper-3);
  border-radius: 9999px;
  overflow: hidden;
  width: 100%;
}
.progress > div {
  height: 100%;
  background: var(--ink);
  border-radius: 9999px;
  transition: width 320ms ease;
}
.progress.success > div { background: var(--moss); }
.progress.warn > div { background: var(--amber); }
.progress.danger > div { background: var(--signal); }

/* ============================================================
   Sticky notes (action chips on dashboard)
   ============================================================ */
.sticky {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  font-family: var(--ff-sans);
  font-size: 13px;
  font-weight: 500;
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: var(--r-3);
  text-decoration: none;
  transition: border-color 140ms ease, background 140ms ease, transform 80ms ease;
}
.sticky:hover { border-color: var(--ink); text-decoration: none; transform: translateY(-1px); }
.sticky.pink    { background: var(--rust-soft); border-color: rgba(197,64,10,0.2); color: var(--rust-deep); }
.sticky.teal    { background: var(--moss-soft); border-color: rgba(47,93,58,0.2); color: var(--moss-deep); }
.sticky.coral   { background: var(--rust-soft); border-color: rgba(197,64,10,0.2); color: var(--rust-deep); }
.sticky.blue    { background: var(--steel-soft); border-color: rgba(74,85,96,0.2); color: var(--steel); }

/* ============================================================
   Chip / dot
   ============================================================ */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--moss); }
.dot.yellow { background: var(--rust); }
.dot.red { background: var(--signal); }
.dot.blue { background: var(--steel); }

/* ============================================================
   Divider / rule
   ============================================================ */
.divider { height: 1px; background: var(--rule-soft); margin: 20px 0; }
.hr-soft { border: 0; border-top: 1px solid var(--rule-soft); margin: 12px 0; }

.timeline-item { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--rule-hair); }
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--paper-2); color: var(--ink); font-size: 12px; }

/* ============================================================
   Hero band (legacy)
   ============================================================ */
.hero-band {
  background: var(--canvas);
  padding: 80px 32px;
  text-align: center;
  border-bottom: 1px solid var(--rule);
}

/* ============================================================
   Toast notifications
   ============================================================ */
.toast-stack {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 1000;
  pointer-events: none;
}
/* Đẩy toast lên khi có FAB Trợ lý AI để không che nút */
body:has(.ai-fab) .toast-stack { bottom: 88px; }
.toast {
  min-width: 260px; max-width: 380px;
  background: var(--ink);
  color: var(--paper);
  padding: 12px 16px;
  border-radius: var(--r-3);
  font-size: 13px;
  font-weight: 400;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 12px 28px rgba(20, 19, 15, 0.18);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(10px);
  animation: toast-in 220ms cubic-bezier(.2,.8,.2,1) forwards;
  border-left: 3px solid var(--rust);
}
.toast.is-leaving { animation: toast-out 200ms ease forwards; }
.toast .toast-icon {
  width: 24px; height: 24px; flex-shrink: 0;
  background: rgba(245, 241, 232, 0.1);
  border-radius: 9999px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--rust-2);
}
.toast .toast-msg { flex: 1; line-height: 1.4; font-weight: 400; }
.toast .toast-msg b { color: var(--rust-2); font-weight: 600; }
.toast-success { border-left-color: var(--moss); }
.toast-success .toast-icon { color: var(--moss); background: rgba(47, 93, 58, 0.15); }
.toast-success .toast-msg b { color: #8db58f; }
.toast-info { border-left-color: var(--rust); }
.toast-warning { border-left-color: var(--amber); }
.toast-warning .toast-icon { color: var(--amber); background: rgba(156, 119, 20, 0.18); }
.toast-warning .toast-msg b { color: #e0c060; }
.toast-error { border-left-color: var(--signal); }
.toast-error .toast-icon { color: var(--signal); background: rgba(138, 31, 31, 0.18); }
.toast-error .toast-msg b { color: #d77878; }

@keyframes toast-in  { to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

/* ============================================================
   Modal overlay
   ============================================================ */
.erp-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 19, 15, 0.45);
  backdrop-filter: blur(2px);
  z-index: 900;
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
  opacity: 0;
  animation: overlay-in 180ms ease forwards;
}
.erp-modal-overlay.is-leaving { animation: overlay-out 160ms ease forwards; }
.erp-modal {
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: var(--r-5);
  max-width: 560px; width: 100%;
  max-height: 80vh; overflow-y: auto;
  padding: 28px;
  transform: scale(0.96);
  animation: modal-in 200ms cubic-bezier(.2,.8,.2,1) forwards;
}
.erp-modal h3 {
  font-size: 18px; font-weight: 600; margin-bottom: 8px;
  letter-spacing: -0.005em;
}
.erp-modal p { color: var(--ash); margin-bottom: 12px; line-height: 1.55; font-size: 14px; }
.erp-modal .erp-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

@keyframes overlay-in  { to { opacity: 1; } }
@keyframes overlay-out { to { opacity: 0; } }
@keyframes modal-in    { to { transform: scale(1); } }

/* ============================================================
   Click flash (on button click)
   ============================================================ */
.erp-flash {
  animation: erp-flash 600ms ease;
}
@keyframes erp-flash {
  0%   { box-shadow: 0 0 0 0 rgba(197, 64, 10, 0.5); }
  100% { box-shadow: 0 0 0 8px rgba(197, 64, 10, 0); }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .grid-12 { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
}

@media (max-width: 1024px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .content { padding: 24px 24px; }
  .grid-12, .grid-2 { grid-template-columns: 1fr; }
  .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .input-search { width: 200px !important; }
}

@media (max-width: 768px) {
  .app { grid-template-columns: 60px minmax(0, 1fr); }
  .sidebar { padding: 14px 8px; }
  .sidebar-logo { padding: 8px 4px 16px; justify-content: center; border-bottom-color: var(--ink-3); }
  .sidebar-logo-text,
  .nav-section-title { display: none; }
  .nav-item {
    justify-content: center;
    padding: 10px 6px;
  }
  .nav-item span:not(.nav-icon) { display: none; }
  .content { padding: 20px 16px; }
  .topbar { padding: 0 16px; }
  .topbar .breadcrumb { font-size: 12px; }
  .input-search { display: none !important; }
  .page-header h1 { font-size: 22px; }
  .grid-2, .grid-3, .grid-4, .kpi-grid, .grid-12 { grid-template-columns: 1fr; }
  .card, .kpi { padding: 16px; }
  .toast { min-width: 200px; max-width: calc(100vw - 32px); }
  .toast-stack { right: 12px; left: 12px; bottom: 12px; }
}

@media (max-width: 480px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 16px 12px; }
}

/* ============================================================
   GROUP SWITCHER — sidebar entity dropdown (multi-company)
   ============================================================ */

.entity-block {
  position: relative;
  margin: 12px 12px 16px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r-4);
  background: var(--canvas);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  cursor: default;
  transition: border-color 140ms ease, background 140ms ease;
}
.entity-block.is-clickable { cursor: pointer; }
.entity-block.is-clickable:hover { border-color: var(--ink); background: var(--paper-2); }

.entity-mark {
  flex-shrink: 0;
  width: 30px; height: 30px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--r-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
  letter-spacing: -0.01em;
}
.entity-mark.is-group {
  background: var(--rust);
  font-size: 16px;
}

.entity-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.entity-info .e-name {
  font-size: 12px; font-weight: 600; color: var(--ink);
  letter-spacing: -0.005em;
  display: flex; align-items: center; gap: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.entity-info .e-name .chev {
  width: 12px; height: 12px; color: var(--ash);
  transition: transform 160ms ease;
}
.entity-block.is-open .e-name .chev { transform: rotate(180deg); }
.entity-info .e-sub {
  font-family: var(--ff-mono);
  font-size: 8.5px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ash);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Dropdown panel */
.entity-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: var(--r-4);
  box-shadow: 0 12px 32px rgba(20, 19, 15, 0.12), 0 0 0 1px var(--rule);
  padding: 10px 0;
  z-index: 50;
  display: none;
}
.entity-block.is-open .entity-dropdown { display: block; }

.entity-dropdown .ed-group-label {
  padding: 8px 14px 6px;
  font-family: var(--ff-mono);
  font-size: 9px; font-weight: 500;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ash-2);
}
.entity-dropdown .ed-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 12.5px; color: var(--ink);
  border: 0; background: transparent; width: 100%; text-align: left;
}
.entity-dropdown .ed-item:hover { background: var(--paper-2); }
.entity-dropdown .ed-item .ed-dot {
  width: 8px; height: 8px; border-radius: 9999px;
  background: transparent; border: 1px solid var(--ash-2); flex-shrink: 0;
}
.entity-dropdown .ed-item.is-active { font-weight: 600; background: var(--paper-2); }
.entity-dropdown .ed-item.is-active .ed-dot { background: var(--rust); border-color: var(--rust); }
.entity-dropdown .ed-item .ed-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.entity-dropdown .ed-item .ed-segment {
  font-family: var(--ff-mono);
  font-size: 8.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ash);
}
.entity-dropdown .ed-divider {
  height: 1px; background: var(--rule-soft); margin: 6px 0;
}

/* ============================================================
   DEMO USER PICKER — tiny dropdown near avatar (debug)
   ============================================================ */
.demo-user-picker {
  position: relative;
}
.demo-user-picker .dup-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}
.demo-user-picker .dup-trigger:hover {
  border-color: var(--ink);
  background: var(--canvas);
}
.demo-user-picker .dup-avatar {
  width: 24px; height: 24px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 9999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--ff-mono);
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.demo-user-picker .dup-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}
/* Dropdown panel */
.demo-user-picker .dup-menu {
  position: absolute;
  top: calc(100% + 8px); right: 0;
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: var(--r-4);
  box-shadow: 0 16px 40px rgba(20, 19, 15, 0.14), 0 2px 6px rgba(20, 19, 15, 0.06);
  padding: 6px;
  min-width: 320px;
  z-index: 60;
  display: none;
  overflow: hidden;
}
.demo-user-picker.is-open .dup-menu { display: block; }

/* Section */
.dup-section { margin-bottom: 4px; }
.dup-section:last-child { margin-bottom: 0; }
.dup-section-label {
  padding: 8px 12px 6px;
  font-family: var(--ff-mono);
  font-size: 9px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ash-2);
}

/* Item base */
.demo-user-picker .dup-item {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  border-radius: var(--r-3);
  transition: background 140ms ease, transform 140ms ease;
  position: relative;
}
.demo-user-picker .dup-item:hover { background: var(--paper-2); }
.demo-user-picker .dup-item:active { transform: scale(0.99); }

/* Active state */
.demo-user-picker .dup-item.is-active {
  background: var(--paper-2);
}
.demo-user-picker .dup-item.is-active.is-elevated {
  background: linear-gradient(135deg, rgba(197, 64, 10, 0.08) 0%, rgba(197, 64, 10, 0.02) 100%);
  border: 1px solid rgba(197, 64, 10, 0.25);
  padding: 9px 11px;
}

/* TGĐ row — premium feel even when inactive */
.demo-user-picker .dup-item.is-elevated {
  background: linear-gradient(135deg, var(--paper-2) 0%, transparent 100%);
}
.demo-user-picker .dup-item.is-elevated:hover {
  background: linear-gradient(135deg, rgba(197, 64, 10, 0.08) 0%, rgba(197, 64, 10, 0.02) 100%);
}

/* Item head */
.dup-item-head {
  display: grid; grid-template-columns: 32px 1fr auto; gap: 11px;
  align-items: center;
}

/* Avatar */
.dup-item-avatar {
  position: relative;
  width: 32px; height: 32px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 9999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--ff-mono);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.04em;
}
.demo-user-picker .dup-item.is-elevated .dup-item-avatar {
  background: linear-gradient(135deg, var(--ink) 0%, #2b2820 100%);
}
.demo-user-picker .dup-item.is-active .dup-item-avatar { background: var(--rust); }
.demo-user-picker .dup-item.is-active.is-elevated .dup-item-avatar {
  background: linear-gradient(135deg, var(--rust) 0%, var(--rust-deep) 100%);
}

/* Crown badge on TGĐ avatar */
.dup-crown {
  position: absolute;
  top: -6px; right: -6px;
  width: 14px; height: 14px;
  background: var(--rust);
  color: var(--paper);
  border-radius: 9999px;
  padding: 2px;
  border: 2px solid var(--canvas);
  box-sizing: content-box;
}
.demo-user-picker .dup-item.is-active .dup-crown {
  background: var(--ink);
}

/* Item text */
.dup-item-text {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.dup-item-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.demo-user-picker .dup-item.is-elevated .dup-item-name {
  font-size: 14px;
}
.demo-user-picker .dup-role {
  font-family: var(--ff-mono);
  font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ash);
}
.demo-user-picker .dup-item.is-elevated .dup-role {
  color: var(--rust);
  font-weight: 600;
}

/* Check icon */
.dup-check {
  width: 16px; height: 16px;
  color: var(--rust);
  stroke-width: 3;
}
.demo-user-picker .dup-item.is-active.is-elevated .dup-check {
  color: var(--rust-deep);
}

/* Access line */
.dup-item-access {
  display: inline-flex; align-items: center; gap: 6px;
  padding-left: 43px;
  font-family: var(--ff-mono);
  font-size: 9.5px; letter-spacing: 0.10em;
  color: var(--ash);
  font-weight: 500;
}
.demo-user-picker .dup-item.is-elevated .dup-item-access {
  color: var(--rust);
}
.demo-user-picker .dup-item.is-elevated .dup-item-access i {
  color: var(--rust);
}

/* ============================================================
   HEALTH CHIP — "Sức khoẻ" trong bảng so sánh
   ============================================================ */
.health-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px;
  border-radius: var(--r-2);
  font-family: var(--ff-mono);
  font-size: 9.5px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
}
.health-chip::before {
  content: ""; width: 6px; height: 6px; border-radius: 9999px;
}
.health-chip.h-good   { background: var(--moss-soft);  color: var(--moss-deep); }
.health-chip.h-good::before   { background: var(--moss); }
.health-chip.h-warn   { background: var(--amber-soft); color: #6b520a; }
.health-chip.h-warn::before   { background: var(--amber); }
.health-chip.h-bad    { background: var(--signal-soft); color: var(--signal); }
.health-chip.h-bad::before    { background: var(--signal); }

/* ============================================================
   AI CHAT — Trợ lý ERP (Industrial Press audit-trail style)
   Floating FAB + slide-in panel + dedicated page share styles
   ============================================================ */

/* ===== Floating FAB ===== */
.ai-fab {
  position: fixed;
  bottom: 22px; right: 22px;
  z-index: 1500;
  display: inline-flex; align-items: center; gap: 10px;
  padding: 11px 18px 11px 13px;
  background: #14130f;
  color: #f5f1e8;
  border: 0;
  border-radius: 9999px;
  font-family: var(--ff-sans);
  font-size: 13px; font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(20, 19, 15, 0.22), 0 2px 6px rgba(20, 19, 15, 0.12);
  transition: transform 140ms ease, box-shadow 140ms ease;
}
.ai-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(20, 19, 15, 0.28), 0 2px 6px rgba(20, 19, 15, 0.14);
}
.ai-fab.is-hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }

.ai-fab-mark {
  width: 26px; height: 26px;
  background: #c5400a;
  border-radius: 9999px;
  display: inline-flex; align-items: center; justify-content: center;
  position: relative;
}
.ai-fab-mark i { width: 14px; height: 14px; color: #f5f1e8; }
.ai-fab-label { padding-right: 2px; }

.ai-fab-pulse {
  position: absolute;
  top: 6px; right: 8px;
  width: 8px; height: 8px;
  background: #5d9b6c;
  border-radius: 9999px;
  border: 2px solid #14130f;
  animation: ai-fab-pulse 2.4s ease-in-out infinite;
}
@keyframes ai-fab-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.4); opacity: 0.7; }
}

/* ===== Slide-in panel ===== */
.ai-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 460px; max-width: calc(100vw - 32px);
  background: var(--paper);
  border-left: 1px solid var(--rule);
  box-shadow: -16px 0 48px rgba(20, 19, 15, 0.18);
  z-index: 1600;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(0.22, 0.61, 0.36, 1);
  font-family: var(--ff-sans);
  color: var(--ink);
}
.ai-panel.is-open { transform: translateX(0); }

/* Header */
.ai-panel-head {
  padding: 14px 18px;
  background: #14130f;
  color: #f5f1e8;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-shrink: 0;
}
.ai-panel-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.ai-panel-mark {
  width: 36px; height: 36px;
  background: #c5400a; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  position: relative;
}
.ai-panel-mark i { width: 18px; height: 18px; color: #f5f1e8; }
.ai-panel-mark::after {
  content: ""; position: absolute; right: -2px; bottom: -2px;
  width: 6px; height: 6px; background: #f5f1e8; border-radius: 9999px;
}
.ai-panel-brand-txt { display: flex; flex-direction: column; min-width: 0; }
.ai-panel-name { font-size: 14px; font-weight: 600; letter-spacing: -0.005em; }
.ai-panel-sub {
  font-family: var(--ff-mono);
  font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase;
  color: rgba(245, 241, 232, 0.65);
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 2px;
}
.ai-panel-pulse {
  width: 6px; height: 6px; background: #5d9b6c; border-radius: 9999px;
  animation: ai-fab-pulse 2.4s ease-in-out infinite;
}

.ai-panel-actions { display: inline-flex; gap: 4px; }
.ai-panel-btn {
  width: 32px; height: 32px;
  background: rgba(245, 241, 232, 0.08);
  border: 1px solid rgba(245, 241, 232, 0.14);
  color: #f5f1e8;
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 140ms ease;
  text-decoration: none;
}
.ai-panel-btn:hover { background: rgba(245, 241, 232, 0.18); color: #f5f1e8; }
.ai-panel-btn i { width: 14px; height: 14px; }

/* Scroll area */
.ai-chat-scroll {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 18px;
  background: var(--paper);
  scrollbar-width: thin;
}
.ai-chat-scroll::-webkit-scrollbar { width: 6px; }
.ai-chat-scroll::-webkit-scrollbar-track { background: transparent; }
.ai-chat-scroll::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 99px; }

/* ===== Welcome state ===== */
.ai-welcome { padding: 8px 2px 14px; }
.ai-welcome-h {
  font-size: 22px; font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--ink);
  margin-bottom: 16px;
}
.ai-welcome-chips {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

/* Chip — vertical stacked layout (hint on top, question below) */
.ai-chip {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px 14px;
  background: var(--canvas);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-3);
  cursor: pointer;
  font-family: var(--ff-sans);
  text-align: left;
  transition: background 140ms ease, border-color 140ms ease, transform 80ms ease;
  min-width: 0;
}
.ai-chip:hover {
  background: var(--paper-2);
  border-color: var(--rule);
  transform: translateY(-1px);
}
.ai-chip-head {
  display: inline-flex; align-items: center; gap: 8px;
}
.ai-chip-icon {
  width: 22px; height: 22px;
  background: rgba(197, 64, 10, 0.10);
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ai-chip-icon i { width: 13px; height: 13px; color: var(--rust); }
.ai-chip-hint {
  font-family: var(--ff-mono);
  font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ash);
  font-weight: 500;
}
.ai-chip-q {
  font-size: 13.5px; font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1.3;
}

/* ===== Thread messages ===== */
.ai-thread { display: flex; flex-direction: column; gap: 14px; }
.ai-msg {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 260ms ease, transform 260ms ease;
}
.ai-msg.is-in { opacity: 1; transform: translateY(0); }

/* User bubble */
.ai-msg.ai-user {
  opacity: 1; transform: none;
  display: flex; justify-content: flex-end;
}
.ai-user-bubble {
  max-width: 80%;
  padding: 9px 14px;
  background: #14130f;
  color: #f5f1e8;
  border-radius: 14px 14px 4px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  word-break: break-word;
}

/* ===== § Thinking block ===== */
.ai-think { padding: 0 2px; }
.ai-sig {
  font-family: var(--ff-mono);
  font-size: 10.5px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--rust);
  display: inline-flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.ai-dot-pulse {
  display: inline-flex; gap: 3px;
}
.ai-dot-pulse span {
  width: 4px; height: 4px; background: var(--rust); border-radius: 9999px;
  animation: ai-dot 1.2s ease-in-out infinite;
}
.ai-dot-pulse span:nth-child(2) { animation-delay: 0.15s; }
.ai-dot-pulse span:nth-child(3) { animation-delay: 0.30s; }
@keyframes ai-dot {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50%      { opacity: 1;    transform: translateY(-2px); }
}

.ai-reason-list { display: flex; flex-direction: column; gap: 4px; }
.ai-reason {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ash);
  font-style: italic;
  display: flex; gap: 8px;
  padding-left: 4px;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 240ms ease, transform 240ms ease;
}
.ai-reason.is-in { opacity: 1; transform: translateX(0); }
.ai-reason-mark {
  color: var(--rust);
  font-style: normal;
  font-weight: 600;
  flex-shrink: 0;
}
.ai-reason i { font-style: italic; color: var(--ink-2); }
.ai-reason-done {
  color: var(--moss);
  margin-top: 6px;
  font-style: normal;
  font-weight: 500;
}
.ai-reason-done .ai-reason-mark { color: var(--moss); }
.ai-reason-done .ai-check {
  width: 12px; height: 12px;
  color: var(--moss);
  margin-left: 4px;
  vertical-align: -2px;
  stroke-width: 2.5;
}

/* Intermediate "Đang tổng hợp..." line */
.ai-reason-synth {
  color: var(--ink-2);
  margin-top: 6px;
  font-style: normal;
  font-weight: 500;
  align-items: center;
}
.ai-reason-synth .ai-reason-mark { color: var(--rust); }
.ai-reason-synth .ai-dot-pulse { margin-left: 6px; }

/* Check icon at end of § header after reasoning done */
.ai-sig-check {
  width: 11px; height: 11px;
  color: var(--moss);
  margin-left: 6px;
  vertical-align: -1px;
  stroke-width: 2.5;
  animation: ai-sig-pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes ai-sig-pop {
  from { opacity: 0; transform: scale(0.4); }
  to   { opacity: 1; transform: scale(1); }
}

/* ===== ■ Tool action log ===== */
.ai-tools {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 4px;
}
.ai-tool {
  padding: 10px 12px 10px 14px;
  background: var(--canvas);
  border: 1px solid var(--rule-soft);
  border-left: 2px solid var(--rule);
  border-radius: 4px;
  font-size: 12.5px;
  transition: border-left-color 200ms ease, background 200ms ease;
}
.ai-tool.is-in { /* fade handled by .ai-msg parent */ }
.ai-tool.is-pending { border-left-color: var(--amber, #c08c1a); background: #fbf6e8; }
.ai-tool.is-done.tone-good    { border-left-color: var(--moss); }
.ai-tool.is-done.tone-warn    { border-left-color: var(--amber, #c08c1a); }
.ai-tool.is-done.tone-bad     { border-left-color: var(--signal); }
.ai-tool.is-done.tone-neutral { border-left-color: var(--ink); }

.ai-tool-head {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--ff-mono);
  font-size: 10px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ash);
}
.ai-tool-mark { color: var(--rust); font-size: 12px; line-height: 1; }
.ai-tool-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: inherit;
}
.ai-tool-status b { color: var(--ink); font-weight: 600; }
.ai-tool-status i { width: 12px; height: 12px; flex-shrink: 0; }
.ai-tool.is-pending .ai-tool-status i { color: var(--amber, #c08c1a); }
.ai-tool.is-done .ai-tool-status i { color: var(--moss); }
.ai-spin { animation: ai-spin 0.9s linear infinite; }
@keyframes ai-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

.ai-tool-detail {
  font-size: 12px;
  color: var(--ash);
  font-style: italic;
  margin-top: 4px;
  padding-left: 20px;
  line-height: 1.45;
}
.ai-tool-result {
  margin-top: 8px;
  padding-left: 20px;
  padding-top: 6px;
  border-top: 1px dashed var(--rule-soft);
  animation: ai-result-fade 260ms ease both;
}
@keyframes ai-result-fade {
  from { opacity: 0; transform: translateY(-2px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ai-tool-result-main {
  font-size: 13px; font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.ai-tool-result-meta {
  font-family: var(--ff-mono);
  font-size: 10px; letter-spacing: 0.10em;
  color: var(--ash);
  margin-top: 3px;
  text-transform: uppercase;
}
.ai-tool.tone-good .ai-tool-result-meta    { color: var(--moss-deep); }
.ai-tool.tone-warn .ai-tool-result-meta    { color: #6b520a; }
.ai-tool.tone-bad  .ai-tool-result-meta    { color: var(--signal); }

/* ===== § Final report ===== */
.ai-final {
  padding: 16px 16px 14px;
  background: #14130f;
  color: #f5f1e8;
  border-radius: var(--r-4);
  position: relative;
  overflow: hidden;
  margin-top: 4px;
}
.ai-final::before {
  content: ""; position: absolute; top: 0; left: 0;
  width: 100%; height: 2px; background: #c5400a;
}
.ai-final-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(245, 241, 232, 0.14);
}
.ai-sig-num {
  font-family: var(--ff-mono);
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: rgba(245, 241, 232, 0.5);
  padding: 4px 8px;
  background: rgba(245, 241, 232, 0.08);
  border-radius: 2px;
  flex-shrink: 0;
  margin-top: 2px;
}
.ai-final-h {
  font-size: 17px; font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: #f5f1e8;
}
.ai-final-sub {
  font-family: var(--ff-mono);
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(245, 241, 232, 0.55);
  margin-top: 4px;
}

.ai-final-body { display: flex; flex-direction: column; gap: 12px; }

/* Metrics grid */
.ai-final-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: rgba(245, 241, 232, 0.10);
  border-radius: 4px;
  overflow: hidden;
}
.ai-fm {
  padding: 11px 13px;
  background: #14130f;
  min-width: 0;
}
.ai-fm-l {
  font-family: var(--ff-mono);
  font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(245, 241, 232, 0.55);
}
.ai-fm-v {
  font-size: 20px; font-weight: 500;
  letter-spacing: -0.015em;
  color: #f5f1e8;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin-top: 4px;
}
.ai-fm-v .u {
  font-size: 11px; color: rgba(245, 241, 232, 0.55);
  font-weight: 400;
  margin-left: 3px;
}
.ai-fm.tone-good .ai-fm-v { color: #87c195; }
.ai-fm.tone-warn .ai-fm-v { color: #e88a5e; }
.ai-fm.tone-bad  .ai-fm-v { color: #e85a4a; }
.ai-fm-d {
  font-size: 10.5px;
  color: rgba(245, 241, 232, 0.55);
  margin-top: 4px;
  font-family: var(--ff-mono);
  letter-spacing: 0.10em;
}

/* Final table */
.ai-final-table {
  background: rgba(245, 241, 232, 0.04);
  border-radius: 3px;
  overflow-x: auto;
}
.ai-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.ai-tbl th {
  text-align: left;
  font-family: var(--ff-mono);
  font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(245, 241, 232, 0.55);
  font-weight: 500;
  padding: 9px 10px;
  border-bottom: 1px solid rgba(245, 241, 232, 0.14);
  white-space: nowrap;
}
.ai-tbl td {
  padding: 9px 10px;
  color: #f5f1e8;
  border-bottom: 1px solid rgba(245, 241, 232, 0.08);
  font-variant-numeric: tabular-nums;
}
.ai-tbl tr:last-child td { border-bottom: 0; }

.ai-final-note {
  font-size: 12.5px;
  line-height: 1.55;
  color: rgba(245, 241, 232, 0.82);
  padding: 11px 12px;
  background: rgba(245, 241, 232, 0.06);
  border-left: 2px solid #c5400a;
  border-radius: 0 3px 3px 0;
}
.ai-final-note b { color: #f5f1e8; font-weight: 500; }

.ai-final-ctas {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 2px;
}
.ai-cta {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 11px;
  background: rgba(245, 241, 232, 0.08);
  border: 1px solid rgba(245, 241, 232, 0.16);
  color: #f5f1e8;
  text-decoration: none;
  border-radius: 3px;
  font-size: 12px; font-weight: 500;
  transition: background 140ms ease;
}
.ai-cta:hover { background: rgba(245, 241, 232, 0.16); color: #f5f1e8; text-decoration: none; }
.ai-cta i { width: 12px; height: 12px; opacity: 0.7; }

/* Suggestion chips (fallback) */
.ai-suggest-label {
  font-family: var(--ff-mono);
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ash);
  margin-bottom: 8px;
}
.ai-suggest-chips { display: flex; flex-direction: column; gap: 6px; }

/* ===== Input bar ===== */
.ai-input {
  flex-shrink: 0;
  padding: 12px;
  background: var(--paper-2);
  border-top: 1px solid var(--rule);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}
.ai-input-box {
  width: 100%;
  resize: none;
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r-3);
  font-family: var(--ff-sans);
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--ink);
  outline: none;
  max-height: 140px;
  transition: border-color 140ms ease;
}
.ai-input-box:focus { border-color: var(--ink); }
.ai-input-box::placeholder { color: var(--ash); }
.ai-input-send {
  width: 38px; height: 38px;
  background: #14130f;
  color: #f5f1e8;
  border: 0;
  border-radius: 9999px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 140ms ease, transform 80ms ease;
}
.ai-input-send:hover { background: #000; transform: translateY(-1px); }
.ai-input-send i { width: 16px; height: 16px; }

/* ===== Dedicated page layout overrides ===== */
.ai-page {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  height: calc(100vh - 56px - 24px); /* topbar + padding */
  min-height: 600px;
  border: 1px solid var(--rule);
  border-radius: var(--r-4);
  background: var(--paper);
  overflow: hidden;
}
.ai-page-sidebar {
  background: var(--paper-2);
  border-right: 1px solid var(--rule);
  display: flex; flex-direction: column;
  min-height: 0;
}
.ai-page-sidebar-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--rule-soft);
}
.ai-page-newchat {
  width: 100%;
  padding: 9px 12px;
  background: #14130f; color: #f5f1e8;
  border: 0; border-radius: var(--r-3);
  font-family: var(--ff-sans);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  transition: background 140ms ease;
}
.ai-page-newchat:hover { background: #000; }
.ai-page-newchat i { width: 14px; height: 14px; }

.ai-page-threads {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 10px 8px;
}
.ai-page-section-label {
  font-family: var(--ff-mono);
  font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ash);
  padding: 8px 10px 4px;
}
.ai-page-thread {
  display: block;
  padding: 9px 11px;
  border-radius: var(--r-2);
  font-size: 12.5px;
  color: var(--ink-2);
  text-decoration: none;
  cursor: pointer;
  border: 0; background: transparent;
  width: 100%; text-align: left;
  transition: background 120ms ease;
  position: relative;
  font-family: var(--ff-sans);
}
.ai-page-thread:hover { background: var(--canvas); }
.ai-page-thread.is-active { background: var(--canvas); color: var(--ink); font-weight: 500; }
.ai-page-thread.is-active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 2px; background: var(--rust); border-radius: 0 2px 2px 0;
}
.ai-page-thread-title {
  display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ai-page-thread-meta {
  display: flex; gap: 6px;
  font-family: var(--ff-mono);
  font-size: 9.5px; letter-spacing: 0.10em;
  color: var(--ash);
  margin-top: 3px;
}

.ai-page-main {
  display: flex; flex-direction: column;
  min-height: 0;
}
.ai-page-main .ai-chat-scroll {
  padding: 28px 32px 20px;
  flex: 1;
  background: var(--paper);
}
.ai-page-main .ai-welcome { padding: 14px 2px 12px; }
.ai-page-main .ai-welcome-h { font-size: 26px; }
.ai-page-main .ai-welcome-chips {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
@media (max-width: 1180px) {
  .ai-page-main .ai-welcome-chips { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .ai-page-main .ai-welcome-chips { grid-template-columns: 1fr; }
}
.ai-page-main .ai-input {
  padding: 14px 32px 18px;
}
.ai-page-main .ai-input-box { font-size: 14px; padding: 12px 14px; }

.ai-page-empty-hint {
  font-family: var(--ff-mono);
  font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ash);
  padding: 16px 12px 4px;
  text-align: center;
}

/* Responsive */
@media (max-width: 980px) {
  .ai-panel { width: 100vw; max-width: 100vw; }
  .ai-page { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .ai-page-sidebar { display: none; }
  .ai-page-main .ai-chat-scroll { padding: 18px 16px; }
  .ai-page-main .ai-input { padding: 12px 16px 14px; }
  .ai-page-main .ai-welcome-chips { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .ai-fab-label { display: none; }
  .ai-fab { padding: 12px; }
  .ai-final-metrics { grid-template-columns: 1fr 1fr; }
}
