/* AI Trading Sentinel dashboard (M8). RTL, Vazirmatn, light/dark with a manual override. */

@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Medium.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* --- design tokens ------------------------------------------------------------------------ */
:root {
  color-scheme: light;
  --font: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e7ee;
  --text: #17202c;
  --text-2: #5b6676;
  --text-3: #8a94a3;
  --accent: #b8860b;          /* gold */
  --accent-strong: #946b00;
  --accent-soft: #fbf3dc;
  --on-accent: #ffffff;
  --link: #1d5fbf;
  --ok: #16794a;
  --ok-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf1d8;
  --bad: #b42335;
  --bad-soft: #fbe6e9;
  --info: #1d5fbf;
  --info-soft: #e5eefb;
  --muted-soft: #eef0f4;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 232px;
  --bottombar: 64px;
  --chart-1: #b8860b;
  --chart-2: #1d5fbf;
  --chart-3: #16794a;
  --chart-4: #b42335;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f141b;
    --surface: #161d27;
    --surface-2: #1b2430;
    --border: #273241;
    --text: #e6ebf2;
    --text-2: #a5b0bf;
    --text-3: #77839a;
    --accent: #e0b04a;
    --accent-strong: #f0c463;
    --accent-soft: #33290f;
    --on-accent: #1c1404;
    --link: #79a8f2;
    --ok: #4cc58a;
    --ok-soft: #15301f;
    --warn: #e9b44c;
    --warn-soft: #362a10;
    --bad: #f07385;
    --bad-soft: #3a1820;
    --info: #79a8f2;
    --info-soft: #172840;
    --muted-soft: #222c3a;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --chart-1: #e0b04a;
    --chart-2: #79a8f2;
    --chart-3: #4cc58a;
    --chart-4: #f07385;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b;
  --surface: #161d27;
  --surface-2: #1b2430;
  --border: #273241;
  --text: #e6ebf2;
  --text-2: #a5b0bf;
  --text-3: #77839a;
  --accent: #e0b04a;
  --accent-strong: #f0c463;
  --accent-soft: #33290f;
  --on-accent: #1c1404;
  --link: #79a8f2;
  --ok: #4cc58a;
  --ok-soft: #15301f;
  --warn: #e9b44c;
  --warn-soft: #362a10;
  --bad: #f07385;
  --bad-soft: #3a1820;
  --info: #79a8f2;
  --info-soft: #172840;
  --muted-soft: #222c3a;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  --chart-1: #e0b04a;
  --chart-2: #79a8f2;
  --chart-3: #4cc58a;
  --chart-4: #f07385;
}

/* --- base --------------------------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.4; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
code, pre, .mono, .num { font-family: var(--mono); }
.num, .ltr { direction: ltr; unicode-bidi: isolate; }
td.num, td.ltr { text-align: right; }
.when { direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
td code, dd code { white-space: nowrap; }
pre {
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem;
  font-size: .82rem;
  max-height: 32rem;
  overflow: auto;
  margin: .5rem 0;
}
pre.rtl { direction: rtl; text-align: right; font-family: var(--font); font-size: .9rem; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

/* --- layout ------------------------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--sidebar);
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem .75rem;
  overflow-y: auto;
  z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 700; padding: .25rem .5rem 1rem; color: var(--text);
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: grid; place-items: center; color: #fff; font-size: .9rem;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .65rem; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }
.nav .icon { width: 1.25rem; text-align: center; }
.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); }
.who { font-size: .85rem; color: var(--text-2); padding: 0 .5rem .5rem; }
.main {
  flex: 1;
  margin-inline-start: var(--sidebar);
  padding: 1.25rem 1.5rem 2rem;
  min-width: 0;
}
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.page-head p { margin: 0; }
.bottombar { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { margin-inline-start: 0; padding: 1rem .9rem calc(var(--bottombar) + 1.5rem); }
  .bottombar {
    display: flex;
    position: fixed; inset-inline: 0; bottom: 0; height: var(--bottombar);
    background: var(--surface); border-top: 1px solid var(--border);
    z-index: 30; overflow-x: auto;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottombar a {
    flex: 1 0 64px; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px; color: var(--text-2); font-size: .7rem;
  }
  .bottombar a[aria-current="page"] { color: var(--accent-strong); }
  .bottombar .icon { font-size: 1.15rem; line-height: 1; }
  .mobile-only { display: initial; }
}
@media (min-width: 861px) { .mobile-only { display: none; } }

/* --- cards and grids ---------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  min-width: 0;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.span-all { grid-column: 1 / -1; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-bottom: .5rem; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem 1rem; box-shadow: var(--shadow);
}
.stat .label { color: var(--text-2); font-size: .82rem; }
.stat .value { font-size: 1.35rem; font-weight: 700; margin-top: .15rem; }
.stat .hint { color: var(--text-3); font-size: .78rem; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--text-2); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* --- badges ------------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .05rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 500;
  background: var(--muted-soft); color: var(--text-2); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.gold { background: var(--accent-soft); color: var(--accent-strong); }
.dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }

/* --- tables ------------------------------------------------------------------------------- */
.table-tools {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .6rem;
}
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td {
  text-align: right; padding: .5rem .6rem; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--text-2); font-weight: 500; font-size: .82rem; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " ↕"; color: var(--text-3); font-size: .75rem; }
