:root {
  --paper: #eef1f7;
  --panel: #ffffff;
  --ink: #1b2340;
  --ink-2: #4a5475;
  --ink-3: #7c86a4;
  --line: #d5dbe8;
  --line-2: #e6eaf2;
  --live: #1f9d6b;
  --live-soft: #dff3ea;
  --alert: #c2412d;
  --alert-soft: #fbe7e2;
  --warn: #a8690f;
  --focus: #3e63dd;
  --shadow: 0 1px 0 rgba(27, 35, 64, .06);
  --r-sm: 6px;
  --r-md: 10px;
  --font: "Readex Pro", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121829;
    --panel: #1a2238;
    --ink: #e7ebf5;
    --ink-2: #b3bbd4;
    --ink-3: #7f89a8;
    --line: #2a3452;
    --line-2: #222b45;
    --live: #3fc48e;
    --live-soft: #173a30;
    --alert: #f07a64;
    --alert-soft: #3d2124;
    --warn: #e0a94a;
    --focus: #8aa4ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  font-feature-settings: "tnum" 1;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--focus); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--ink-3); }
.boot { padding: 80px 16px; text-align: center; color: var(--ink-3); }

/* ---------- الدخول ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 28px; }
.gate h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.gate p { margin: 0 0 20px; color: var(--ink-2); font-size: 14px; }

/* ---------- عناصر النماذج ---------- */
.field { display: grid; gap: 4px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 12px; }
input[type=text], input[type=password], input[type=url], select, textarea {
  width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 9px 11px; outline: none; min-height: 40px;
}
textarea { min-height: 96px; resize: vertical; font-size: 13px; direction: ltr; text-align: left; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); }
input.ltr, .ltr { direction: ltr; text-align: left; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 14px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--r-sm); padding: 8px 14px; min-height: 38px; cursor: pointer; font-weight: 500; font-size: 14px;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.danger { color: var(--alert); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.err { color: var(--alert); font-size: 13px; margin: 8px 0 0; }

/* ---------- الرأس ---------- */
.top {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 600; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 4px var(--live-soft); }
.top .spacer { flex: 1; }
.top .stamp { font-size: 12px; color: var(--ink-3); }
.tabs { display: flex; gap: 2px; background: var(--line-2); padding: 3px; border-radius: 8px; }
.tabs button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.tabs button[aria-pressed=true] { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

main { max-width: 1240px; margin: 0 auto; padding: 22px 16px 60px; }

/* ---------- جملة اليوم (العنصر الأبرز) ---------- */
.today { margin: 6px 0 22px; }
.today h1 {
  margin: 0; font-weight: 300; font-size: clamp(22px, 3.4vw, 34px); line-height: 1.5; max-width: 34ch;
  letter-spacing: -0.005em;
}
.today h1 b { font-weight: 600; }
.today h1 .live { color: var(--live); }
.today h1 .quiet { color: var(--ink-3); }
.figures { display: flex; flex-wrap: wrap; gap: 6px 28px; margin-top: 14px; color: var(--ink-2); font-size: 14px; }
.figures div { display: flex; align-items: baseline; gap: 8px; }
.figures div b { color: var(--ink); font-weight: 600; font-size: 18px; }

/* ---------- سجل المشاريع ---------- */
.section-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 30px 0 10px; }
.section-h h2 { margin: 0; font-size: 18px; font-weight: 600; }
.section-h span { font-size: 13px; color: var(--ink-3); }

.ledger { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow); }
.ledger-head, .row {
  display: grid;
  grid-template-columns: minmax(170px, 1.6fr) repeat(6, minmax(84px, 1fr)) minmax(100px, 1fr) 90px;
  align-items: center; gap: 8px; padding: 12px 16px;
}
.ledger-head { font-size: 12px; color: var(--ink-3); border-bottom: 1px solid var(--line); padding-top: 10px; padding-bottom: 10px; }
.row {
  border-bottom: 1px solid var(--line-2); cursor: pointer; position: relative; background: none; border-inline: 0; border-top: 0;
  width: 100%; text-align: inherit;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: color-mix(in srgb, var(--paper) 55%, var(--panel)); }
