/* =============================================================================
 * Basaffar Finance Copilot — "Aurora Console"
 * A dark, alive AI-cockpit: living aurora backdrop, glass panels, a pulsing
 * copilot orb, and an interactive chat. Bilingual (RTL/LTR via [dir]).
 * System fonts only (CSP blocks external fonts). Every JS-used class preserved.
 * ========================================================================== */

:root {
  color-scheme: dark;
  --bg: #080b14;
  --bg-2: #0b1020;
  --panel: rgba(255,255,255,0.035);
  --panel-2: rgba(255,255,255,0.055);
  --panel-solid: #121a2e;
  --line: rgba(255,255,255,0.09);
  --line-2: rgba(255,255,255,0.14);
  --text: #e9edf7;
  --muted: #93a0bd;
  --faint: #64708c;

  --a1: #2dd4bf;   /* teal */
  --a2: #6366f1;   /* indigo */
  --a3: #a855f7;   /* violet */
  --accent: #7c8cff;
  --accent-soft: rgba(124,140,255,0.16);
  --grad: linear-gradient(135deg, var(--a1), var(--a2) 60%, var(--a3));

  --pos: #34d399; --pos-soft: rgba(52,211,153,0.15);
  --warn: #fbbf24; --warn-soft: rgba(251,191,36,0.15);
  --dang: #fb7185; --dang-soft: rgba(251,113,133,0.15);
  --info: #60a5fa; --info-soft: rgba(96,165,250,0.15);
  --seal: #f0b429; --seal-soft: rgba(240,180,41,0.14); --seal-line: rgba(240,180,41,0.4);

  --danger: var(--dang); --danger-dark: #e11d48;
  --green: var(--pos); --orange: var(--warn); --gray: var(--faint);
  --gold: var(--seal); --gold-soft: var(--seal-soft);

  --radius: 16px; --radius-sm: 11px;
  --shadow: 0 18px 50px rgba(0,0,0,0.45);
  --font-ui: -apple-system, "SF Arabic", BlinkMacSystemFont, "Segoe UI", "Noto Sans Arabic", "Tahoma", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", "DejaVu Sans Mono", monospace;

  /* theme-swappable surfaces (dark defaults) */
  --body-bg: radial-gradient(1200px 800px at 80% -10%, #131c34 0%, #080b14 55%);
  --rail-bg: rgba(9,13,24,0.55);
  --input-bg: rgba(9,13,24,0.7);
  --input-bg-focus: rgba(9,13,24,0.95);
  --tint: rgba(255,255,255,0.025);
  --tint-2: rgba(255,255,255,0.03);
  --hover: rgba(255,255,255,0.03);
  --chat-grad: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
  --aurora-op: 0.5;
  --aurora-blend: screen;
  --orb-in-1: #1b2540; --orb-in-2: #0a0f1d;
}

/* =============================================================================
 * LIGHT THEME — same Aurora identity on a soft light canvas
 * ========================================================================== */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f8; --bg-2: #e6eaf5;
  --panel: rgba(255,255,255,0.74);
  --panel-2: rgba(255,255,255,0.92);
  --panel-solid: #ffffff;
  --line: rgba(24,34,66,0.10);
  --line-2: rgba(24,34,66,0.17);
  --text: #161c30;
  --muted: #58627e;
  --faint: #8a92aa;
  --accent: #5b63e0;
  --accent-soft: rgba(91,99,224,0.13);

  --shadow: 0 16px 40px rgba(38,50,100,0.13);
  --body-bg: radial-gradient(1200px 820px at 80% -12%, #dbe4fb 0%, #eef1f8 52%);
  --rail-bg: rgba(255,255,255,0.72);
  --input-bg: #ffffff;
  --input-bg-focus: #ffffff;
  --tint: rgba(24,34,66,0.028);
  --tint-2: rgba(24,34,66,0.045);
  --hover: rgba(24,34,66,0.04);
  --chat-grad: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(247,249,255,0.65));
  --aurora-op: 0.42;
  --aurora-blend: normal;
  --orb-in-1: #26304e; --orb-in-2: #141a2e;

  --seal-soft: rgba(240,180,41,0.16);
  --pos-soft: rgba(16,160,110,0.14); --pos: #0f9d63;
  --warn-soft: rgba(202,138,4,0.14); --warn: #b7791f;
  --dang-soft: rgba(225,53,86,0.12); --dang: #e11d48;
  --info-soft: rgba(37,99,235,0.12); --info: #2563eb;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--body-bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---- Living aurora backdrop ---- */
.aurora { position: fixed; inset: 0; z-index: -1; overflow: hidden; filter: blur(60px); opacity: var(--aurora-op); }
.aurora span { position: absolute; width: 46vw; height: 46vw; border-radius: 50%; mix-blend-mode: var(--aurora-blend); }
.aurora span:nth-child(1) { background: radial-gradient(circle, var(--a1), transparent 60%); top: -10%; inset-inline-end: -8%; animation: drift1 22s ease-in-out infinite; }
.aurora span:nth-child(2) { background: radial-gradient(circle, var(--a2), transparent 60%); bottom: -14%; inset-inline-start: -6%; animation: drift2 27s ease-in-out infinite; }
.aurora span:nth-child(3) { background: radial-gradient(circle, var(--a3), transparent 60%); top: 30%; inset-inline-start: 40%; animation: drift3 31s ease-in-out infinite; }
@keyframes drift1 { 0%,100%{transform:translate(0,0) scale(1)} 50%{transform:translate(-4vw,6vh) scale(1.15)} }
@keyframes drift2 { 0%,100%{transform:translate(0,0) scale(1.05)} 50%{transform:translate(5vw,-5vh) scale(0.9)} }
@keyframes drift3 { 0%,100%{transform:translate(0,0)} 50%{transform:translate(-6vw,-4vh)} }

button, input, select, a { font: inherit; }

/* ---- Buttons (base = primary; both `button` and `.btn` styled) ---- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  color: #05121a; background: var(--grad); background-size: 160% 160%;
  font-weight: 700; letter-spacing: 0.01em; text-decoration: none; cursor: pointer;
  transition: transform 120ms ease, box-shadow 160ms ease, background-position 400ms ease, opacity 140ms;
  box-shadow: 0 6px 18px rgba(45,90,160,0.28);
}
button:hover, .btn:hover { background-position: 100% 0; box-shadow: 0 10px 26px rgba(70,90,220,0.4); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled { cursor: progress; opacity: 0.55; }
.block { width: 100%; }
.primary { color: #05121a; background: var(--grad); }

.ghost, .btn.ghost {
  color: var(--text); background: var(--panel); border-color: var(--line-2);
  box-shadow: none; backdrop-filter: blur(8px);
}
.ghost:hover, .btn.ghost:hover { background: var(--panel-2); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.danger, .btn.danger { color: #fff; background: linear-gradient(135deg, #f43f5e, #b91c4b); box-shadow: 0 6px 18px rgba(220,40,80,0.32); }
.danger:hover { background: linear-gradient(135deg, #fb5b74, #c11f52); }
.sm { min-height: 34px; padding: 0 13px; font-size: 13px; border-radius: 9px; }

.button-icon, .nav-icon { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.button-icon svg, .nav-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button .btn-text { display: inline-block; line-height: 1; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Fields ---- */
input, select {
  width: 100%; min-height: 44px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  padding: 9px 13px; color: var(--text); background: var(--input-bg);
  transition: border-color 140ms, box-shadow 140ms, background 140ms;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus { outline: none; border-color: var(--accent); background: var(--input-bg-focus); box-shadow: 0 0 0 3px var(--accent-soft); }
select option { background: var(--panel-solid); color: var(--text); }

.hidden { display: none !important; }
.muted { color: var(--muted); }

.eyebrow { margin: 0 0 6px; font-size: 11.5px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(23px, 3vw, 32px); font-weight: 800; letter-spacing: -0.02em; }
h2 { margin-bottom: 4px; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.lead { max-width: 720px; margin: 8px 0 0; font-size: 14.5px; color: var(--muted); }
p { color: var(--muted); }
.batch-sub, .detail-block strong { font-variant-numeric: tabular-nums; }
.batch-sub { font-family: var(--font-mono); }

/* ---- Language pill ---- */
.lang-pill {
  min-height: 34px; padding: 0 14px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  color: var(--text); background: var(--panel); border: 1px solid var(--line-2); box-shadow: none; backdrop-filter: blur(8px);
}
.lang-pill:hover { border-color: var(--accent); background: var(--panel-2); box-shadow: 0 0 0 3px var(--accent-soft); }

/* theme toggle (sun/moon swap) */
.theme-toggle { padding: 0; width: 40px; }
.theme-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .ic-sun, .theme-toggle .ic-moon { display: inline-flex; align-items: center; }
.theme-toggle .ic-sun { display: none; }
:root[data-theme="light"] .theme-toggle .ic-sun { display: inline-flex; }
:root[data-theme="light"] .theme-toggle .ic-moon { display: none; }
.auth-toggles { position: absolute; top: 16px; inset-inline-end: 16px; display: flex; gap: 8px; }
.rail-toggles { display: flex; gap: 8px; }
.rail-toggles .lang-pill:not(.theme-toggle) { flex: 1; }

/* =============================================================================
 * COPILOT ORB — the living signature
 * ========================================================================== */
.copilot-orb { position: relative; display: inline-grid; place-items: center; border-radius: 50%; flex: 0 0 auto; }
.copilot-orb.lg { width: 76px; height: 76px; }
.copilot-orb.md { width: 52px; height: 52px; }
.copilot-orb.sm { width: 40px; height: 40px; }
.copilot-orb::before {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--a1), var(--a2), var(--a3), var(--a1));
  animation: spin 6s linear infinite; filter: blur(2px);
}
.copilot-orb::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: radial-gradient(circle at 32% 28%, var(--orb-in-1), var(--orb-in-2)); }
.orb-core { position: relative; z-index: 1; font-family: var(--font-mono); font-weight: 700; font-size: 0.8em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.copilot-orb.thinking::before { animation-duration: 1.4s; }

/* =============================================================================
 * AUTH
 * ========================================================================== */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  position: relative; width: min(430px, 100%); padding: 40px 34px 30px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow); backdrop-filter: blur(18px);
  animation: rise 0.5s cubic-bezier(0.2,0.7,0.2,1);
}
.auth-card .copilot-orb { margin: 0 auto 18px; }
.auth-card h2 { margin: 2px 0; }
.auth-card .stack { margin-top: 22px; text-align: start; }
.stack { display: grid; gap: 15px; }
.field span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* =============================================================================
 * SHELL
 * ========================================================================== */
