/* =====================================================================
   GRX — Global Resource Exchange | Enterprise B2B Design System
   SaaS Dark Theme · Edge-to-Edge · Precision Typography · Clean Spacing
   ===================================================================== */
:root {
  --bg: #0b1014;
  --bg-2: #111a20;
  --panel: #16222b;
  --panel-2: #1c2b36;
  --border: #24384a;
  --border-light: rgba(36, 56, 74, 0.6);
  --fg: #e8eff3;
  --fg-bright: #ffffff;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-2: #059669;
  --amber: #f59e0b;
  --danger: #ef4444;
  --ok: #10b981;
  --blue: #38bdf8;
  --purple: #a855f7;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  overflow-x: hidden;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#grx-root { min-height: 100vh; display: flex; flex-direction: column; }
#grx-root h1, #grx-root h2, #grx-root h3, #grx-root h4, #grx-root p, #grx-root ul { margin: 0; }
#grx-root ul { padding-left: 18px; }
#grx-root a { color: inherit; text-decoration: none; }
#grx-root button, #grx-root input, #grx-root select, #grx-root textarea { font-family: inherit; font-size: 13.5px; }

/* ---------- Header ---------- */
.grx-header {
  position: sticky; top: 0; z-index: 40; background: rgba(11, 16, 20, 0.96);
  border-bottom: 1px solid var(--border); backdrop-filter: blur(10px);
}
.grx-header-in { max-width: 1440px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.grx-logo { font-weight: 800; letter-spacing: 0.5px; font-size: 20px; display: inline-flex; flex-direction: column; }
.grx-logo span { color: var(--accent); }
.grx-logo small { font-size: 8px; letter-spacing: 2px; color: var(--muted); font-weight: 700; margin-top: -3px; }
.grx-nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; margin-left: 16px; }
.grx-nav a { padding: 6px 11px; border-radius: var(--radius-sm); font-size: 12.5px; color: var(--muted); font-weight: 600; transition: all 0.15s ease; }
.grx-nav a:hover { background: var(--panel); color: var(--fg); }
.grx-nav a.active { background: var(--accent); color: #04231f; font-weight: 700; }
.grx-header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

/* Notification Bell Dropdown Button */
.notif-btn {
  position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--fg); padding: 6px 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.notif-btn:hover { border-color: var(--accent); }
.notif-badge {
  position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 800; border-radius: 10px; padding: 1px 5px; min-width: 16px; text-align: center; border: 2px solid var(--bg);
}
.notif-dropdown {
  position: absolute; top: 52px; right: 20px; width: 360px; max-width: 90vw; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 60; overflow: hidden;
}
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.notif-head h4 { font-size: 13px; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--border-light); transition: background 0.15s; cursor: pointer; }
.notif-item:hover { background: var(--bg-2); }
.notif-item.unread { background: rgba(16, 185, 129, 0.08); border-left: 3px solid var(--accent); }
.notif-item b { display: block; font-size: 12px; color: var(--fg); margin-bottom: 2px; }
.notif-item p { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.notif-item span { font-size: 10px; color: var(--muted); display: block; margin-top: 4px; }

@media (max-width: 1180px) { .grx-nav { display: none; } }

/* ---------- Mobile dock ---------- */
.grx-dock { display: none; }
@media (max-width: 1180px) {
  .grx-dock {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: #0d151b; border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    overflow-x: auto;
  }
  .grx-dock a { flex: 1 0 19%; text-align: center; font-size: 9.5px; color: var(--muted); padding: 5px 2px; border-radius: var(--radius-sm); font-weight: 700; }
  .grx-dock a b { display: block; font-size: 15px; font-weight: 400; }
  .grx-dock a.active { color: var(--accent); background: var(--panel); }
  .grx-main { padding-bottom: 84px; }
}

/* ---------- Layout & Grid ---------- */
.grx-main { max-width: 1440px; margin: 0 auto; padding: 24px 20px 60px; width: 100%; flex: 1; }
.grx-sec-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.grx-sec-head h2 { font-size: 21px; letter-spacing: -0.3px; font-weight: 800; color: var(--fg-bright); }
.grx-sec-head p { color: var(--muted); font-size: 13px; margin-top: 4px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g6 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* ---------- Cards & Panels ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); transition: border-color 0.15s ease;
}
.card:hover { border-color: rgba(16, 185, 129, 0.4); }
.card.own { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.card-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card h3 { font-size: 15.5px; line-height: 1.35; font-weight: 700; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 12px 0; font-size: 12.5px; }
.kv div span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.kv div b { font-weight: 700; color: var(--fg); }
.price { font-size: 19px; font-weight: 800; color: var(--accent); }
.masked { font-family: var(--font-mono); font-size: 11px; color: var(--muted); background: var(--bg-2); border: 1px dashed var(--border); border-radius: 6px; padding: 7px 10px; margin-top: 10px; }

/* ---------- Badges & Chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--border); color: var(--muted); background: var(--bg-2); letter-spacing: 0.3px; }
.chip.ok { color: var(--ok); border-color: rgba(16,185,129,.45); background: rgba(16,185,129,.08); }
.chip.amber { color: var(--amber); border-color: rgba(245,158,11,.45); background: rgba(245,158,11,.08); }
.chip.acc { color: var(--accent); border-color: rgba(16,185,129,.45); background: rgba(16,185,129,.08); }
.chip.bad { color: var(--danger); border-color: rgba(239,68,68,.45); background: rgba(239,68,68,.08); }
.chip.blue { color: var(--blue); border-color: rgba(56,189,248,.45); background: rgba(56,189,248,.08); }

/* 3-Tier Data Badges */
.chip.user-data { color: var(--muted); border-color: var(--border); background: var(--bg-2); }
.chip.ai-data { color: var(--purple); border-color: rgba(168,85,247,.4); background: rgba(168,85,247,.1); }
.chip.lab-data { color: var(--ok); border-color: rgba(16,185,129,.5); background: rgba(16,185,129,.12); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel-2); color: var(--fg); font-weight: 700; font-size: 12.5px; cursor: pointer;
  transition: all 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04231f; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.4); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 5px 9px; font-size: 11.5px; }