.row::before { content: ""; position: absolute; inset-inline-start: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--accent, var(--line)); }
.p-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.p-name .ic { font-size: 20px; width: 28px; text-align: center; }
.p-name strong { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-name small { display: block; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-name small.bad { color: var(--alert); }
.cell .v { font-size: 18px; font-weight: 600; line-height: 1.2; }
.cell .s { font-size: 12px; color: var(--ink-3); }
.cell .s .up { color: var(--live); }
.cell .s .down { color: var(--alert); }
.cell .lab { display: none; }
.cell.dim .v { color: var(--ink-3); font-weight: 400; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-inline-end: 6px; vertical-align: middle; }
.dot.on { background: var(--live); animation: beat 2.4s ease-in-out infinite; }
@keyframes beat { 0%, 100% { box-shadow: 0 0 0 0 var(--live-soft); } 50% { box-shadow: 0 0 0 5px var(--live-soft); } }
@media (prefers-reduced-motion: reduce) { .dot.on { animation: none; } }
.spark { width: 96px; height: 30px; display: block; }
.spark path.l { fill: none; stroke: var(--accent, var(--ink-3)); stroke-width: 1.6; }
.spark path.a { fill: var(--accent, var(--ink-3)); opacity: .12; }
.connect-hint { grid-column: 2 / -1; font-size: 13px; color: var(--ink-3); }
.connect-hint b { color: var(--focus); font-weight: 500; }

/* ---------- اليوتيوب ---------- */
.yt { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.ch { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; }
.ch-h { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.ch-h img { width: 44px; height: 44px; border-radius: 50%; background: var(--line-2); }
.ch-h strong { font-weight: 600; display: block; }
.ch-h a { font-size: 12px; }
.ch-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.ch-stats .v { font-size: 22px; font-weight: 600; line-height: 1.2; }
.ch-stats .s { font-size: 12px; color: var(--ink-3); }
.vids { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-2); }
.vids li { display: flex; gap: 10px; justify-content: space-between; padding: 7px 0; font-size: 13px; border-bottom: 1px solid var(--line-2); }
.vids li:last-child { border-bottom: 0; }
.vids li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vids li span:last-child { color: var(--ink-3); white-space: nowrap; }

.notice { border: 1px solid var(--line); background: var(--panel); border-radius: var(--r-md); padding: 14px 16px; font-size: 14px; color: var(--ink-2); }
.notice.bad { border-color: color-mix(in srgb, var(--alert) 40%, var(--line)); background: var(--alert-soft); color: var(--ink); }

/* ---------- الدرج الجانبي ---------- */
.drawer { position: fixed; inset: 0; z-index: 20; display: flex; }
.drawer .shade { flex: 1; background: rgba(15, 20, 38, .45); }
.drawer .sheet {
  width: min(560px, 100%); background: var(--panel); height: 100%; overflow-y: auto; border-inline-start: 1px solid var(--line);
  padding: 20px; animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer .sheet { animation: none; } }
.sheet-h { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.sheet-h h2 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.kv div { border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 10px 12px; }
.kv .v { font-size: 20px; font-weight: 600; display: block; line-height: 1.3; }
.kv .s { font-size: 12px; color: var(--ink-3); }
.sheet h3 { font-size: 15px; font-weight: 600; margin: 20px 0 8px; }
.list { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line-2); border-radius: var(--r-sm); }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.list li .t { color: var(--ink-3); font-size: 13px; white-space: nowrap; }
.list li .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; unicode-bidi: plaintext; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 70px; border-bottom: 1px solid var(--line); margin-bottom: 4px; direction: ltr; }
.bars i { flex: 1; background: var(--accent, var(--ink-3)); opacity: .75; min-height: 1px; border-radius: 2px 2px 0 0; }
.bars-cap { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); direction: ltr; }

/* ---------- الإعدادات ---------- */
.settings { display: grid; grid-template-columns: 210px 1fr; gap: 22px; align-items: start; }
.side { display: grid; gap: 2px; position: sticky; top: 72px; }
.side button { text-align: start; border: 0; background: none; padding: 9px 12px; border-radius: var(--r-sm); cursor: pointer; color: var(--ink-2); }
.side button[aria-current=true] { background: var(--panel); color: var(--ink); font-weight: 500; box-shadow: var(--shadow); }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 22px; min-width: 0; }
.pane h2 { margin: 0 0 4px; font-size: 19px; font-weight: 600; }
.pane > p.lead { margin: 0 0 18px; color: var(--ink-2); font-size: 14px; max-width: 70ch; }
.pane h3 { font-size: 15px; font-weight: 600; margin: 24px 0 10px; padding-top: 18px; border-top: 1px solid var(--line-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.plist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line-2); border-radius: var(--r-sm); }
.plist li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line-2); }
.plist li:last-child { border-bottom: 0; }
.plist li .grow { flex: 1; min-width: 0; }
.plist li small { display: block; color: var(--ink-3); font-size: 12px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.tag.ok { background: var(--live-soft); color: var(--live); }
.tag.bad { background: var(--alert-soft); color: var(--alert); }
details.help { background: var(--paper); border-radius: var(--r-sm); padding: 10px 14px; margin: 0 0 16px; font-size: 14px; }
details.help summary { cursor: pointer; font-weight: 500; }
details.help ol { margin: 10px 0 4px; padding-inline-start: 20px; }
details.help li { margin-bottom: 6px; }
code, .code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--line-2); padding: 1px 5px; border-radius: 4px; direction: ltr; unicode-bidi: isolate; }
pre.out {
  background: var(--paper); border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 12px; overflow-x: auto;
  font-size: 12.5px; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-word; max-height: 320px;
}
.scan-app { border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 10px 12px; margin-bottom: 8px; }
.scan-app .db { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 6px 0; border-top: 1px dashed var(--line-2); font-size: 13px; }
.scan-app .db:first-of-type { border-top: 0; }
.scan-app .db code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.box { border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 14px; margin-bottom: 14px; }
.extra-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; margin-bottom: 8px; }

.toast {
  position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(50%); background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; }
.toast.bad { background: var(--alert); color: #fff; }

/* ---------- الموبايل ---------- */
@media (max-width: 960px) {
  .ledger-head { display: none; }
  .row { grid-template-columns: repeat(3, 1fr); gap: 12px 10px; padding: 14px 16px 14px 16px; padding-inline-start: 20px; }
  .row .p-name { grid-column: 1 / -1; }
  .row .spark-cell { display: none; }
  .row .go { display: none; }
  .cell .lab { display: block; font-size: 11px; color: var(--ink-3); }
  .connect-hint { grid-column: 1 / -1; }
  .settings { grid-template-columns: 1fr; }
  .side { position: static; display: flex; overflow-x: auto; gap: 4px; }
  .side button { white-space: nowrap; }
  .grid2 { grid-template-columns: 1fr; }
  .section-h span { display: none; }
}
@media (max-width: 520px) {
  .top .stamp { display: none; }
  .pane { padding: 16px; }
  .yt { grid-template-columns: 1fr; }
  .extra-row { grid-template-columns: 1fr; }
}
