/* جدوى منصة الحرفيين — التصميم */

/* ── الخط (محفوظ على السيرفر) ── */
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-arabic-400.b88ccd3247d2.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E, U+2010-2011, U+204F, U+2E41; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-arabic-500.48674700322e.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E, U+2010-2011, U+204F, U+2E41; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-arabic-600.597b7873fee3.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E, U+2010-2011, U+204F, U+2E41; }
@font-face { font-family: "Plex Arabic"; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-arabic-700.c057ba3c2827.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E, U+2010-2011, U+204F, U+2E41; }
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-latin-400.d431f94c0b9f.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-latin-500.abc7a447358f.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-latin-600.58d827ef695d.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plex Arabic"; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-latin-700.a5fc85cc7d80.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --bg: #000000;
  --panel: #121212;
  --panel-2: #191919;
  --line: #242424;
  --line-soft: #1b1b1b;
  --text: #ececec;
  --muted: #8f8f8f;
  --accent: #c9a54e;
  --accent-soft: rgba(201, 165, 78, .13);
  --accent-line: rgba(201, 165, 78, .55);
  --pos: #7cc49a;
  --neg: #e2786a;
  --pos-soft: rgba(124, 196, 154, .12);
  --neg-soft: rgba(226, 120, 106, .12);
  --s1: #c9a54e; --s2: #7fb3e0; --s3: #b593e3; --s4: #e39bbd;
  --radius: 16px;
  --radius-sm: 11px;
  --font: "Plex Arabic", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Geeza Pro", "Noto Sans Arabic", Arial, sans-serif;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.65;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.35; font-weight: 600; letter-spacing: 0; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic.sm { width: 15px; height: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 40px 0; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.acc { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
[hidden] { display: none !important; }

/* ── الهيكل ── */
.shell { max-width: 1280px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + var(--safe-b) + 24px); }
.appbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(10px + var(--safe-t)) 0 10px; background: rgba(0, 0, 0, .86);
  -webkit-backdrop-filter: saturate(140%) blur(14px); backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line-soft); margin: 0 -16px; padding-inline: 16px;
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; min-width: 0; }
.brand img { border-radius: 9px; }
.brand span { display: flex; flex-direction: column; line-height: 1.25; }
.brand b { font-weight: 600; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11.5px; }
.topnav { display: none; gap: 4px; }
.topnav a { text-decoration: none; color: var(--muted); padding: 8px 14px; border-radius: 10px; font-size: 14px; }
.topnav a:hover { color: var(--text); background: var(--panel); }
.topnav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.page { padding-top: 22px; }

.bottomnav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 40; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 6px 4px calc(6px + var(--safe-b)); background: rgba(8, 8, 8, .94);
  -webkit-backdrop-filter: saturate(150%) blur(16px); backdrop-filter: saturate(150%) blur(16px);
  border-top: 1px solid var(--line);
}
.bottomnav a, .bottomnav button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 52px; padding: 4px 2px; border: 0; background: none; text-decoration: none; cursor: pointer;
  color: var(--muted); font-size: 11.5px; line-height: 1.2; border-radius: 12px;
}
.bottomnav .ic { width: 23px; height: 23px; }
.bottomnav span { white-space: nowrap; }
.bottomnav [aria-current="page"], .bottomnav [aria-current="true"] { color: var(--accent); font-weight: 600; }
.bottomnav [aria-current="page"]::before, .bottomnav [aria-current="true"]::before {
  content: ""; position: absolute; top: -6px; width: 26px; height: 2.5px; border-radius: 2px; background: var(--accent);
}