.shell { display: grid; grid-template-columns: 268px 1fr; min-height: 100vh; }
.rail {
  display: flex; flex-direction: column; gap: 16px; padding: 20px 14px;
  background: var(--rail-bg); border-inline-end: 1px solid var(--line);
  backdrop-filter: blur(16px); position: sticky; top: 0; height: 100vh;
}
.rail-brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 16px; border-bottom: 1px solid var(--line); }
.rail-brand-txt strong { display: block; font-size: 15px; font-weight: 800; }
.rail-brand-txt span { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; justify-content: flex-start;
  min-height: 46px; padding: 0 12px; text-align: start; font-weight: 600;
  color: var(--muted); background: transparent; border: 1px solid transparent; box-shadow: none;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { color: var(--text); background: var(--panel-2); border-color: var(--line-2); }
.nav-item.active::before { content: ""; position: absolute; inset-inline-start: 0; top: 11px; bottom: 11px; width: 3px; border-radius: 3px; background: var(--grad); }
.nav-icon { width: 34px; height: 34px; border-radius: 10px; color: var(--muted); background: var(--panel); }
.nav-item.active .nav-icon { color: #05121a; background: var(--grad); }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.rail-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-badge { color: var(--muted); font-size: 13px; font-weight: 600; }

.main { padding: 26px clamp(16px, 3vw, 38px) 52px; max-width: 1180px; }
.view { display: none; }
.view.active { display: block; animation: viewIn 0.3s ease-out; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.status-chip { min-width: 66px; padding: 5px 13px; border-radius: 999px; text-align: center; height: fit-content;
  color: var(--pos); background: var(--pos-soft); border: 1px solid rgba(52,211,153,0.3); font-weight: 700; font-size: 13px; box-shadow: none; }

/* ---- Notices ---- */
.notice { padding: 12px 14px; margin-bottom: 16px; border: 1px solid var(--line-2);
  border-inline-start: 3px solid var(--accent); border-radius: var(--radius-sm); color: var(--text); background: var(--panel); font-size: 14px; }
.notice.error { border-inline-start-color: var(--dang); color: #ffd9df; background: var(--dang-soft); }

/* =============================================================================
 * CARDS
 * ========================================================================== */
.card { position: relative; padding: 24px; margin-bottom: 18px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.section-head p { margin: 4px 0 0; }

.upload-row, .search-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 14px; align-items: center; }
.user-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 14px; align-items: end; }
.checkbox-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.checkbox-row input { width: auto; min-height: auto; accent-color: var(--a2); }
.checkbox-row span { margin: 0; }

.file-control { min-width: 0; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-trigger { display: flex; align-items: center; gap: 10px; min-height: 54px; width: 100%;
  border: 1px dashed var(--line-2); border-radius: var(--radius-sm); padding: 0 14px; color: var(--text);
  background: var(--input-bg); cursor: pointer; transition: border-color 140ms, background 140ms; }
.file-trigger:hover { border-color: var(--accent); background: var(--accent-soft); }
.file-trigger .button-icon { width: 34px; height: 34px; border-radius: 9px; color: #05121a; background: var(--grad); }
.file-trigger span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px,1fr)); gap: 12px; margin-top: 18px; }
.metric { display: flex; flex-direction: column; justify-content: space-between; min-height: 92px; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; background: var(--tint); }
.metric.status-metric { align-items: flex-start; }
.metric span { display: block; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.metric strong { display: block; margin-top: 6px; overflow-wrap: anywhere; font-size: 19px; font-weight: 800; line-height: 1.4; }

/* ---- Badges ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 25px; border-radius: 999px;
  padding: 3px 11px; font-size: 12px; font-weight: 700; line-height: 1.2; text-align: center; border: 1px solid transparent; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.badge.READY_FOR_APPROVAL { color: var(--seal); background: var(--seal-soft); border-color: var(--seal-line); border-style: dashed; }
.badge.SENT { color: var(--pos); background: var(--pos-soft); }
.badge.PARTIALLY_SENT { color: var(--warn); background: var(--warn-soft); }
.badge.FAILED_SEND, .badge.FAILED, .badge.FAILED_PREVIEW { color: var(--dang); background: var(--dang-soft); }
.badge.CANCELLED { color: var(--faint); background: rgba(148,160,189,0.12); }
.badge.SENDING { color: var(--info); background: var(--info-soft); }

/* ---- Tables ---- */
.history-filters { display: grid; grid-template-columns: minmax(240px,1.4fr) minmax(160px,0.8fr) minmax(150px,0.7fr) minmax(150px,0.7fr) auto;
  gap: 12px; align-items: end; margin-bottom: 16px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--tint); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; min-width: 820px; border-collapse: collapse; background: transparent; font-variant-numeric: tabular-nums; }
th, td { border-bottom: 1px solid var(--line); padding: 12px 13px; text-align: start; vertical-align: middle; font-size: 14px; }
th { color: var(--muted); background: var(--tint-2); font-size: 11.5px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
tbody tr { transition: background 120ms; }
tbody tr:hover { background: var(--hover); }
tr:last-child td { border-bottom: 0; }
.file-cell { min-width: 220px; }
.file-name { display: block; color: var(--text); font-weight: 800; overflow-wrap: anywhere; }
.batch-sub { display: block; margin-top: 4px; color: var(--muted); direction: ltr; text-align: start; font-size: 12px; }
.table-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.table-actions button, .table-actions a { min-height: 30px; border-radius: 8px; padding: 0 11px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line-2); font-size: 12px; font-weight: 700; box-shadow: none; }
.table-actions button:hover, .table-actions a:hover { border-color: var(--accent); background: var(--accent-soft); }
.empty { color: var(--muted); text-align: center; padding: 10px 0; }

.details-panel { border-color: var(--line-2); }
.details-content { display: grid; gap: 16px; }
.details-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px,1fr)); gap: 10px; }
.detail-block { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; background: var(--tint); }
.detail-block span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.detail-block strong { display: block; margin-top: 5px; color: var(--text); font-weight: 800; overflow-wrap: anywhere; }
.report-links { display: flex; flex-wrap: wrap; gap: 8px; }
.report-links a, .report-links span { min-height: 32px; display: inline-flex; align-items: center; border-radius: 9px; padding: 0 12px; text-decoration: none; font-size: 13px; font-weight: 700; }
.report-links a { color: #05121a; background: var(--grad); }
.report-links span { color: var(--muted); background: var(--panel-2); }

/* =============================================================================
 * CHAT — the interactive hero
 * ========================================================================== */
.copilot-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.copilot-id { display: flex; align-items: center; gap: 14px; }
.copilot-id h1 { font-size: clamp(20px, 2.4vw, 26px); }
.copilot-status { display: flex; align-items: center; gap: 7px; margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pos); box-shadow: 0 0 0 0 rgba(52,211,153,0.6); animation: pulse 2s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(52,211,153,0.55)} 70%{box-shadow:0 0 0 8px rgba(52,211,153,0)} 100%{box-shadow:0 0 0 0 rgba(52,211,153,0)} }

