@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&family=Tajawal:wght@400;500;700;800&display=swap');

/* SEGA.M brand: black/red wordmark (see public/assets/segam-logo.png), sampled from
   the company's real offer documents — #E81820 is the exact red used in the logo. */
:root {
  --bg: #F5F4F2;
  --surface: #FFFFFF;
  --surface2: #F0EDEA;
  --ink: #191512;
  --muted: #6B625B;
  --line: #E2DCD5;
  --accent: #D31A22;
  --accent-ink: #FFFFFF;
  --accent2: #16324A;
  --good: #2F7D4E;
  --good-bg: #E4F3EA;
  --warn: #B98A17;
  --warn-bg: #FBF1DC;
  --crit: #B0201F;
  --crit-bg: #FBE6E3;
  --draft: #6B5FA8;
  --draft-bg: #EDEAF7;
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-ui-ar: "Tajawal", "Inter", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(25, 21, 18, 0.07), 0 1px 1px rgba(25, 21, 18, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140F;
    --surface: #221E19;
    --surface2: #2B2620;
    --ink: #F1ECE6;
    --muted: #AB9F93;
    --line: #3A342C;
    --accent: #EA4B4F;
    --accent-ink: #17140F;
    --accent2: #6D93B4;
    --good: #4FAE79;
    --good-bg: #17281F;
    --warn: #D7AE4E;
    --warn-bg: #2B240F;
    --crit: #E0796B;
    --crit-bg: #2C1917;
    --draft: #9C90D9;
    --draft-bg: #211D33;
  }
}
:root[data-theme="dark"] {
  --bg: #17140F; --surface: #221E19; --surface2: #2B2620; --ink: #F1ECE6; --muted: #AB9F93; --line: #3A342C;
  --accent: #EA4B4F; --accent-ink: #17140F; --accent2: #6D93B4; --good: #4FAE79; --good-bg: #17281F;
  --warn: #D7AE4E; --warn-bg: #2B240F; --crit: #E0796B; --crit-bg: #2C1917; --draft: #9C90D9; --draft-bg: #211D33;
}

