/**
 * AgentIQ — CIQ Design Language layer
 * ===================================
 * Adopts the Collections-IQ (CIQ) UX/UI system from CIQ_UX_Style_Guide.pdf:
 * floating-card shell, system-UI typography, GitHub-Dark dark palette,
 * flat surfaces, colour-only interaction. The workspace accent stays TEAL.
 *
 * This file is loaded LAST on every admin-shell page and supersedes the
 * older "glassmorphic enhancement layer" in style.css + glass.css.
 * Nothing here changes markup or class names — it is a pure restyle so it
 * can be removed by deleting one <link> if anything regresses.
 *
 * Not touched: login.html / splash (login stays exactly as-is).
 */

/* ═══════════════════════════════════════════════════════════════════════════
   1 · DESIGN TOKENS  (guide §03 — Colour)
   ═══════════════════════════════════════════════════════════════════════════ */
:root,
body.theme-light {
  /* Surfaces & text — LIGHT */
  --bg:            #F6F8FA;
  --surface:       #FFFFFF;
  --surface2:      #F6F8FA;
  --border:        #E3E7EB;
  --text:          #1C2526;
  --text-mid:      #424A53;
  --text-muted:    #6E7781;

  /* Workspace accent — TEAL (unchanged brand) */
  --primary:       #0B7A75;
  --primary-hover: #0A6A66;
  --accent:        #0B7A75;
  --accent-soft:   rgba(11, 122, 117, 0.10);

  /* Semantic (guide §03) */
  --success:       #1A7F37;
  --warning:       #BC4C00;
  --danger:        #CF222E;
  --info:          #0969DA;
  --secondary:     #BC4C00;
  --purple:        #8250DF;

  /* Tinted-badge fills — colour at ~13% (guide §04 "tint, don't fill") */
  --success-soft:  rgba(26, 127, 55, 0.13);
  --warning-soft:  rgba(188, 76, 0, 0.13);
  --danger-soft:   rgba(207, 34, 46, 0.13);
  --info-soft:     rgba(9, 105, 218, 0.13);
  --purple-soft:   rgba(130, 80, 223, 0.13);
  --muted-soft:    rgba(110, 119, 129, 0.13);

  /* Shape (guide §01 — Layout & shell) */
  --gutter:        14px;
  --radius:        14px;   /* content cards */
  --radius-sm:     10px;   /* controls */
  --radius-shell:  20px;   /* sidebar / header / footer */
  --radius-pill:   999px;
  --sidebar-w:     284px;

  /* Elevation */
  --shadow-sm:     0 0 0 1px var(--border);
  --shadow:        0 1px 2px rgba(0,0,0,0.05), 0 0 0 1px var(--border);
  --shadow-lg:     0 10px 30px rgba(0,0,0,0.18);
  --shadow-shell:  0 10px 30px rgba(0,0,0,0.12);

  /* Type — one family throughout (guide §02) */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

body.theme-dark {
  /* GitHub-Dark, validated 9.5:1 for body (guide §03) */
  --bg:            #010409;
  --surface:       #161B22;
  --surface2:      #21262D;
  --border:        #30363D;
  --text:          #C9D1D9;
  --text-mid:      #8B949E;
  --text-muted:    #8B949E;

  --primary:       #2DD4BF;
  --primary-hover: #5EEAD4;
  --accent:        #2DD4BF;
  --accent-soft:   rgba(45, 212, 191, 0.14);

  --success:       #3FB950;
  --warning:       #FB923C;
  --danger:        #F85149;
  --info:          #58A6FF;
  --secondary:     #FB923C;
  --purple:        #A371F7;

  --success-soft:  rgba(63, 185, 80, 0.15);
  --warning-soft:  rgba(251, 146, 60, 0.15);
  --danger-soft:   rgba(248, 81, 73, 0.15);
  --info-soft:     rgba(88, 166, 255, 0.15);
  --purple-soft:   rgba(163, 113, 247, 0.15);
  --muted-soft:    rgba(139, 148, 158, 0.15);

  --sidebar-bg:    #0D1117;
  --shadow-sm:     0 0 0 1px var(--border);
  --shadow:        0 1px 2px rgba(0,0,0,0.4), 0 0 0 1px var(--border);
  --shadow-lg:     0 12px 34px rgba(0,0,0,0.6);
  --shadow-shell:  0 10px 30px rgba(0,0,0,0.45);
}

:root { --sidebar-bg: #0D1117; }

/* ═══════════════════════════════════════════════════════════════════════════
   2 · TYPOGRAPHY  (guide §02 — no web fonts, system stack, strict weights)
   ═══════════════════════════════════════════════════════════════════════════ */
body,
input, select, textarea, button,
.btn, .form-control {
  font-family: var(--font-sans) !important;
}

body {
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

/* Page title — "Dashboard" in the header (guide: 22 / 800 / -0.02em) */
.topbar h2,
#page-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* Card / panel heading (guide: 13.5 / 800) */
.card-header h3,
.card-header h4 {
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text);
}

/* Group label — sidebar section headings (guide: 9.5 / 800 / 0.12em, UPPER) */
.nav-section {
  font-family: var(--font-sans);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.75;
  padding: 16px 22px 6px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   3 · FLATTEN THE GLASS LAYER  (guide §05 — "this is a workbench")
   ═══════════════════════════════════════════════════════════════════════════ */
.sidebar, .topbar, .card, .stat-card, .modal, .modal-header,
.btn, .btn-secondary, .toast, thead th, .glass-card, .glass-card-sm,
.glass-nav, .glass-btn, .race-row, .sidebar-toggle, .file-thumb {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* Motion: only colour / opacity / width may animate — never size, position, shadow */
.card:hover, .stat-card:hover, .stat-card:hover::before,
.glass-card:hover, .race-row:hover, .glass-btn:hover,
.btn:hover, .btn-primary:hover, .btn-secondary:hover,
.sidebar-brand img:hover, .file-thumb:hover {
  transform: none !important;
}

.nav-item, .btn, .card, .stat-card, .tab-btn, .badge,
.form-control, input, select, textarea, .sidebar-toggle {
  transition-duration: 0.15s;
}

/* ═══════════════════════════════════════════════════════════════════════════
   4 · THE FLOATING-CARD SHELL  (guide §01)  — desktop only; mobile drawer untouched
   ═══════════════════════════════════════════════════════════════════════════ */
@media (min-width: 1024px) {

  .layout { background: var(--bg); }

  /* Sidebar — floating card, full height minus gutters */
  .sidebar {
    top: var(--gutter);
    left: var(--gutter);
    bottom: var(--gutter);
    width: var(--sidebar-w);
    background: var(--sidebar-bg) !important;
    border: none !important;
    border-radius: var(--radius-shell);
    box-shadow: var(--shadow-shell) !important;
    overflow: hidden;
  }
  .sidebar-nav { overflow-y: auto; }

  .sidebar-brand {
    background: transparent !important;
    border-bottom: 1px solid rgba(255,255,255,0.06) !important;
  }

  /* Content column sits to the right of the sidebar + one gutter each side */
  .main {
    margin-left: calc(var(--gutter) + var(--sidebar-w) + var(--gutter));
    padding-right: var(--gutter);
  }

  /* Header — floating card */
  .topbar {
    position: sticky;
    top: var(--gutter);
    z-index: 50;
    margin-top: var(--gutter);
    background: var(--sidebar-bg) !important;
    color: #fff;
    border: none !important;
    border-radius: var(--radius-shell);
    box-shadow: var(--shadow-shell) !important;
    padding: 14px 22px;
  }
  .topbar h2, .topbar #page-title { color: #fff; }
  .topbar-user { color: rgba(255,255,255,0.65); }

  /* Content strip */
  .content { padding: var(--gutter) 0 var(--gutter) 0; }

  /* Collapsed sidebar keeps the gutter frame */
  body.sidebar-collapsed .sidebar { width: 72px; }
  body.sidebar-collapsed .main {
    margin-left: calc(var(--gutter) + 72px + var(--gutter));
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   5 · SIDEBAR NAVIGATION  (guide §04 — no background block, state = colour + weight)
   ═══════════════════════════════════════════════════════════════════════════ */
.nav-item {
  background: none !important;
  border-left: 2px solid transparent !important;
  box-shadow: none !important;
  border-radius: 8px;
  margin: 1px 10px !important;
  width: calc(100% - 20px) !important;
  padding: 8px 12px !important;
  font-size: 13px;
  font-weight: 500;
  color: rgba(201,209,217,0.72) !important;
  transition: color 0.15s ease;
}
.nav-item .icon { opacity: 1 !important; color: rgba(201,209,217,0.55); }
.nav-item .icon svg { stroke: currentColor; }

.nav-item:hover {
  background: none !important;
  box-shadow: none !important;
  color: var(--accent) !important;
}
.nav-item:hover .icon { color: var(--accent); }

.nav-item.active {
  background: none !important;
  box-shadow: none !important;
  color: var(--accent) !important;
  font-weight: 700 !important;
  border-left-color: transparent !important;
}
.nav-item.active .icon { color: var(--accent); }

.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.sidebar-brand h1 { font-size: 13.5px; font-weight: 800; color: #fff; letter-spacing: 0; }
.sidebar-brand p  { font-size: 9.5px; font-weight: 700; letter-spacing: 0.12em;
                    text-transform: uppercase; color: rgba(201,209,217,0.4); }
.sidebar-brand img { box-shadow: none !important; border-radius: 10px; }

/* ═══════════════════════════════════════════════════════════════════════════
   6 · CARDS  (guide §01/§04 — hairline + 1px ambient, 12–14px radius)
   ═══════════════════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  transition: none;
}
.card:hover { box-shadow: var(--shadow) !important; border-color: var(--border) !important; }
body.theme-dark .card { background: var(--surface) !important; border-color: var(--border) !important; }

.card-header {
  background: transparent !important;
  border-bottom: 1px solid var(--border) !important;
  padding: 14px 20px;
}
.card-body { padding: 16px 20px; }

/* ═══════════════════════════════════════════════════════════════════════════
   7 · KPI / STAT CARDS  (guide §04 — 2px coloured top border, label→number→context)
   ═══════════════════════════════════════════════════════════════════════════ */
.stats-grid { gap: var(--gutter); margin-bottom: 16px; }

.stat-card {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-top: 2px solid var(--stat-accent, var(--accent)) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  padding: 16px 18px;
  transition: none;
}
.stat-card::before { display: none !important; }   /* replaced by real top border */
.stat-card:hover {
  transform: none !important;
  box-shadow: var(--shadow) !important;
  border-color: var(--border) !important;
  border-top-color: var(--stat-accent, var(--accent)) !important;
}
body.theme-dark .stat-card { background: var(--surface) !important; }

.stat-card.blue   { --stat-accent: var(--info); }
.stat-card.green  { --stat-accent: var(--success); }
.stat-card.orange { --stat-accent: var(--warning); }
.stat-card.red    { --stat-accent: var(--danger); }
.stat-card.yellow { --stat-accent: #D4A72C; }
.stat-card.purple { --stat-accent: #8250DF; }

.stat-card .stat-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.stat-card .stat-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-top: 6px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-card.blue   .stat-value { color: var(--info); }
.stat-card.green  .stat-value { color: var(--success); }
.stat-card.orange .stat-value { color: var(--warning); }
.stat-card.red    .stat-value { color: var(--danger); }
.stat-card .stat-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; opacity: 1; }

/* ═══════════════════════════════════════════════════════════════════════════
   8 · TABLES  (guide §04 — 10px uppercase header, ~40px rows, tabular numbers)
   ═══════════════════════════════════════════════════════════════════════════ */
table { font-size: 13px; }

thead th {
  background: var(--surface) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
  font-weight: 800 !important;
  letter-spacing: 0.06em !important;
  text-transform: uppercase;
  padding: 11px 14px !important;
  border-bottom: 1px solid var(--border) !important;
  position: sticky;
  top: 0;
}
body.theme-dark thead th { background: var(--surface) !important; }

tbody td { padding: 11px 14px; border-bottom-color: var(--border); vertical-align: middle; }
tbody tr:hover td { background: var(--accent-soft); }
tbody td.num, tbody td.amount, thead th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ═══════════════════════════════════════════════════════════════════════════
   9 · BADGES & PILLS  (guide §04 — tinted, not solid; solid = selected only)
   The fill is the colour at ~13% and the text is the colour itself.
   ═══════════════════════════════════════════════════════════════════════════ */
.badge {
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: none !important;
}

.badge-executed, .badge-closed, .badge-validated, .badge-paid,
.badge-confirmed, .badge-valid {
  background: var(--success-soft) !important; color: var(--success) !important;
}
.badge-pending, .badge-awaiting, .badge-valuation_pending, .badge-expiring {
  background: var(--warning-soft) !important; color: var(--warning) !important;
}
.badge-assigned, .badge-submitted {
  background: var(--info-soft) !important; color: var(--info) !important;
}
.badge-in_progress {
  background: var(--purple-soft) !important; color: var(--purple) !important;
}
.badge-rejected, .badge-rejected_bank, .badge-expired {
  background: var(--danger-soft) !important; color: var(--danger) !important;
}
.badge-cancelled, .badge-draft {
  background: var(--muted-soft) !important; color: var(--text-mid) !important;
}

/* status pills (agent active/inactive etc.) */
.status-pill.on  { background: var(--success-soft); color: var(--success); }
.status-pill.off { background: var(--muted-soft);   color: var(--text-mid); }

/* ═══════════════════════════════════════════════════════════════════════════
   10 · BUTTONS  (guide §05 — primary solid accent, secondary bordered)
   ═══════════════════════════════════════════════════════════════════════════ */
.btn {
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn:disabled { opacity: 0.35; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: none;
}
body.theme-dark .btn-primary { color: #06201E; }

.btn-secondary {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg) !important;
  border-color: var(--accent) !important;
  color: var(--text) !important;
  box-shadow: none !important;
}

.btn-success { background: var(--success); border-color: var(--success); }
.btn-danger  { background: var(--danger);  border-color: var(--danger); }
.btn-success:hover:not(:disabled),
.btn-danger:hover:not(:disabled) { box-shadow: none; filter: brightness(0.94); }

.sidebar-toggle:hover {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   11 · MODALS  (guide §05 — 20px radius)
   ═══════════════════════════════════════════════════════════════════════════ */
.modal {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-shell) !important;
  box-shadow: var(--shadow-lg) !important;
}
.modal-header {
  background: transparent !important;
  border-radius: var(--radius-shell) var(--radius-shell) 0 0 !important;
  border-bottom: 1px solid var(--border) !important;
}
.modal-footer { background: transparent !important; border-top: 1px solid var(--border) !important; }
.modal-backdrop { background: rgba(1,4,9,0.55) !important; }

/* ═══════════════════════════════════════════════════════════════════════════
   12 · FORMS & TABS
   ═══════════════════════════════════════════════════════════════════════════ */
.form-control, input[type="text"], input[type="number"], input[type="email"],
input[type="date"], input[type="month"], input[type="search"], input[type="password"],
textarea, select {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.form-control:focus, input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}
body.theme-dark .form-control, body.theme-dark input, body.theme-dark textarea, body.theme-dark select {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}

.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs { border-bottom-color: var(--border); }

/* Selection */
::selection { background: var(--accent-soft); }