.btn.block { width: 100%; margin-top: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }

/* ---------- Forms & Fields ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 11px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--fg); outline: none; transition: border-color 0.15s; font-size: 13.5px;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { min-height: 75px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .row2 { grid-template-columns: 1fr; } }
.checkline { display: flex; gap: 10px; align-items: flex-start; font-size: 12.5px; cursor: pointer; padding: 8px 10px; background: var(--bg-2); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.checkline input { margin-top: 3px; accent-color: var(--accent); }

/* ---------- Ledgers & Data Tables ---------- */
.ledger { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 12px 0; }
.ledger td, .ledger th { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.ledger th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; background: var(--panel-2); }
.ledger td:last-child { text-align: right; font-weight: 700; }
.ledger tr.total td { font-size: 14px; font-weight: 800; color: var(--accent); border-top: 2px solid var(--border); border-bottom: none; }
.ledger tr.subtotal td { color: var(--muted); }

/* ---------- Timeline Tracker ---------- */
.timeline { display: flex; justify-content: space-between; position: relative; margin: 20px 0 10px; padding: 0 10px; }
.timeline::before { content: ""; position: absolute; top: 14px; left: 24px; right: 24px; height: 2px; background: var(--border); z-index: 1; }
.timeline-step { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 5px; }
.timeline-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--bg-2); border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; color: var(--muted); }
.timeline-step.done .timeline-dot { background: var(--ok); border-color: var(--ok); color: #04231f; }
.timeline-step.active .timeline-dot { background: var(--accent); border-color: var(--accent); color: #04231f; box-shadow: 0 0 10px var(--accent); }
.timeline-label { font-size: 10px; font-weight: 700; color: var(--muted); max-width: 65px; }
.timeline-step.active .timeline-label { color: var(--accent); }
.timeline-step.done .timeline-label { color: var(--fg); }

/* ---------- Modals ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0.8); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 580px;
  box-shadow: var(--shadow); max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal.wide { max-width: 840px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.modal-head h3 { font-size: 15px; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--panel-2); }
.x { background: transparent; border: none; color: var(--muted); font-size: 17px; cursor: pointer; padding: 3px 6px; border-radius: 4px; }
.x:hover { background: var(--bg-2); color: var(--fg); }

/* ---------- Messaging / Chat Modal ---------- */
.chat-log { height: 280px; overflow-y: auto; padding: 12px; background: var(--bg-2); border-radius: var(--radius-sm); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.chat-bubble { max-width: 78%; padding: 8px 11px; border-radius: 8px; font-size: 12.5px; line-height: 1.4; }
.chat-bubble.mine { align-self: flex-end; background: var(--accent); color: #04231f; font-weight: 600; border-bottom-right-radius: 2px; }
.chat-bubble.theirs { align-self: flex-start; background: var(--panel-2); color: var(--fg); border-bottom-left-radius: 2px; }
.chat-meta { font-size: 9.5px; opacity: 0.7; margin-top: 2px; display: block; text-align: right; }

/* ---------- Empty States ---------- */
.empty {
  text-align: center; padding: 42px 20px; background: var(--panel); border: 1px dashed var(--border);
  border-radius: var(--radius); color: var(--muted); font-size: 13px;
}
.empty-icon { font-size: 34px; display: block; margin-bottom: 8px; opacity: 0.7; }
.empty h3 { font-size: 15px; color: var(--fg); margin-bottom: 4px; }
.empty p { max-width: 420px; margin: 0 auto 14px; font-size: 12px; line-height: 1.4; }

/* ---------- AI Assistant Drawer ---------- */
.ai-fab { position: fixed; bottom: 20px; right: 20px; z-index: 45; box-shadow: var(--shadow); border-radius: 20px; padding: 9px 16px; font-weight: 800; font-size: 12.5px; }
@media (max-width: 1180px) { .ai-fab { bottom: 74px; } }
.ai-drawer {
  position: fixed; bottom: 20px; right: 20px; width: 420px; max-width: calc(100vw - 40px); height: 560px; max-height: calc(100vh - 100px);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 55; display: flex; flex-direction: column; overflow: hidden;
}
.ai-log { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.ai-msg { padding: 9px 12px; border-radius: 8px; font-size: 12.5px; line-height: 1.45; max-width: 88%; }
.ai-msg.u { align-self: flex-end; background: var(--accent); color: #04231f; font-weight: 600; }
.ai-msg.a { align-self: flex-start; background: var(--panel-2); color: var(--fg); border: 1px solid var(--border); }
.ai-input { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--panel-2); }
.ai-input input { flex: 1; padding: 7px 11px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--fg); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 24px; left: 24px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: 360px; pointer-events: none; }
.toast {
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: var(--radius-sm); padding: 10px 14px;
  box-shadow: var(--shadow); pointer-events: auto;
}
.toast b { display: block; font-size: 12.5px; color: var(--accent); margin-bottom: 2px; }
.toast span { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