html[lang="ar"] body { font-family: var(--font-ui-ar); }
html[dir="rtl"] { direction: rtl; }
/* Numbers, order codes, money and dates keep left-to-right runs even inside RTL text */
.ltr, .mono, code, .num-cell, .num { unicode-bidi: isolate; }
html[dir="rtl"] .ltr-force { direction: ltr; unicode-bidi: isolate; display: inline-block; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono, input[type="number"], .num { font-family: var(--font-mono); }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 20;
}
.topbar .brand { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.topbar .brand .bolt { color: var(--accent2); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); font-weight: 600; font-size: 13.5px; padding: 8px 12px; border-radius: var(--radius); }
.topbar nav a:hover, .topbar nav a.active { color: var(--ink); background: var(--surface2); text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .env-badge { font-family: var(--font-mono); font-size: 11.5px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }

.page { max-width: 1240px; margin: 0 auto; padding: 24px; }
.page.wide { max-width: 1440px; }

h1 { font-size: 22px; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 700; margin: 0 0 10px; }
h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 8px; }
.subtitle { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card-flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* ---------- KPI tiles ---------- */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

/* ---------- buttons / forms ---------- */
button, .btn {
  font-family: var(--font-ui); font-size: 13.5px; font-weight: 600; cursor: pointer;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; display: inline-flex; align-items: center; gap: 6px; transition: background 0.1s;
}
button:hover, .btn:hover { background: var(--surface2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.danger { background: var(--crit-bg); border-color: var(--crit); color: var(--crit); }
button.good { background: var(--good-bg); border-color: var(--good); color: var(--good); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.small { padding: 4px 9px; font-size: 12px; }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  font-family: var(--font-ui); font-size: 13.5px; width: 100%; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
}
textarea { font-family: var(--font-ui); resize: vertical; }
.field { margin-bottom: 12px; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }
fieldset { border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px; margin: 0 0 12px; }
legend { font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 6px; }

/* ---------- chips / badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.chip.status-Draft, .chip.status-Extraction { background: var(--surface2); color: var(--muted); }
.chip.status-BoMReview, .chip.status-Pricing { background: var(--warn-bg); color: var(--warn); }
.chip.status-Approval { background: var(--draft-bg); color: var(--draft); }
.chip.status-Issued { background: var(--accent); color: var(--accent-ink); }
.chip.status-Won { background: var(--good-bg); color: var(--good); }
.chip.status-Lost, .chip.status-Expired { background: var(--crit-bg); color: var(--crit); }
.chip.status-Nodecision { background: var(--surface2); color: var(--muted); }
.badge-conf { font-family: var(--font-mono); font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.badge-conf.high { background: var(--good-bg); color: var(--good); }
.badge-conf.mid { background: var(--warn-bg); color: var(--warn); }
.badge-conf.low { background: var(--crit-bg); color: var(--crit); }
.rule-badge { font-family: var(--font-mono); font-size: 10.5px; background: var(--surface2); color: var(--accent); padding: 1px 6px; border-radius: 4px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: start; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 2px solid var(--line); position: sticky; top: 0; background: var(--surface); }
td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:hover td { background: var(--surface2); }
.table-wrap { overflow-x: auto; }
.num-cell { text-align: end; font-family: var(--font-mono); font-variant-numeric: tabular-nums; unicode-bidi: isolate; }
tr.clickable { cursor: pointer; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 4px; margin-inline-end: 20px; color: var(--muted); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.banner { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.crit { background: var(--crit-bg); color: var(--crit); }
.banner.good { background: var(--good-bg); color: var(--good); }
.banner.info { background: var(--surface2); color: var(--ink); }
.stepper { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.stepper .step { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--surface2); color: var(--muted); font-weight: 600; }
.stepper .step.current { background: var(--accent); color: var(--accent-ink); }
.stepper .arrow { color: var(--line); }
details.panel-group { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
details.panel-group summary { cursor: pointer; padding: 10px 14px; font-weight: 700; background: var(--surface2); list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.panel-group summary::-webkit-details-marker { display: none; }
details.panel-group[open] summary { border-bottom: 1px solid var(--line); }
.section-header { padding: 7px 14px; font-weight: 700; font-size: 12px; color: var(--accent); background: var(--surface); border-bottom: 1px solid var(--line); }
.confidence-bar { width: 60px; height: 6px; border-radius: 3px; background: var(--surface2); overflow: hidden; display: inline-block; vertical-align: middle; margin-inline-end: 6px; }
.confidence-bar > span { display: block; height: 100%; background: var(--accent); }
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.footer-note { color: var(--muted); font-size: 12px; margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.watermark-note { font-size: 11.5px; color: var(--draft); background: var(--draft-bg); padding: 6px 10px; border-radius: var(--radius); display: inline-block; }

/* ---------- brand / logo ---------- */
.topbar .brand { gap: 10px; }
.topbar .brand img.logo-mark { height: 32px; width: auto; display: block; }
.topbar .brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.topbar .brand-text .app-name { font-weight: 800; font-size: 14.5px; letter-spacing: -0.01em; }
.topbar .brand-text .app-sub { font-size: 10px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }

/* ---------- language toggle ---------- */
.lang-toggle { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang-toggle button { border: none; background: none; padding: 5px 11px; font-size: 12px; font-weight: 700; color: var(--muted); border-radius: 0; }
.lang-toggle button.active { background: var(--accent); color: var(--accent-ink); }
.lang-toggle button:hover:not(.active) { background: var(--surface2); }

/* ---------- user menu ---------- */
.user-menu { position: relative; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
html[dir="rtl"] .user-chip { padding: 4px 4px 4px 12px; }
.user-avatar { width: 27px; height: 27px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0; }
.user-chip .u-name { font-size: 13px; font-weight: 600; line-height: 1.1; }
.user-chip .u-role { font-size: 10.5px; color: var(--muted); line-height: 1.1; }
.user-menu-dropdown { position: absolute; top: calc(100% + 8px); inset-inline-end: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 210px; padding: 10px; z-index: 30; }
.user-menu-dropdown[hidden] { display: none; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(160deg, var(--bg) 0%, var(--surface2) 100%); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(25,21,18,0.1); padding: 32px 30px; }
.auth-card .logo-row { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 22px; }
.auth-card .logo-row img { height: 56px; }
.auth-card .logo-row .tagline { font-size: 12px; color: var(--muted); text-align: center; }
.auth-card h1 { font-size: 18px; text-align: center; margin: 0 0 20px; }
.auth-error { display: none; }
.auth-error.show { display: block; }
.demo-accounts { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; }
.demo-accounts summary { cursor: pointer; font-size: 12px; color: var(--muted); font-weight: 600; }
.demo-accounts table { margin-top: 10px; font-size: 11.5px; }
.demo-accounts td { padding: 3px 6px; border: none; }
.demo-accounts button.small { padding: 2px 7px; }

/* ---------- role badge on user rows ---------- */
.role-badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface2); color: var(--accent2); }
.role-badge.Administrator { background: var(--accent); color: var(--accent-ink); }
