/* BrainWave: calm, high-contrast, direction-agnostic (logical properties give RTL for free). */
:root {
    --ink: #123a42;
    --text: #23343a;
    --muted: #5b6f75;
    --brand: #0f6f78;
    --brand-soft: #e2f1f1;
    --bg: #f4f7f7;
    --card: #fff;
    --line: #d7e2e3;
    --warn-bg: #fff4dc;
    --warn: #7a5200;
    --danger: #a4312a;
    --ok-bg: #e3f4e8;
    --ok: #1f6b3a;
    --radius: 12px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; background: var(--bg); color: var(--text); line-height: 1.55; }
a { color: var(--brand); }
h1, h2, h3 { color: var(--ink); line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
:focus-visible { outline: 3px solid #e59b00; outline-offset: 2px; }

/* Hidden by clipping, not by moving off screen, which would shift right-to-left pages. */
.skip { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip:focus { width: auto; height: auto; clip-path: none; inset-inline-start: 1rem; top: .5rem; background: #fff; padding: .5rem 1rem; z-index: 10; }

.topbar { background: var(--ink); color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem; padding: .7rem 1.25rem; }
.topbar a { color: #fff; text-decoration: none; padding: .25rem .1rem; border-bottom: 2px solid transparent; }
.topbar a[aria-current] { border-bottom-color: #7fd6d6; }
.brand { font-weight: 700; font-size: 1.15rem; margin-inline-end: .5rem; }
.topbar .spacer { flex: 1; }
.topbar form { margin: 0; }
.topbar button { background: transparent; border: 1px solid #5f8a91; color: #fff; }

main { max-width: 1120px; margin: 0 auto; padding: 1.25rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid > .card { margin: 0; }
.grid + * { margin-top: 1rem; }
.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 1rem; }
.stat strong { display: block; font-size: 1.9rem; color: var(--ink); }
.muted { color: var(--muted); }
.small { font-size: .87rem; }

.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.row > h1, .row > h2 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

.btn, button { display: inline-block; font: inherit; cursor: pointer; border: 1px solid var(--brand); background: var(--brand); color: #fff; border-radius: 8px; padding: .42rem .9rem; text-decoration: none; }
.btn.secondary, button.secondary { background: #fff; color: var(--brand); }
.btn.danger, button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.linkbtn { background: none; border: 0; color: var(--danger); padding: 0; text-decoration: underline; }

.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; }
.tabs a { padding: .45rem .85rem; text-decoration: none; border-radius: 8px 8px 0 0; color: var(--muted); }
.tabs a[aria-current] { background: var(--ink); color: #fff; }

/* relative: keeps visually hidden cell text inside the scrolling box. */
.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: start; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }

label { display: block; font-weight: 600; margin-bottom: .25rem; color: var(--ink); }
input, select, textarea { font: inherit; width: 100%; padding: .45rem .6rem; border: 1px solid #a9bcbf; border-radius: 8px; background: #fff; color: var(--text); }
input[type=checkbox], input[type=radio] { width: auto; margin-inline-end: .4rem; }
textarea { min-height: 5.5rem; resize: vertical; }
.field { margin-bottom: .9rem; }
.field.check label { display: flex; align-items: baseline; font-weight: 500; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.error { color: var(--danger); font-size: .88rem; margin-top: .2rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.inline-form .field { margin: 0; min-width: 150px; }

.alert { border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: #fbe9e7; color: var(--danger); }
.badge { display: inline-block; font-size: .8rem; padding: .1rem .55rem; border-radius: 99px; background: var(--brand-soft); color: var(--ink); white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }

progress { width: 100%; height: .7rem; accent-color: var(--brand); }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; gap: .6rem; align-items: center; margin-bottom: .3rem; font-size: .9rem; }

.thread { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.msg { background: var(--brand-soft); border-radius: var(--radius); padding: .6rem .9rem; max-width: 75%; align-self: flex-start; }
.msg .body { white-space: pre-wrap; }
.msg.mine { background: #e9eefc; align-self: flex-end; }
.narrative { white-space: pre-wrap; }

.login { max-width: 400px; margin: 8vh auto; }
.pagination { display: flex; gap: .75rem; align-items: center; justify-content: center; margin-top: .8rem; }

@media (max-width: 640px) {
    main { padding: .75rem; }
    .msg { max-width: 92%; }
    /* One swipeable row for navigation and tabs, so content starts near the top. */
    .topbar { padding: .5rem .75rem; gap: .35rem .75rem; }
    .topbar nav.actions { order: 5; width: 100%; }
    .topbar nav.actions, .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
    .topbar nav a, .tabs a { white-space: nowrap; }
    /* Tables scroll sideways instead of squeezing words onto many lines. */
    .table-wrap table { width: max-content; min-width: 100%; }
    .table-wrap td { max-width: 15rem; min-width: 5.5rem; }
}

@media print {
    .topbar, .tabs, .no-print, .skip { display: none !important; }
    body { background: #fff; }
    main { max-width: none; padding: 0; }
    .card { border: 0; padding: 0; break-inside: avoid; }
}

/* Welcome page */
.hero { padding: 2rem 1.5rem; background: var(--brand-soft); border-color: #bcdcdc; }
.hero h1 { font-size: 1.9rem; max-width: 24ch; }
.hero .lead { font-size: 1.1rem; max-width: 62ch; color: var(--text); }
.section-title { margin: 1.6rem 0 .8rem; }
.features .feature h3 { color: var(--brand); }
.features .feature p { margin: 0; }
.demo { border-color: var(--brand); border-width: 2px; margin-top: 1.5rem; }
.demo code { background: var(--brand-soft); padding: .1rem .4rem; border-radius: 6px; }

