/* Exeria brand: navy #001C5B + olive gold #BCBB80, Outfit, soft shadowed cards (from the Exeria Figma file). */
@font-face { font-family: "Outfit"; src: url("fonts/outfit.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
:root {
  --navy: #001C5B; --gold: #BCBB80; --gold-soft: #F3F3E8;
  --bg: #F8F9FC; --panel: #ffffff; --ink: #0A1811; --heading: #001C5B; --muted: #6C6C75; --line: #EAEAEA; --soft: #F2F4F9;
  --accent: #001C5B; --accent-ink: #ffffff; --accent-soft: #E7EBF5; --danger: #C62828; --ok: #3F7A2E;
  --radius: 25px; --radius-sm: 14px; --shadow: 0 8px 24px rgba(149, 157, 165, .2);
  --logo-ink: #001C5B; --logo-gold: #BCBB80; --pattern: url("brand/pattern.svg");
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #060D22; --panel: #0E1936; --ink: #E8ECF6; --heading: #ffffff; --muted: #9AA3BD; --line: #1E2A4C; --soft: #152147;
    --accent: #BCBB80; --accent-ink: #001C5B; --accent-soft: #262F4B; --danger: #FF7A6E; --ok: #8BC37A;
    --shadow: 0 8px 24px rgba(0, 0, 0, .35); --logo-ink: #ffffff; --pattern: none; color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif; background: var(--bg); color: var(--ink); }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0; white-space: pre-wrap; }
.ok { color: var(--ok); }
.mono, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* Controls */
.label, label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--soft); }
.btn:disabled { opacity: .65; cursor: progress; }
.btn[aria-busy="true"]::before { content: ""; width: 13px; height: 13px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn[aria-busy="true"]::before { animation-duration: 2s; } }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; }
.row-actions.end { justify-content: flex-end; }
.inline { display: flex; gap: 8px; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.auth-card h1 { margin-top: 20px; }
.auth-card .btn-block { margin-top: 8px; }

/* Shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 8px 18px; }
.brand-lg { font-size: 20px; padding: 0; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { padding: 9px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
nav a:hover { background: var(--soft); color: var(--ink); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.whoami { font-size: 13px; padding: 0 8px 10px; overflow-wrap: anywhere; }
.whoami b { display: block; font-size: 14px; }
.content { padding: 28px 32px 48px; min-width: 0; }
.page { display: none; max-width: 1280px; }
.page.active { display: block; }
.page-head { margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; }

/* Cards & layout */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 460px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: 0 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.align-start { align-items: start; }
.align-end { align-items: end; }
.grid-2 > .card { margin-bottom: 18px; }

/* Checklist */
.check-list { border: 1px solid var(--line); border-radius: 8px; padding: 6px; max-height: 150px; overflow: auto; }
.check-list.horizontal { display: flex; flex-wrap: wrap; gap: 6px; max-height: none; border: 0; padding: 0; }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; margin: 0; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; }
.check:hover { background: var(--soft); }
.check input { width: auto; margin: 0; }
.check-list.horizontal .check { border: 1px solid var(--line); }
.check small { color: var(--muted); font-weight: 400; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .k { color: var(--muted); font-size: 13px; }
.tile .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* Tables */
.table-wrap { min-width: 0; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.table-count { font-size: 13px; font-weight: 600; color: var(--muted); }
.table-tools { display: flex; gap: 8px; align-items: center; }
.table-filter { width: 220px; padding: 6px 10px; font-size: 14px; }
.table-scroll { overflow: auto; max-height: 68vh; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
th, td { padding: 11px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; line-height: 1.45; }
th { position: sticky; top: 0; z-index: 2; background: var(--soft); padding: 0; white-space: nowrap; }
th.num { text-align: right; }
.th-btn { display: inline-flex; align-items: center; gap: 6px; width: 100%; justify-content: inherit; padding: 10px 16px; border: 0; background: none; font: inherit; font-size: 12px; font-weight: 700; letter-spacing: .02em; color: var(--muted); cursor: pointer; text-align: inherit; }
th.num .th-btn { justify-content: flex-end; }
.th-btn:hover { color: var(--ink); }
.sort-ind { font-size: 10px; opacity: .45; }
th[aria-sort="ascending"] .sort-ind, th[aria-sort="descending"] .sort-ind { opacity: 1; color: var(--accent); }
td { white-space: nowrap; unicode-bidi: plaintext; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }
td .dash { color: var(--line); }
tbody tr { cursor: pointer; }
tbody tr:hover td, tbody tr:focus-visible td { background: var(--soft); }
tbody tr:focus-visible { outline: none; }
tbody tr:focus-visible td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tbody tr:last-child td { border-bottom: 0; }
/* First column stays visible while scrolling sideways. */
th:first-child, td:first-child { position: sticky; left: 0; z-index: 1; background: var(--panel); }
th:first-child { z-index: 3; background: var(--soft); }
tbody tr:hover td:first-child { background: var(--soft); }
table.compact td { padding: 6px 12px; font-size: 13px; }
table.compact .th-btn { padding: 7px 12px; }
table.compact .clamp { -webkit-line-clamp: 1; }

/* Long text: a readable column width with clamped lines instead of a narrow wrapped strip. */
th.long-col { min-width: 320px; }
td.long-cell { white-space: normal; min-width: 320px; max-width: 520px; }
.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; white-space: pre-line; overflow-wrap: break-word; unicode-bidi: plaintext; }
.clamp.open { display: block; -webkit-line-clamp: unset; }
/* Follow each value's own direction so Arabic lines align right and Latin lines align left. */
td[dir="auto"], .clamp, .prose, .bubble, .thread-item b, .thread-item span, .chip-btn { text-align: start; }
.more { border: 0; background: none; padding: 2px 0 0; color: var(--accent); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip-btn { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid var(--line); background: var(--soft); color: var(--ink); border-radius: 6px; padding: 3px 8px; font: inherit; font-size: 13px; cursor: pointer; unicode-bidi: plaintext; }
.chip-btn:hover { border-color: var(--accent); }
.link { font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); text-transform: capitalize; white-space: nowrap; }
.badge.on { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.off { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.warn { background: color-mix(in srgb, #d97706 16%, transparent); color: #b45309; }
.badge.admin { background: var(--accent-soft); color: var(--accent); }
@media (prefers-color-scheme: dark) { .badge.warn { color: #fbbf24; } }

/* Row detail drawer */
.drawer-root { position: fixed; inset: 0; z-index: 60; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 20, .4); }
.drawer { position: absolute; top: 0; right: 0; height: 100%; width: min(560px, 100%); background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.15); animation: slide-in .16s ease-out; }
@keyframes slide-in { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; }
.drawer-body { overflow: auto; padding: 8px 20px 24px; }
.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; margin: 0; }
.kv dt { padding: 10px 12px 10px 0; color: var(--muted); font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.kv dd { margin: 0; padding: 10px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.prose { white-space: pre-wrap; overflow-wrap: break-word; unicode-bidi: plaintext; line-height: 1.6; }
pre.json { margin: 0; padding: 10px 12px; background: var(--soft); border-radius: 8px; font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: none; }
body.drawer-open { overflow: hidden; }
@media (max-width: 760px) { .kv { grid-template-columns: 1fr; } .kv dt { border-bottom: 0; padding-bottom: 0; } .table-filter { width: 100%; } .table-tools { width: 100%; } }

/* Explorer */
.field-picker { margin-top: 4px; }
.field-list { border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; height: 260px; overflow: auto; }
.field-list button { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; padding: 7px 10px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); font: inherit; font-size: 13px; cursor: pointer; }
.field-list button:hover { background: var(--soft); }
.field-list button span { color: var(--muted); white-space: nowrap; }
.field-list button.picked { background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; border: 1px dashed var(--line); border-radius: 8px; padding: 10px; min-height: 260px; margin-top: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border: 0; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.tpl-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 24px; margin-bottom: 14px; }
.tpl-source { width: 260px; max-width: 100%; }
.tpl-source .label { margin-top: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.tab:hover { color: var(--ink); background: var(--soft); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.tpl { display: flex; flex-direction: column; gap: 4px; text-align: left; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); padding: 12px 14px; font: inherit; cursor: pointer; }
.tpl:hover { border-color: var(--accent); }
.tpl.active { border-color: var(--accent); background: var(--accent-soft); }
.tpl b { font-size: 14px; }
.tpl span { font-size: 13px; color: var(--muted); }
.tpl small { font-size: 12px; color: var(--muted); }
.tpl.custom { border-style: dashed; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title-row h2 { margin: 0; }
.advanced { margin-top: 14px; }
.advanced summary { cursor: pointer; font-weight: 600; color: var(--muted); }

/* Messages */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
/* .card.flush sets overflow:hidden with higher specificity, so the scroll rules must match it. */
.card.thread-list, .card.thread-view { max-height: calc(100vh - 290px); min-height: 320px; overflow-y: auto; overscroll-behavior: contain; }
.thread-item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 12px 16px; font: inherit; color: var(--ink); cursor: pointer; }
.thread-item:hover, .thread-item.active { background: var(--soft); }
.thread-item b { display: block; unicode-bidi: plaintext; }
.thread-item span { font-size: 13px; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }
.bubble { max-width: 75%; margin: 8px 0; padding: 8px 12px; border-radius: 14px; background: var(--soft); white-space: pre-wrap; unicode-bidi: plaintext; }
.bubble.me { margin-left: auto; background: var(--accent-soft); }
.bubble small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }

/* Statistics: tiles with a second line, settings diff, before/after results */
.tile .v2 { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; overflow-wrap: anywhere; }
.card h3 { font-size: 14px; margin: 20px 0 8px; }
.note { background: var(--soft); border-radius: 8px; padding: 8px 12px; white-space: pre-wrap; unicode-bidi: plaintext; }
.th-static { display: block; padding: 10px 16px; font-size: 12px; font-weight: 700; letter-spacing: .02em; color: var(--muted); }
table.diff { border: 1px solid var(--line); border-radius: 8px; }
table.diff td { white-space: normal; min-width: 160px; max-width: 520px; overflow-wrap: anywhere; }
table.diff tbody tr { cursor: default; }
table.diff tbody tr:hover td { background: inherit; }
table.diff tr.changed td, table.diff tr.changed td:first-child { background: color-mix(in srgb, #d97706 9%, var(--panel)); }
table.diff tr.changed td:first-child { box-shadow: inset 3px 0 0 #d97706; }
table.diff td .badge { margin-left: 8px; }
.delta { font-weight: 600; }
.delta.good { color: var(--ok); }
.delta.bad { color: var(--danger); }
.period-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.role-select { width: auto; padding: 4px 8px; font-size: 13px; }
#assignList { max-height: 320px; margin-top: 8px; }
@media (max-width: 760px) { .period-grid { grid-template-columns: 1fr; } }

/* Manage */
.schema, .result { background: var(--soft); border-radius: 8px; padding: 12px; overflow: auto; max-height: 420px; white-space: pre-wrap; margin: 12px 0 0; }

/* Settings: API keys */
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .grow { flex: 1 1 280px; }
.key-reveal { margin-top: 16px; padding: 14px 16px; border: 1px solid color-mix(in srgb, var(--ok) 40%, var(--line)); background: color-mix(in srgb, var(--ok) 7%, var(--panel)); border-radius: var(--radius); }
.key-reveal p { margin: 0 0 8px; }
.copy-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.copy-row code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 8px 10px; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.card-note { margin: 0; padding: 10px 16px 0; }

/* Dialog & toast */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--ink); width: min(560px, 92vw); }
dialog::backdrop { background: rgba(10, 14, 20, .45); }
.dlg { padding: 22px; }
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--ink); color: var(--panel); padding: 11px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 420px; z-index: 50; }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 1000px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inbox { grid-template-columns: 1fr; }
  .card.thread-list { max-height: 45vh; min-height: 0; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: flex; align-items: center; gap: 8px; }
  .content { padding: 18px 16px 40px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- Exeria components ---------- */
h1, h2, h3 { color: var(--heading); font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-weight: 600; }
.label, label { color: var(--muted); font-weight: 500; }
a { color: var(--heading); }

/* Brand lockup */
.brand { gap: 10px; padding: 4px 10px 20px; color: var(--logo-ink); }
.brand-logo { height: 34px; width: auto; color: var(--logo-ink); flex: none; }
.brand-lg .brand-logo { height: 52px; }
.brand-product { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--navy); background: var(--gold-soft); border: 1px solid var(--gold); border-radius: 999px; padding: 2px 10px; }
@media (prefers-color-scheme: dark) { .brand-product { color: var(--gold); background: transparent; } }

/* Surfaces */
body { background-image: var(--pattern); background-size: 90px 110px; background-attachment: fixed; }
.card { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); }
.card.flush { border-radius: var(--radius); }
.tile { border: 0; border-radius: 20px; box-shadow: var(--shadow); }
.tile .v { color: var(--heading); }
.tile .k { font-weight: 500; }

/* Controls: pills like the Exeria app */
.btn { border-radius: 999px; font-weight: 600; padding: 9px 20px; }
.btn-sm { padding: 5px 14px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:not(.btn-primary):not(.btn-danger):not(.btn-ghost) { border-color: var(--line); box-shadow: 0 1px 2px rgba(149, 157, 165, .15); }
input, select, textarea { border-radius: var(--radius-sm); border-color: var(--line); background: var(--panel); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold); }
.check-list { border-radius: var(--radius-sm); }
.check-list.horizontal .check { border-radius: 999px; }

/* Sidebar: white panel, pill navigation, navy active state */
.sidebar { border-right: 0; box-shadow: 4px 0 24px rgba(149, 157, 165, .15); padding: 22px 14px; }
nav { gap: 4px; }
nav a { border-radius: 999px; padding: 10px 16px; font-weight: 500; }
nav a:hover { background: var(--soft); color: var(--heading); }
nav a.active { background: var(--navy); color: #fff; font-weight: 600; box-shadow: 0 6px 16px rgba(0, 28, 91, .25); }
@media (prefers-color-scheme: dark) { nav a.active { background: var(--gold); color: var(--navy); } }
.whoami b { color: var(--heading); }

/* Tables */
th { background: var(--soft); }
.th-btn, .th-static { color: var(--heading); }
.table-toolbar { border-radius: var(--radius) var(--radius) 0 0; }
.badge { font-weight: 600; }
.badge.admin { background: var(--gold-soft); color: var(--navy); }
.chip { background: var(--gold-soft); color: var(--navy); }
.tab[aria-selected="true"], .tpl.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.tpl { border-radius: 18px; }
.tpl.active span, .tpl.active small { color: rgba(255, 255, 255, .8); }
@media (prefers-color-scheme: dark) {
  .badge.admin, .chip { background: var(--accent-soft); color: var(--gold); }
  .tab[aria-selected="true"], .tpl.active { background: var(--gold); color: var(--navy); border-color: var(--gold); }
  .tpl.active span, .tpl.active small { color: var(--navy); }
}

/* Sign-in: owl pattern, white card, big lockup */
.auth { background: var(--bg) var(--pattern); background-size: 90px 110px; }
.auth-card { border: 0; border-radius: 28px; box-shadow: 0 12px 40px rgba(0, 28, 91, .12); padding: 36px; }
.auth-card .brand { padding: 0; flex-wrap: wrap; }

/* Dialogs, toasts, drawer */
dialog { border: 0; border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0, 28, 91, .2); }
.toast { background: var(--navy); color: #fff; border-radius: 16px; }
@media (prefers-color-scheme: dark) { .toast { background: var(--gold); color: var(--navy); } }
.drawer { border-radius: var(--radius) 0 0 var(--radius); border-left: 0; }
.key-reveal, .note { border-radius: 18px; }

/* Facebook connect */
.steps { margin: 4px 0 16px; padding-left: 20px; color: var(--muted); font-size: 14px; }
.steps li { margin: 4px 0; }
.btn-facebook { background: #1877F2; border-color: #1877F2; color: #fff; }
.btn-facebook:hover { background: #1877F2; filter: brightness(1.06); }

/* Legal pages */
.legal-links { margin: 14px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.legal-links a { color: var(--muted); }
body.legal { background: var(--bg) var(--pattern); background-size: 90px 110px; }
.legal-page { max-width: 780px; margin: 32px auto; padding: 36px 40px; background: var(--panel); border-radius: 28px; box-shadow: var(--shadow); line-height: 1.65; }
.legal-page h1 { font-size: 30px; margin: 22px 0 6px; }
.legal-page h2 { font-size: 19px; margin: 28px 0 8px; }
.legal-page h3 { font-size: 15px; margin: 18px 0 6px; color: var(--ink); }
.legal-page ul, .legal-page ol { padding-left: 22px; }
.legal-page li { margin: 6px 0; }
.legal-brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.legal-foot { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 14px; }
@media (max-width: 760px) { .legal-page { margin: 0; border-radius: 0; padding: 24px 18px; } }

/* ---------- language and direction ---------- */
.lang-pick { width: 100%; margin-bottom: 8px; }
/* Arabic mirrors the whole interface. Only the few physical rules below need flipping; the rest
   of the stylesheet already lays out with flex/grid, which follows the document direction. */
[dir="rtl"] .sidebar { border-right: 0; border-left: 1px solid var(--line); box-shadow: -4px 0 24px rgba(149, 157, 165, .15); }
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
[dir="rtl"] th.num, [dir="rtl"] td.num { text-align: left; }
[dir="rtl"] th:first-child, [dir="rtl"] td:first-child { left: auto; right: 0; }
[dir="rtl"] .drawer { right: auto; left: 0; border-left: 0; border-right: 1px solid var(--line); box-shadow: 8px 0 30px rgba(0,0,0,.15); }
[dir="rtl"] .toast { right: auto; left: 22px; }
[dir="rtl"] .bubble.me { margin-left: 0; margin-right: auto; }
[dir="rtl"] .steps, [dir="rtl"] .legal-page ul, [dir="rtl"] .legal-page ol { padding-left: 0; padding-right: 20px; }
[dir="rtl"] table.diff td .badge { margin-left: 0; margin-right: 8px; }
[dir="rtl"] .field-list button, [dir="rtl"] .tpl, [dir="rtl"] .thread-item { text-align: right; }
[dir="rtl"] .chat-msg.me { flex-direction: row-reverse; }
/* Figures keep their own direction: without this, Arabic reorders "154 200" into "200 154". */
.tile .v, .tile .v2, td.num, .plan-dl dd, .chat-meta, .badge { unicode-bidi: isolate; }
[dir="rtl"] .tile .v, [dir="rtl"] .tile .v2, [dir="rtl"] td.num { direction: ltr; }

/* ---------- AI chat ---------- */
.chat-shell { display: flex; flex-direction: column; gap: 12px; height: calc(100vh - 190px); min-height: 420px; }
.chat-log {
  flex: 1; overflow-y: auto; padding: 18px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; gap: 14px;
}
.chat-empty { margin: auto; text-align: center; max-width: 520px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.chat-owl { width: 46px; height: 72px; color: var(--accent); opacity: .9; }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chat-msg { display: flex; gap: 10px; align-items: flex-start; max-width: 80%; }
.chat-msg.me { margin-inline-start: auto; flex-direction: row-reverse; }
.chat-avatar { width: 20px; height: 31px; flex: none; color: var(--accent); margin-top: 2px; }
.chat-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.chat-text {
  white-space: pre-wrap; overflow-wrap: anywhere; padding: 11px 14px; border-radius: 14px;
  background: var(--bg); border: 1px solid var(--line); line-height: 1.55;
}
.chat-msg.me .chat-text { background: var(--accent-soft); border-color: transparent; }
.chat-msg.pending .chat-text { color: var(--muted); font-style: italic; }
.chat-msg.bad .chat-text { border-color: var(--danger, #b3261e); }
.chat-meta { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-bar { display: flex; gap: 8px; align-items: flex-end; }
.chat-bar textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 160px; padding: 12px 14px;
  border-radius: 12px; line-height: 1.5;
}
.chat-send { width: 44px; height: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; }
[dir="rtl"] .chat-send svg { transform: scaleX(-1); }
.chat-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0; }

.chat-scope { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 10px; }
.chat-scope-label { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--muted); cursor: pointer; }
.chat-scope-label input { margin: 0; }

/* ---------- support tickets ---------- */
.ticket-split { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 16px; align-items: start; }
.ticket-list { max-height: 70vh; overflow-y: auto; }
.ticket-item {
  display: block; width: 100%; text-align: start; border: 0; border-bottom: 1px solid var(--line);
  background: none; padding: 12px 16px; font: inherit; color: var(--ink); cursor: pointer;
}
.ticket-item:hover, .ticket-item.active { background: var(--accent-soft); }
.ticket-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.ticket-row + .ticket-row { margin-top: 4px; }
.ticket-messages { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; max-height: 46vh; overflow-y: auto; }
.ticket-reply { display: flex; flex-direction: column; gap: 8px; }
.ticket-reply textarea { width: 100%; }
.badge-open { background: var(--accent-soft); color: var(--accent); }
.badge-in_progress { background: #fdf0d5; color: #92610a; }
.badge-waiting_client { background: #eef1f6; color: var(--muted); }
.badge-resolved, .badge-closed { background: #e4f3ec; color: #12674c; }

/* ---------- plan ---------- */
.plan-body { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.plan-badge {
  font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: 12px;
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
}
.plan-silver { background: #eef1f6; color: #5a6675; }
.plan-gold { background: #fbf1da; color: #8a6300; border-color: #e6c987; }
.plan-platinum { background: var(--accent-soft); color: var(--accent); border-color: currentColor; }
.plan-dl { display: grid; grid-template-columns: auto auto; gap: 4px 16px; margin: 0; font-size: 14px; }
.plan-dl dt { color: var(--muted); }
.plan-dl dd { margin: 0; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .ticket-split { grid-template-columns: 1fr; }
  .chat-shell { height: auto; }
  .chat-log { min-height: 320px; }
  .chat-msg { max-width: 100%; }
}