/* ── عناصر عامة ── */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head p { margin-top: 6px; max-width: 640px; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { display: flex; align-items: center; gap: 9px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.narrow { max-width: 520px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: 12px; background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(201, 165, 78, .3); white-space: nowrap; }
.badge.gray { background: var(--panel-2); color: var(--muted); border-color: var(--line); }
.hint { display: block; color: var(--muted); font-size: 13px; }
.alert { padding: 11px 14px; border-radius: 12px; font-size: 14px; border: 1px solid var(--line); }
.alert.neg { background: var(--neg-soft); color: var(--neg); border-color: rgba(226, 120, 106, .3); }
.alert.pos { background: var(--pos-soft); color: var(--pos); border-color: rgba(124, 196, 154, .3); margin-bottom: 12px; }
.alert.warn { background: var(--accent-soft); color: var(--accent); border-color: rgba(201, 165, 78, .3); }
.err { color: var(--neg); font-size: 13px; margin-top: -6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  text-decoration: none; cursor: pointer; font-size: 14.5px; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.btn:hover { border-color: #353535; background: #1f1f1f; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #141006; font-weight: 600; }
.btn.primary:hover { background: #d6b25b; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel); }
.btn.danger { color: var(--neg); }
.btn.danger.solid { background: var(--neg); border-color: var(--neg); color: #1a0a07; font-weight: 600; }
.btn.big { min-height: 50px; padding: 0 20px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.iconbtn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 12px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none;
}
.iconbtn:hover { color: var(--text); background: var(--panel-2); border-color: var(--line); }
.iconbtn.danger:hover { color: var(--neg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13.5px; color: var(--muted); }
.field input, .field textarea, .field select {
  min-height: 50px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2);
  outline: none; font-size: 16px; transition: border-color .15s, background .15s;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--accent); background: #1c1a15; }

/* ── تسجيل الدخول ── */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px; padding: 32px 24px;
  background: radial-gradient(120% 70% at 50% 0%, rgba(201, 165, 78, .09), transparent 60%), var(--panel);
  border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
.auth-card h1 { text-align: center; font-size: 22px; }
.auth-card > p.muted { text-align: center; margin-top: -8px; }
.auth-logo { align-self: center; border-radius: 18px; box-shadow: 0 10px 40px rgba(201, 165, 78, .15); }

/* ── قائمة السيناريوهات ── */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); }
.sc-card { position: relative; display: flex; flex-direction: column; gap: 14px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); transition: border-color .15s; }
.sc-card:hover { border-color: #303030; }
.sc-card.ref { border-color: rgba(201, 165, 78, .45); background: linear-gradient(180deg, rgba(201, 165, 78, .06), transparent 40%), var(--panel); }
.sc-card.picked { outline: 2px solid var(--accent); outline-offset: -1px; }
.sc-top { display: flex; align-items: flex-start; gap: 10px; }
.sc-title { flex: 1; min-width: 0; text-decoration: none; }
.sc-title h2 { font-size: 17px; overflow-wrap: anywhere; }
.sc-title p { color: var(--muted); font-size: 13.5px; margin-top: 3px; overflow-wrap: anywhere; }
.sc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.sc-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.sc-stats div { background: var(--panel-2); padding: 10px 12px; }
.sc-stats span { display: block; font-size: 12px; color: var(--muted); }
.sc-stats b { font-size: 16.5px; font-weight: 600; }
.sc-actions { display: flex; gap: 8px; }
.sc-actions .btn.primary { flex: 1; }
.pick { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-size: 14px; user-select: none; }
.pick input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.comparebar {
  position: fixed; z-index: 35; inset-inline: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); display: flex; align-items: center; gap: 10px;
  max-width: 560px; margin: 0 auto; padding: 10px 10px 10px 16px; padding-inline-start: 18px; border-radius: 16px; background: #1b1913; border: 1px solid rgba(201, 165, 78, .4);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .7);
}
.comparebar span { flex: 1; font-size: 14px; }
.empty { text-align: center; padding: 50px 20px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty .btn { margin-top: 16px; }

/* ── المحرر ── */
.editor-page .shell { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 28px); }
.resultsbar {
  position: sticky; top: 0; z-index: 30; margin: 0 -16px; padding: calc(6px + var(--safe-t)) 12px 10px;
  background: rgba(0, 0, 0, .9); -webkit-backdrop-filter: saturate(140%) blur(14px); backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.rb-top { display: flex; align-items: center; gap: 6px; min-height: 44px; }
.rb-name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; background: none; border: 0; padding: 6px 4px; cursor: pointer; text-align: start; color: var(--text); }
.rb-name span { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-name .ic { color: var(--muted); }
.savestate { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border-radius: 99px; font-size: 12.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); white-space: nowrap; }
.savestate i { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); }
.savestate[data-state="dirty"] i, .savestate[data-state="saving"] i { background: var(--accent); animation: pulse 1s infinite; }
.savestate[data-state="error"] { color: var(--neg); border-color: rgba(226, 120, 106, .35); }
.savestate[data-state="error"] i { background: var(--neg); }
@keyframes pulse { 50% { opacity: .3; } }
.rb-kpis { display: grid; grid-template-columns: 1.25fr 1fr .8fr; gap: 6px; margin-top: 6px; }
.kpi { padding: 7px 10px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line-soft); min-width: 0; }
.kpi span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi b { display: block; font-size: 16.5px; font-weight: 600; line-height: 1.35; }
.kpi.main b { color: var(--accent); }
.rb-years { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 6px; }
.rb-years div { text-align: center; padding: 4px 2px; border-radius: 9px; background: var(--panel); min-width: 0; }
.rb-years span { display: block; font-size: 10.5px; color: var(--muted); line-height: 1.3; }
.rb-years b { display: block; font-size: 12.5px; font-weight: 600; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; }
.rb-caption { display: none; }

.editor-body { display: block; }
.sidenav { display: none; }
.editor-main { min-width: 0; padding-top: 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 14px; padding: 2px 16px; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; min-height: 40px; padding: 0 15px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer; font-size: 14px; white-space: nowrap; }
.chips button[aria-current="true"] { color: #141006; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.chips:empty { display: none; }
.content { display: flex; flex-direction: column; gap: 14px; }
.tab-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.tab-head p { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* أقسام قابلة للطي */
.sec { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.sec > summary {
  list-style: none; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 12px 16px; cursor: pointer; user-select: none;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary h2 { flex: 1; font-size: 16px; }
.sec > summary small { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.sec > summary::after { content: ""; width: 9px; height: 9px; border-left: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted); transform: rotate(-45deg); margin-top: -4px; transition: transform .2s; }
.sec[open] > summary::after { transform: rotate(135deg); margin-top: 4px; }
.sec-body { padding: 2px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.sec-note { color: var(--muted); font-size: 13.5px; margin-top: -4px; }

/* حقول */
.frow { display: grid; grid-template-columns: 1fr minmax(120px, 170px); align-items: center; gap: 12px; padding: 4px 0; }
.frow + .frow { border-top: 1px solid var(--line-soft); padding-top: 12px; }
.flabel { font-size: 14.5px; }
.flabel small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.5; margin-top: 2px; }
.inwrap { position: relative; display: flex; align-items: center; gap: 6px; }
.unit { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.in {
  width: 100%; min-width: 0; height: 42px; padding: 0 6px; border: 0; border-bottom: 1.5px solid var(--accent-line); border-radius: 8px 8px 2px 2px;
  background: rgba(255, 255, 255, .025); color: var(--text); text-align: center; outline: none; font-size: 16px; font-weight: 500;
  font-variant-numeric: tabular-nums; direction: ltr; transition: background .15s, border-color .15s;
}
.in:hover { background: rgba(201, 165, 78, .06); }
.in:focus { background: var(--accent-soft); border-bottom-color: var(--accent); }
.in.text { direction: rtl; text-align: start; padding: 0 10px; font-weight: 500; }
.in.bad { border-bottom-color: var(--neg); background: var(--neg-soft); }
.yrow { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.yrow + .yrow, .frow + .yrow, .yrow + .frow { border-top: 1px solid var(--line-soft); padding-top: 12px; }
.ycells { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.ycell { display: flex; flex-direction: column; align-items: stretch; gap: 1px; }
.ycell span { text-align: center; font-size: 11px; color: var(--muted); }
.ycells.out .ycell b { display: block; text-align: center; padding: 8px 2px; font-size: 14px; font-weight: 600; border-radius: 8px; background: var(--panel-2); overflow: hidden; text-overflow: ellipsis; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.toggle.on { border-color: rgba(201, 165, 78, .5); background: linear-gradient(90deg, transparent, rgba(201, 165, 78, .07)), var(--panel); }
.toggle b { display: block; font-size: 16px; font-weight: 600; }
.toggle small { display: block; color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: #2a2a2a; transition: background .2s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: #9a9a9a; transition: transform .2s, background .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(-22px); background: #141006; }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); }
.seg button { min-height: 44px; border: 0; border-radius: 10px; background: none; color: var(--muted); cursor: pointer; font-size: 14.5px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #141006; font-weight: 600; }

/* صفوف قابلة للإضافة والحذف */
.rows { display: flex; flex-direction: column; gap: 10px; }
.rowcard { padding: 12px; border-radius: 13px; background: var(--panel-2); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.rowhead { display: flex; align-items: center; gap: 6px; }
.rowhead .in.text { flex: 1; }
.rowcols { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.rowcols label { display: flex; flex-direction: column; gap: 2px; font-size: 11.5px; color: var(--muted); text-align: center; }
.rowsub { font-size: 12px; color: var(--muted); margin-bottom: -4px; }
.addrow { border-style: dashed; color: var(--accent); background: transparent; }
.addrow:hover { background: var(--accent-soft); border-color: var(--accent-line); }
.sumline { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; background: var(--panel-2); font-size: 14px; }
.sumline b { font-weight: 600; }

/* نتائج القسم */
.results { background: linear-gradient(180deg, rgba(201, 165, 78, .05), transparent 70%), var(--panel); border: 1px solid rgba(201, 165, 78, .22); border-radius: var(--radius); padding: 14px 16px 16px; }
.results h3 { color: var(--accent); font-size: 14px; font-weight: 600; margin-bottom: 8px; }

/* بطاقات المؤشرات */
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kcard { padding: 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); min-width: 0; }
.kcard span { display: block; color: var(--muted); font-size: 12.5px; }
.kcard b { display: block; font-size: 21px; font-weight: 600; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; }
.kcard small { display: block; color: var(--muted); font-size: 12px; }
.kcard.hero { grid-column: 1 / -1; background: radial-gradient(100% 140% at 100% 0%, rgba(201, 165, 78, .14), transparent 60%), var(--panel); border-color: rgba(201, 165, 78, .35); }
.kcard.hero b { font-size: 30px; color: var(--accent); }

/* الجداول */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); overscroll-behavior-x: contain; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.tbl thead th { position: sticky; top: 0; background: #161616; color: var(--muted); font-weight: 500; font-size: 12.5px; text-align: left; z-index: 1; }
.tbl td { text-align: left; font-variant-numeric: tabular-nums; }
.tbl th:first-child, .tbl td:first-child { position: sticky; right: 0; text-align: right; background: var(--panel); z-index: 2; box-shadow: -1px 0 0 var(--line-soft); }
.tbl thead th:first-child { background: #161616; z-index: 3; }
.tbl tr.sect td { background: #151515; color: var(--accent); font-weight: 600; font-size: 13px; padding-top: 12px; }
.tbl tr.sect td:first-child { background: #151515; }
.tbl tr.total td { font-weight: 600; background: #171717; }
.tbl tr.total td:first-child { background: #171717; }
.tbl tr.hl td { background: #1c1913; }
.tbl tr.hl td:first-child { background: #1c1913; }
.tbl tr.big td { font-size: 15px; font-weight: 700; }
.tbl tr.yr td { border-top: 1px solid #333; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .sub { display: block; font-size: 11.5px; font-weight: 500; }
.tbl td.lbl small { display: block; color: var(--muted); font-size: 11.5px; }
.tbl-monthly td, .tbl-monthly th { padding: 7px 10px; font-size: 13px; }
.tbl-monthly tr.be td { background: rgba(124, 196, 154, .1); }
.tbl-monthly tr.be td:first-child { background: #142019; }

/* الرسم البياني */
.chart { position: relative; width: 100%; user-select: none; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: #1d1d1d; stroke-width: 1; }
.chart .zero { stroke: #4a4a4a; stroke-width: 1; stroke-dasharray: 3 3; }
.chart .ytick, .chart .xtick { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .yearsep { stroke: #222; }
.chart .line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { stroke: none; }
.chart .c0 { stroke: var(--s1); } .chart .c1 { stroke: var(--s2); } .chart .c2 { stroke: var(--s3); } .chart .c3 { stroke: var(--s4); }
.chart .dot { stroke: var(--bg); stroke-width: 2; }
.chart .d0 { fill: var(--s1); } .chart .d1 { fill: var(--s2); } .chart .d2 { fill: var(--s3); } .chart .d3 { fill: var(--s4); }
.chart .cursor { stroke: #555; stroke-width: 1; }
.chart .marker { fill: var(--pos); }
.chart .marker-neg { fill: var(--neg); }
.chart .gstop0 { stop-color: var(--accent); stop-opacity: .28; }
.chart .gstop1 { stop-color: var(--accent); stop-opacity: 0; }
.tip { position: absolute; top: 0; pointer-events: none; min-width: 150px; padding: 9px 12px; border-radius: 12px; background: rgba(22, 22, 22, .96); border: 1px solid #333; font-size: 12.5px; box-shadow: 0 10px 30px rgba(0, 0, 0, .6); transform: translateX(-50%); }
.tip b { display: block; font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 3px; }
.tip div { display: flex; justify-content: space-between; gap: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; }
.legend .l0 { background: var(--s1); } .legend .l1 { background: var(--s2); } .legend .l2 { background: var(--s3); } .legend .l3 { background: var(--s4); }

/* المقارنة */
.picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.picker label { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 14px; }
.picker label.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.picker input { position: absolute; opacity: 0; pointer-events: none; }
.picker .dotc { width: 10px; height: 10px; border-radius: 50%; background: #333; }
.picker label.on .dotc.l0 { background: var(--s1); } .picker label.on .dotc.l1 { background: var(--s2); } .picker label.on .dotc.l2 { background: var(--s3); } .picker label.on .dotc.l3 { background: var(--s4); }
.cmp-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.cmp-card { padding: 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--s1); }
.cmp-card.k1 { border-top-color: var(--s2); } .cmp-card.k2 { border-top-color: var(--s3); } .cmp-card.k3 { border-top-color: var(--s4); }
.cmp-card h3 { font-size: 15px; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.cmp-card dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 0; font-size: 13.5px; }
.cmp-card dt { color: var(--muted); }
.cmp-card dd { margin: 0; font-weight: 600; text-align: left; }
.cmp-card dd .sub { display: block; font-size: 11.5px; font-weight: 500; }
.th-s { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-weight: 600; }
.th-s i { width: 9px; height: 9px; border-radius: 50%; }
.th-s .l0 { background: var(--s1); } .th-s .l1 { background: var(--s2); } .th-s .l2 { background: var(--s3); } .th-s .l3 { background: var(--s4); }

/* سجل النسخ */
.vlist { display: flex; flex-direction: column; gap: 8px; }
.vitem { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 13px; background: var(--panel-2); border: 1px solid var(--line); }
.vitem div { flex: 1; min-width: 0; }
.vitem b { display: block; font-weight: 600; font-size: 14.5px; }
.vitem small { color: var(--muted); font-size: 12.5px; }

.actions-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.actions-grid .btn { justify-content: flex-start; min-height: 58px; padding: 0 16px; }
.actions-grid .btn span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.35; }
.actions-grid .btn small { color: var(--muted); font-size: 12px; font-weight: 400; }

/* التثبيت */
.install-hero { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.install-hero img { border-radius: 16px; flex: none; }
.install-hero > div { display: flex; flex-direction: column; gap: 8px; }
.done { display: flex; align-items: center; gap: 8px; color: var(--pos); font-weight: 600; }
.guides { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.guide.dim { opacity: .62; }
.guide .hint { margin: -6px 0 10px; }
.steps { margin: 0; padding-inline-start: 22px; display: flex; flex-direction: column; gap: 8px; }
.steps li::marker { color: var(--accent); font-weight: 600; }

/* نوافذ الحوار */
.dlg {
  width: min(460px, calc(100vw - 24px)); max-height: 86vh; padding: 0; border: 1px solid var(--line); border-radius: 20px;
  background: var(--panel); color: var(--text); box-shadow: 0 30px 90px rgba(0, 0, 0, .8);
}
.dlg::backdrop { background: rgba(0, 0, 0, .72); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.dlg form { display: flex; flex-direction: column; gap: 14px; padding: 22px 20px 18px; }
.dlg h2 { font-size: 18px; }
.dlg p { color: var(--muted); font-size: 14.5px; }
.dlg .dlg-actions { display: flex; flex-direction: row-reverse; gap: 8px; margin-top: 4px; }
.dlg .dlg-actions .btn { flex: 1; }
.dlg .menu { display: flex; flex-direction: column; gap: 4px; }
.dlg .menu button { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 12px; border: 0; border-radius: 12px; background: none; cursor: pointer; text-align: start; font-size: 15px; }
.dlg .menu button:hover { background: var(--panel-2); }
.dlg .menu button.danger { color: var(--neg); }
.dlg .menu .ic { color: var(--muted); }
.dlg .menu button.danger .ic { color: var(--neg); }

.toast {
  position: fixed; z-index: 100; inset-inline: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); max-width: 420px; margin: 0 auto;
  padding: 12px 16px; border-radius: 14px; background: #1f1f1f; border: 1px solid #333; text-align: center; font-size: 14.5px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .7); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { border-color: rgba(226, 120, 106, .5); color: var(--neg); }
.printhead { display: none; }

/* ── الشاشات الكبيرة ── */
@media (min-width: 600px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kcard.hero { grid-column: span 1; }
  .kcard.hero b { font-size: 26px; }
}
@media (min-width: 960px) {
  :root { --nav-h: 0px; }
  .shell { padding-inline: 28px; }
  .appbar, .resultsbar { margin: 0 -28px; padding-inline: 28px; }
  .topnav { display: flex; }
  .bottomnav { display: none; }
  .comparebar { bottom: 24px; }
  .toast { bottom: 24px; }
  .page { padding-top: 30px; }
  h1 { font-size: 28px; }
  .resultsbar { display: grid; grid-template-columns: minmax(220px, 1fr) auto auto; align-items: center; gap: 18px; padding-top: calc(10px + var(--safe-t)); padding-bottom: 12px; }
  .rb-kpis { margin: 0; grid-template-columns: repeat(3, auto); }
  .kpi { padding: 6px 14px; }
  .kpi b { font-size: 18px; }
  .rb-years { margin: 0; grid-template-columns: repeat(5, 82px); }
  .rb-years div { padding: 6px 4px; }
  .rb-years b { font-size: 13.5px; }
  .editor-body { display: grid; grid-template-columns: 236px minmax(0, 1fr); gap: 28px; align-items: start; }
  .sidenav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 92px; padding: 18px 0; max-height: calc(100vh - 100px); overflow-y: auto; }
  .sidenav h4 { margin: 14px 12px 4px; font-size: 12px; font-weight: 500; color: var(--muted); display: flex; align-items: center; gap: 7px; }
  .sidenav h4:first-child { margin-top: 0; }
  .sidenav button { display: flex; align-items: center; min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; background: none; color: #bdbdbd; cursor: pointer; text-align: start; font-size: 14.5px; }
  .sidenav button:hover { background: var(--panel); color: var(--text); }
  .sidenav button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset -2.5px 0 0 var(--accent); }
  .sidenav .dot { margin-inline-start: auto; width: 7px; height: 7px; border-radius: 50%; background: var(--pos); }
  .chips { display: none; }
  .editor-main { padding-top: 26px; }
  .sec-body { padding: 2px 20px 20px; }
  .sec > summary { padding: 14px 20px; }
  .frow { grid-template-columns: 1fr 200px; }
  .yrow { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(0, 470px); align-items: center; gap: 16px; }
  .ycell span { display: none; }
  .ycells.with-head .ycell span { display: block; }
  .yhead { display: grid !important; }
  .rowcard { padding: 14px 16px; }
}
.yhead { display: none; grid-template-columns: minmax(180px, 1fr) minmax(0, 470px); gap: 16px; margin-bottom: -6px; }
.yhead div { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.yhead span { text-align: center; color: var(--muted); font-size: 12px; }

@media (max-width: 380px) {
  .in { font-size: 15px; }
  .kpi b { font-size: 15px; }
  .rb-years b { font-size: 11.5px; }
  .frow { grid-template-columns: 1fr 120px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ── الطباعة / PDF ── */
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  :root { --bg: #fff; --panel: #fff; --panel-2: #f6f6f6; --line: #ddd; --line-soft: #eee; --text: #111; --muted: #666; --accent: #8a6a1c; --pos: #1f7a46; --neg: #b23a2b; --accent-soft: #f6efdd; }
  body { background: #fff; color: #111; font-size: 11.5px; }
  .appbar, .bottomnav, .sidenav, .chips, .resultsbar, .toast, .no-print, .comparebar, button, .btn { display: none !important; }
  .shell { padding: 0; max-width: none; }
  .editor-body { display: block; }
  .editor-main { padding: 0; }
  .printhead { display: block; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid #8a6a1c; }
  .printhead h1 { font-size: 20px; }
  .printhead p { color: #666; }
  .card, .sec, .kcard, .tbl-wrap, .results { break-inside: avoid; border-color: #ddd; background: #fff !important; box-shadow: none; }
  .tbl-wrap { overflow: visible; }
  .tbl th, .tbl td { padding: 4px 6px; font-size: 10.5px; }
  .tbl thead th, .tbl tr.sect td, .tbl tr.total td, .tbl th:first-child, .tbl td:first-child, .tbl tr.hl td { background: #fff !important; position: static; box-shadow: none; }
  .tbl tr.sect td { color: #8a6a1c; border-top: 1px solid #ccc; }
  .kcard.hero b { color: #8a6a1c; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .chart .grid line { stroke: #eee; }
  .chart .zero { stroke: #999; }
  .chart .ytick, .chart .xtick { fill: #666; }
}