.chat-window {
  display: flex; flex-direction: column; gap: 14px; padding: 22px;
  height: calc(100vh - 300px); min-height: 380px; overflow-y: auto;
  background: var(--chat-grad);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  backdrop-filter: blur(12px); margin-bottom: 12px;
}
.msg { display: flex; gap: 11px; max-width: 82%; align-items: flex-start; animation: msgIn 0.22s ease-out; }
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: translateY(0) scale(1); } }

.msg-avatar { position: relative; flex: 0 0 36px; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 12px; color: #05121a; }
.msg.bot .msg-avatar { background: var(--grad); box-shadow: 0 0 14px rgba(99,102,241,0.5); }
.msg.user .msg-avatar { color: var(--text); background: var(--panel-2); border: 1px solid var(--line-2); }

.msg-bubble { padding: 11px 15px; border-radius: 15px; white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.75; }
.msg.bot .msg-bubble { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-top-right-radius: 4px; }
.msg.user .msg-bubble { background: var(--grad); color: #06121b; border-top-left-radius: 4px; font-weight: 600; }
.msg-meta { font-size: 11px; color: var(--faint); margin-top: 5px; }
.msg.bot .msg-bubble a { color: var(--a1); text-decoration: underline; word-break: break-all; }
.msg.user .msg-bubble a { color: #06121b; text-decoration: underline; }
.chat-file-card { margin-top: 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  box-shadow: 0 10px 24px rgba(0,0,0,0.12); }
.chat-file-card strong { display: block; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.chat-file-card span:not(.button-icon):not(.btn-text) { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.chat-file-card .btn { min-height: 36px; white-space: nowrap; text-decoration: none; }
.chat-chart-card { margin-top: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); box-shadow: 0 10px 24px rgba(0,0,0,0.12); max-width: 560px; }
.chat-chart-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--fg, #222); }
.chat-chart-svg { width: 100%; }
.chat-chart-svg svg { width: 100%; height: auto; display: block; border-radius: 8px; }
/* dashboard */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin: 14px 0; }
.kpi-card { padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: 0 8px 20px rgba(0,0,0,0.08); transition: transform 0.18s ease, box-shadow 0.18s ease; will-change: transform; }
.kpi-card:hover { transform: scale(1.03); box-shadow: 0 14px 30px rgba(0,0,0,0.18); border-color: var(--a1); cursor: zoom-in; }
.kpi-card .kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-card .kpi-value { font-size: 20px; font-weight: 700; }
.kpi-card .kpi-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.dash-alerts { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 14px; }
.dash-alert { padding: 10px 12px; border-radius: 10px; font-size: 13px; border: 1px solid var(--line); }
.dash-alert.warn { background: rgba(240,170,60,0.12); border-color: rgba(240,170,60,0.4); }
.dash-alert.info { background: rgba(78,121,167,0.10); border-color: rgba(78,121,167,0.35); }
.dash-alert.ok { background: rgba(89,161,79,0.10); border-color: rgba(89,161,79,0.35); }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; margin-bottom: 14px; }
.chart-grid .dash-chart { padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: 0 8px 20px rgba(0,0,0,0.08); transition: transform 0.18s ease, box-shadow 0.18s ease; will-change: transform; }
.chart-grid .dash-chart:hover { transform: scale(1.03); box-shadow: 0 16px 36px rgba(0,0,0,0.18); border-color: var(--a1); cursor: zoom-in; }
/* Centered hover-zoom overlay: a big copy of the hovered card, near screen size.
   pointer-events:none so it never steals hover (no flicker). */
.hover-zoom-layer { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(2px); pointer-events: none; padding: 3vh 3vw; }
.hover-zoom-layer.hidden { display: none; }
.hover-zoom-inner { animation: hz-pop 0.15s ease; }
@keyframes hz-pop { from { transform: scale(0.9); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }
.hover-zoom-inner .dash-chart { width: min(1080px, 94vw); padding: 20px; transform: none !important; box-shadow: 0 30px 80px rgba(0,0,0,0.5); }
.hover-zoom-inner .dash-chart h3 { font-size: 20px; }
.hover-zoom-inner .dash-chart svg { width: 100%; height: auto; }
.hover-zoom-inner .kpi-card { width: min(560px, 88vw); padding: 30px 34px; transform: none !important; box-shadow: 0 30px 80px rgba(0,0,0,0.5); }
.hover-zoom-inner .kpi-card .kpi-label { font-size: 18px; }
.hover-zoom-inner .kpi-card .kpi-value { font-size: 52px; }
.hover-zoom-inner .kpi-card .kpi-hint { font-size: 15px; }
.chart-grid .dash-chart h3 { font-size: 13px; margin: 0 0 6px; }
.chart-grid .dash-chart svg { width: 100%; height: auto; display: block; }
.digest-list { display: flex; flex-direction: column; gap: 8px; }
.digest-row { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 12.5px; }
.digest-row b { color: var(--a1); }
.twofa-enroll { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.twofa-enroll img { width: 180px; height: 180px; border-radius: 10px; background: #fff; padding: 6px; }
.twofa-secret { display: inline-block; font-family: ui-monospace, monospace; font-size: 15px; letter-spacing: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; word-break: break-all; }
.dash-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 48px 0; color: var(--muted); }
.dash-loading.hidden { display: none; }
.dash-spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--a1); animation: dash-spin 0.9s linear infinite; }
@keyframes dash-spin { to { transform: rotate(360deg); } }
.dash-loading p { font-size: 13px; margin: 0; }
.dash-refreshing #dashKpis, .dash-refreshing #dashCharts { opacity: 0.55; transition: opacity 0.2s; }
/* streaming caret */
.msg-bubble.streaming::after { content: "▋"; color: var(--a1); margin-inline-start: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.msg-bubble.typing { display: inline-flex; gap: 5px; align-items: center; padding: 15px 17px; }
.msg-bubble.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--a1); opacity: 0.5; animation: typingBounce 1.2s infinite ease-in-out; }
.msg-bubble.typing span:nth-child(2) { animation-delay: 0.18s; background: var(--a2); }
.msg-bubble.typing span:nth-child(3) { animation-delay: 0.36s; background: var(--a3); }
@keyframes typingBounce { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

.pending-banner { align-self: stretch; position: relative; padding-block: 13px; padding-inline-start: 50px; padding-inline-end: 16px;
  border-radius: var(--radius-sm); background: var(--seal-soft); color: var(--seal); border: 1.5px dashed var(--seal-line); font-size: 13px; font-weight: 800; }
.pending-banner::before { content: "⚑"; position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); font-size: 20px; }

.chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { min-height: 36px; padding: 0 15px; border-radius: 999px; background: var(--panel); color: var(--text);
  font-size: 13px; font-weight: 600; border: 1px solid var(--line-2); box-shadow: none; backdrop-filter: blur(8px);
  transition: border-color 120ms, background 120ms, transform 120ms; }
.chip:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.chip.primary { color: #05121a; background: var(--grad); border-color: transparent; }
.chip.danger { color: #fff; background: linear-gradient(135deg,#f43f5e,#b91c4b); border-color: transparent; }

/* composer */
.composer { position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 8px; border: 1px solid var(--line-2); border-radius: 16px; background: var(--input-bg); backdrop-filter: blur(12px);
  transition: border-color 140ms, box-shadow 140ms; }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.composer input { border: 0; background: transparent; min-height: 44px; }
.composer input:focus { box-shadow: none; background: transparent; }
.composer-attach { width: 46px; min-height: 46px; padding: 0; border-radius: 12px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); }
.composer-attach:hover { border-color: var(--accent); background: var(--accent-soft); }
.composer-send { width: 46px; min-height: 46px; padding: 0; border-radius: 12px; color: #05121a; background: var(--grad); }

/* =============================================================================
 * INTEGRATIONS
 * ========================================================================== */
.integrations-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px,1fr)); gap: 14px; }
.integration-card { padding: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(12px); display: flex; flex-direction: column; gap: 12px; min-height: 200px; }
.integration-card.placeholder { border-style: dashed; background: var(--tint); box-shadow: none; }
.integration-card h3 { margin: 0; font-size: 17px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.integration-card .type-tag { display: inline-block; padding: 2px 9px; border-radius: 7px; background: var(--panel-2);
  color: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; width: fit-content; }
.integration-card .desc { color: var(--muted); font-size: 14px; flex: 1; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; width: fit-content; }
.status-pill.connected { background: var(--pos-soft); color: var(--pos); }
.status-pill.available { background: var(--accent-soft); color: var(--accent); }
.status-pill.coming_soon { background: var(--panel-2); color: var(--muted); }
.status-pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.test-result:not(:empty) { margin-top: 4px; }
.test-result .notice { margin-bottom: 0; }
.api-catalog { grid-column: 1 / -1; }
.api-catalog-list { display: grid; gap: 8px; margin-top: 10px; }
.api-catalog-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(130px, 1fr) auto minmax(90px, auto); gap: 10px; align-items: center; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: color-mix(in srgb, var(--surface) 84%, transparent); }
.api-catalog-row code { direction: ltr; text-align: left; font-size: 12px; color: var(--muted); }
.api-catalog-row strong.ok { color: var(--pos); }
.api-catalog-row strong.bad { color: var(--danger); }
.api-catalog-row small { color: var(--muted); }

/* =============================================================================
 * RESPONSIVE
 * ========================================================================== */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: relative; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; border-inline-end: 0; border-bottom: 1px solid var(--line); padding: 12px; }
  .rail-brand { border: 0; padding: 0 6px; }
  .nav { flex-direction: row; flex: 1; flex-wrap: wrap; }
  .nav-item { min-height: 40px; }
  .nav-item.active::before { display: none; }
  .rail-foot { flex-direction: row; margin: 0; border: 0; padding: 0; align-items: center; }
  .main { padding: 18px 14px 40px; }
  .view-head, .copilot-head { flex-direction: column; align-items: flex-start; }
  .upload-row, .search-row { grid-template-columns: 1fr; }
  .history-filters { grid-template-columns: 1fr; }
  .chat-window { height: calc(100vh - 360px); }
  .msg { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .aurora { display: none; }
}