th[aria-sort="ascending"]::after { content: " ↑"; color: var(--accent-strong); }
th[aria-sort="descending"]::after { content: " ↓"; color: var(--accent-strong); }
tr.is-hidden { display: none; }

@media (max-width: 600px) {
  table.stack thead { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--border); padding: .4rem 0; }
  table.stack td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem .3rem; }
  table.stack td::before {
    content: attr(data-label); color: var(--text-2); font-size: .8rem;
    direction: rtl; unicode-bidi: isolate; flex: none;
  }
  table.stack td.num, table.stack td.ltr { direction: rtl; }
}

/* --- forms and buttons -------------------------------------------------------------------- */
label { display: block; font-weight: 500; margin-bottom: .2rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"],
select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .45rem .65rem;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type="number"], input.ltr { direction: ltr; text-align: left; }
textarea { min-height: 12rem; resize: vertical; line-height: 1.8; }
textarea.editor { min-height: 26rem; font-size: .92rem; }
.field { margin-bottom: .9rem; }
.field .help { color: var(--text-2); font-size: .82rem; margin-top: .2rem; }
.field .default { color: var(--text-3); font-size: .78rem; }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline > input, .inline > select { width: auto; flex: 1 1 10rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 500; font-size: .9rem;
  padding: .42rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); }
.btn.small { padding: .2rem .6rem; font-size: .8rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.switch { position: relative; display: inline-block; width: 2.6rem; height: 1.45rem; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px;
  transition: background .15s; cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; width: 1.05rem; height: 1.05rem; top: .2rem;
  inset-inline-start: .2rem; background: #fff; border-radius: 50%; transition: transform .15s;
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(-1.15rem); }
.switch input:disabled + .slider { opacity: .5; cursor: not-allowed; }
fieldset { border: 0; padding: 0; margin: 0; }
.checks { display: flex; flex-wrap: wrap; gap: .3rem 1rem; }
.checks label { font-weight: 400; display: inline-flex; gap: .3rem; align-items: center; }

/* --- notices, empty states, toasts -------------------------------------------------------- */
.notice {
  border-radius: var(--radius-sm); padding: .6rem .8rem; margin-bottom: 1rem;
  background: var(--info-soft); color: var(--info);
}
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.empty {
  text-align: center; color: var(--text-2); padding: 2rem 1rem;
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty .icon { font-size: 1.8rem; display: block; margin-bottom: .3rem; }
.toasts {
  position: fixed; z-index: 50; inset-inline-end: 1rem; top: 1rem;
  display: flex; flex-direction: column; gap: .5rem; max-width: min(92vw, 24rem);
}
@media (max-width: 860px) { .toasts { top: auto; bottom: calc(var(--bottombar) + .75rem); inset-inline: .75rem; } }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--ok);
  border-radius: var(--radius-sm); box-shadow: 0 6px 24px rgb(0 0 0 / 15%);
  padding: .6rem .9rem; animation: toast-in .2s ease-out;
}
.toast.bad { border-inline-start-color: var(--bad); }
.toast.warn { border-inline-start-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* --- pagination, tabs, diff, charts ------------------------------------------------------- */
.pager { display: flex; gap: .4rem; align-items: center; justify-content: center; margin-top: .8rem; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a {
  padding: .3rem .8rem; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--border); color: var(--text-2); font-size: .85rem;
}
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
.diff { font-family: var(--mono); font-size: .82rem; direction: ltr; text-align: left; }
.diff div { white-space: pre-wrap; word-break: break-word; padding: 0 .4rem; }
.diff .add { background: var(--ok-soft); color: var(--ok); }
.diff .del { background: var(--bad-soft); color: var(--bad); }
.diff .hunk { color: var(--info); }
.diff.rtl-text div { direction: rtl; text-align: right; font-family: var(--font); }
.chart-box { position: relative; height: 260px; }
details > summary { cursor: pointer; color: var(--link); }
.theme-toggle { width: 100%; justify-content: flex-start; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 400px; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
