/* ============================================================
   مُنجِز — نظام التصميم
   ============================================================ */

:root{
  --font-ar: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-en: "Inter", "Segoe UI", system-ui, sans-serif;

  --r-xs: 6px;  --r-sm: 9px;  --r-md: 13px;  --r-lg: 18px;  --r-xl: 26px;
  --sp: 4px;
  --dur: .18s;
  --ease: cubic-bezier(.32,.72,0,1);

  --sidebar-w: 268px;
  --drawer-w: 460px;
}

/* ---------- الوضع الفاتح ---------- */
html[data-theme="light"]{
  --bg:        #F4F1EC;
  --bg-grain:  #EFEBE4;
  --surface:   #FFFFFF;
  --surface-2: #FAF8F5;
  --surface-3: #F1EDE6;
  --ink:       #16181D;
  --ink-2:     #4A4E58;
  --ink-3:     #83889433;
  --muted:     #7C8189;
  --line:      #E4DED4;
  --line-2:    #EFEAE2;

  --accent:    #A6793C;
  --accent-2:  #C29A5B;
  --accent-ink:#FFFFFF;
  --accent-sf: #F6EEE1;

  --ok:      #1E7A5A;
  --ok-sf:   #E4F2EC;
  --warn:    #B4761B;
  --warn-sf: #FBF0DE;
  --danger:  #B3352F;
  --danger-sf:#FBE9E7;
  --info:    #2C5F8A;
  --info-sf: #E7F0F8;

  --shadow-1: 0 1px 2px rgba(24,20,14,.05), 0 1px 3px rgba(24,20,14,.04);
  --shadow-2: 0 2px 4px rgba(24,20,14,.04), 0 8px 20px -6px rgba(24,20,14,.10);
  --shadow-3: 0 12px 32px -8px rgba(24,20,14,.18), 0 40px 80px -32px rgba(24,20,14,.24);
}

/* ---------- الوضع الداكن ---------- */
html[data-theme="dark"]{
  --bg:        #0C0D10;
  --bg-grain:  #101216;
  --surface:   #16181D;
  --surface-2: #1B1E24;
  --surface-3: #21252C;
  --ink:       #ECE9E4;
  --ink-2:     #A8ADB8;
  --ink-3:     #6E747F33;
  --muted:     #858B96;
  --line:      #262A32;
  --line-2:    #1E222A;

  --accent:    #D2A75F;
  --accent-2:  #E0BC81;
  --accent-ink:#1A1509;
  --accent-sf: #2A2317;

  --ok:      #4CB58C;
  --ok-sf:   #16281F;
  --warn:    #D6A45C;
  --warn-sf: #2A2113;
  --danger:  #E4736B;
  --danger-sf:#2E1917;
  --info:    #6FA8D8;
  --info-sf: #14202B;

  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 2px 6px rgba(0,0,0,.35), 0 10px 24px -8px rgba(0,0,0,.5);
  --shadow-3: 0 16px 40px -10px rgba(0,0,0,.6), 0 48px 90px -36px rgba(0,0,0,.7);
}

/* ============================================================ */

*,*::before,*::after{ box-sizing:border-box; }

html,body{ height:100%; }

body{
  margin:0;
  font-family:var(--font-ar);
  background:var(--bg);
  color:var(--ink);
  font-size:14.5px;
  line-height:1.6;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  overflow:hidden;
  overscroll-behavior:none;
  -webkit-tap-highlight-color:transparent;
}

html[lang="en"] body{ font-family:var(--font-en); font-size:14px; }

body::before{
  content:"";
  position:fixed; inset:0; z-index:0; pointer-events:none;
  background:
    radial-gradient(1100px 620px at 85% -10%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 62%),
    radial-gradient(900px 520px at 5% 105%, color-mix(in srgb, var(--info) 7%, transparent), transparent 60%);
}

svg{ width:100%; height:100%; fill:none; stroke:currentColor; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }

button{ font:inherit; color:inherit; }

::selection{ background:color-mix(in srgb, var(--accent) 28%, transparent); }

/* شريط التمرير */
*::-webkit-scrollbar{ width:10px; height:10px; }
*::-webkit-scrollbar-track{ background:transparent; }
*::-webkit-scrollbar-thumb{ background:var(--ink-3); border-radius:99px; border:3px solid transparent; background-clip:content-box; }
*::-webkit-scrollbar-thumb:hover{ background:color-mix(in srgb, var(--muted) 55%, transparent); background-clip:content-box; border:3px solid transparent; }

/* ============================================================
   الهيكل
   ============================================================ */

.app{
  position:relative; z-index:1;
  display:grid;
  grid-template-columns:var(--sidebar-w) 1fr;
  height:100vh;
  height:100dvh;
}

/* ---------- الشريط الجانبي ---------- */
.sidebar{
  display:flex; flex-direction:column;
  background:color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter:blur(20px) saturate(1.3);
  border-inline-end:1px solid var(--line);
  overflow:hidden;
}

.brand{
  display:flex; align-items:center; gap:12px;
  padding:22px 20px 18px;
}
.brand-mark{
  width:38px; height:38px; flex:none;
  display:grid; place-items:center;
  border-radius:11px;
  background:linear-gradient(145deg, var(--accent-2), var(--accent));
  color:var(--accent-ink);
  box-shadow:0 4px 12px -4px color-mix(in srgb, var(--accent) 60%, transparent);
}
.brand-mark svg{ width:20px; height:20px; stroke-width:2.6; }
.brand-text{ display:flex; flex-direction:column; line-height:1.25; min-width:0; }
.brand-name{ font-weight:700; font-size:16px; letter-spacing:-.01em; }
.brand-sub{ font-size:11.5px; color:var(--muted); font-weight:400; }

.nav{ flex:1; overflow-y:auto; padding:0 12px 16px; }

.nav-label{
  display:flex; align-items:center; justify-content:space-between;
  padding:0 10px 8px;
  font-size:11px; font-weight:600; letter-spacing:.06em;
  color:var(--muted); text-transform:uppercase;
}
.nav-label--spaced{ margin-top:22px; }
.nav-label-btn{
  border:none; background:none; cursor:pointer; color:var(--muted);
  font-size:16px; line-height:1; padding:2px 6px; border-radius:6px;
  transition:var(--dur);
}
.nav-label-btn:hover{ background:var(--surface-3); color:var(--accent); }

.nav-item{
  width:100%;
  display:flex; align-items:center; gap:11px;
  padding:8px 10px; margin-bottom:2px;
  border:none; background:none; cursor:pointer;
  border-radius:var(--r-sm);
  text-align:start;
  color:var(--ink-2);
  font-size:13.6px; font-weight:500;
  transition:background var(--dur), color var(--dur);
  position:relative;
}
.nav-item:hover{ background:var(--surface-3); color:var(--ink); }
.nav-item.is-active{
  background:var(--surface);
  color:var(--ink);
  font-weight:600;
  box-shadow:var(--shadow-1);
}
.nav-item.is-active::before{
  content:""; position:absolute; inset-inline-start:0; top:50%;
  transform:translateY(-50%);
  width:3px; height:17px; border-radius:99px; background:var(--accent);
}
.nav-ico{ width:17px; height:17px; flex:none; color:var(--muted); }
.nav-item.is-active .nav-ico{ color:var(--accent); }
.nav-txt{ flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.nav-count{
  font-size:11.5px; font-weight:600; color:var(--muted);
  background:var(--surface-3); padding:1px 7px; border-radius:99px;
  min-width:22px; text-align:center;
  font-variant-numeric:tabular-nums;
}
.nav-item.is-active .nav-count{ background:var(--accent-sf); color:var(--accent); }
.nav-count.is-danger[data-hot="1"]{ background:var(--danger-sf); color:var(--danger); }
.nav-count:empty, .nav-count[data-zero="1"]{ opacity:.45; }

.proj-item .nav-ico{ display:grid; place-items:center; }
.proj-dot{ width:8px; height:8px; border-radius:99px; background:var(--accent); display:block; }

.tag-cloud{ display:flex; flex-wrap:wrap; gap:6px; padding:2px 10px; }
.tag-pill{
  border:1px solid var(--line); background:var(--surface-2);
  color:var(--ink-2); font-size:11.5px; font-weight:500;
  padding:3px 9px; border-radius:99px; cursor:pointer;
  transition:var(--dur);
}
.tag-pill:hover{ border-color:var(--accent); color:var(--accent); }
.tag-pill.is-active{ background:var(--accent); border-color:var(--accent); color:var(--accent-ink); }

/* قدم الشريط */
.sidebar-foot{ padding:12px; border-top:1px solid var(--line); }

.sync-card{
  width:100%; display:flex; align-items:center; gap:10px;
  padding:10px 11px; margin-bottom:8px;
  border:1px solid var(--line); border-radius:var(--r-md);
  background:var(--surface-2); cursor:pointer; text-align:start;
  transition:var(--dur);
}
.sync-card:hover{ border-color:var(--accent); background:var(--surface); }
.sync-dot{
  width:8px; height:8px; border-radius:99px; flex:none;
  background:var(--muted); box-shadow:0 0 0 3px color-mix(in srgb, var(--muted) 18%, transparent);
}
.sync-dot[data-state="on"]{ background:var(--ok); box-shadow:0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.sync-dot[data-state="busy"]{ background:var(--warn); box-shadow:0 0 0 3px color-mix(in srgb, var(--warn) 20%, transparent); animation:pulse 1.2s infinite; }
.sync-dot[data-state="err"]{ background:var(--danger); box-shadow:0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent); }
@keyframes pulse{ 50%{ opacity:.35; } }

.sync-body{ display:flex; flex-direction:column; min-width:0; line-height:1.35; }
.sync-title{ font-size:12.5px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sync-sub{ font-size:11px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.foot-actions{ display:flex; gap:6px; }

/* ---------- المنطقة الرئيسية ---------- */
.main{ display:flex; flex-direction:column; min-width:0; overflow:hidden; }

.topbar{
  display:flex; align-items:center; gap:16px;
  padding:20px 28px 14px;
  flex:none;
}
.page-head{ min-width:0; flex:1; }
.page-title{
  margin:0; font-size:24px; font-weight:700; letter-spacing:-.02em;
  line-height:1.25;
}
.page-sub{ margin:1px 0 0; font-size:12.5px; color:var(--muted); }

.topbar-tools{ display:flex; align-items:center; gap:9px; flex:none; }

.search{
  display:flex; align-items:center; gap:8px;
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--r-sm); padding:0 11px; height:38px; width:230px;
  transition:var(--dur);
}
.search:focus-within{ border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-sf); }
.search svg{ width:15px; height:15px; color:var(--muted); flex:none; }
.search input{
  flex:1; min-width:0; border:none; background:none; outline:none;
  font:inherit; font-size:13.5px; color:var(--ink);
}
.search input::-webkit-search-cancel-button{ appearance:none; }

/* ---------- عناصر التحكم ---------- */
.input, .select{
  width:100%; height:38px;
  padding:0 12px;
  border:1px solid var(--line); border-radius:var(--r-sm);
  background:var(--surface); color:var(--ink);
  font:inherit; font-size:13.5px; outline:none;
  transition:var(--dur);
}
textarea.input{ height:auto; padding:10px 12px; resize:vertical; line-height:1.6; }
.input:hover, .select:hover{ border-color:color-mix(in srgb, var(--accent) 45%, var(--line)); }
.input:focus, .select:focus{ border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-sf); }
.input::placeholder{ color:var(--muted); opacity:.75; }
.input-lg{ height:44px; font-size:15.5px; font-weight:600; }
.mono{ font-family:ui-monospace, "Cascadia Code", Consolas, monospace; font-size:12.5px; }

.select{
  appearance:none; cursor:pointer;
  padding-inline-end:32px;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-size:15px;
  background-position:left 11px center;
}
html[dir="ltr"] .select{ background-position:right 11px center; }
.select-wrap .select{ width:auto; min-width:132px; }

input[type="date"], input[type="time"]{ font-variant-numeric:tabular-nums; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator{ cursor:pointer; opacity:.55; }
html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator{ filter:invert(1); opacity:.6; }

.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  height:38px; padding:0 16px;
  border:1px solid transparent; border-radius:var(--r-sm);
  font:inherit; font-size:13.5px; font-weight:600;
  cursor:pointer; white-space:nowrap;
  transition:transform var(--dur), background var(--dur), border-color var(--dur), box-shadow var(--dur);
}
.btn svg{ width:16px; height:16px; stroke-width:2.1; }
.btn:active{ transform:scale(.975); }

.btn-primary{
  background:linear-gradient(180deg, var(--accent-2), var(--accent));
  color:var(--accent-ink);
  box-shadow:0 1px 2px rgba(0,0,0,.12), 0 6px 16px -8px color-mix(in srgb, var(--accent) 75%, transparent);
}
.btn-primary:hover{ filter:brightness(1.06); }

.btn-ghost{
  background:var(--surface); border-color:var(--line); color:var(--ink-2);
}
.btn-ghost:hover{ border-color:var(--accent); color:var(--accent); background:var(--surface); }
.btn-danger{ color:var(--danger); }
.btn-danger:hover{ border-color:var(--danger); color:var(--danger); background:var(--danger-sf); }

.icon-btn{
  width:34px; height:34px; flex:none;
  display:grid; place-items:center;
  border:1px solid transparent; border-radius:var(--r-sm);
  background:none; cursor:pointer; color:var(--muted);
  transition:var(--dur);
}
.icon-btn svg{ width:16.5px; height:16.5px; }
.icon-btn:hover{ background:var(--surface-3); color:var(--ink); }
.icon-btn--text{ font-size:11.5px; font-weight:700; letter-spacing:.04em; }

.link-btn{
  border:none; background:none; cursor:pointer;
  color:var(--accent); font:inherit; font-size:12.5px; font-weight:600;
  padding:2px 4px; border-radius:5px;
}
.link-btn:hover{ text-decoration:underline; }

.chip-btn{
  border:1px solid var(--line); background:var(--surface-2);
  color:var(--ink-2); font:inherit; font-size:12.5px; font-weight:500;
  padding:5px 12px; border-radius:99px; cursor:pointer;
  transition:var(--dur);
}
.chip-btn:hover{ border-color:var(--accent); color:var(--accent); }

.seg{
  display:grid; grid-template-columns:repeat(4,1fr); gap:3px;
  padding:3px; border-radius:var(--r-sm);
  background:var(--surface-3); border:1px solid var(--line);
}
.seg-item{
  border:none; background:none; cursor:pointer;
  padding:6px 4px; border-radius:calc(var(--r-sm) - 3px);
  font-size:12.5px; font-weight:500; color:var(--ink-2);
  transition:var(--dur);
}
.seg-item:hover{ color:var(--ink); }
.seg-item.is-active{ background:var(--surface); color:var(--ink); font-weight:600; box-shadow:var(--shadow-1); }
.seg-item[data-value="high"].is-active{ color:var(--warn); }
.seg-item[data-value="urgent"].is-active{ color:var(--danger); }

.switch{
  display:flex; align-items:flex-start; gap:11px; cursor:pointer;
  padding:11px 12px; border:1px solid var(--line); border-radius:var(--r-md);
  background:var(--surface-2); margin-bottom:9px;
  transition:var(--dur);
}
.switch:hover{ border-color:color-mix(in srgb, var(--accent) 40%, var(--line)); }
.switch input{ position:absolute; opacity:0; pointer-events:none; }
.switch-track{
  width:36px; height:21px; flex:none; margin-top:1px;
  border-radius:99px; background:var(--surface-3);
  border:1px solid var(--line);
  position:relative; transition:var(--dur);
}
.switch-thumb{
  position:absolute; top:2px; inset-inline-start:2px;
  width:15px; height:15px; border-radius:99px;
  background:var(--muted);
  transition:transform var(--dur) var(--ease), background var(--dur);
}
.switch input:checked + .switch-track{ background:var(--accent); border-color:var(--accent); }
.switch input:checked + .switch-track .switch-thumb{ background:#fff; transform:translateX(-15px); }
html[dir="ltr"] .switch input:checked + .switch-track .switch-thumb{ transform:translateX(15px); }
.switch-label{ display:flex; flex-direction:column; line-height:1.4; }
.switch-label strong{ font-size:13.5px; font-weight:600; }
.switch-label small{ font-size:11.8px; color:var(--muted); }

/* ============================================================
   البطاقات الإحصائية
   ============================================================ */
.stats{
  display:grid; grid-template-columns:repeat(4,1fr); gap:12px;
  padding:0 28px 16px; flex:none;
}
.stat{
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--r-md); padding:13px 15px;
  display:flex; flex-direction:column; gap:2px;
  box-shadow:var(--shadow-1);
  position:relative; overflow:hidden;
}
.stat::after{
  content:""; position:absolute; inset-inline-start:0; top:0; bottom:0; width:3px;
  background:var(--tone, var(--accent)); opacity:.85;
}
.stat-val{ font-size:23px; font-weight:700; line-height:1.15; letter-spacing:-.02em; font-variant-numeric:tabular-nums; }
.stat-lbl{ font-size:11.8px; color:var(--muted); font-weight:500; }
.stat-bar{ height:3px; border-radius:99px; background:var(--surface-3); margin-top:7px; overflow:hidden; }
.stat-bar span{ display:block; height:100%; border-radius:99px; background:var(--tone, var(--accent)); transition:width .5s var(--ease); }

/* ============================================================
   قائمة المهام
   ============================================================ */
.content{ flex:1; overflow-y:auto; padding:4px 28px 90px; }

.group{ margin-bottom:26px; }
.group-head{
  display:flex; align-items:center; gap:10px;
  padding:0 2px 9px;
  position:sticky; top:0; z-index:2;
  background:linear-gradient(var(--bg) 62%, transparent);
  backdrop-filter:blur(4px);
}
.group-title{ font-size:12.5px; font-weight:700; letter-spacing:.02em; color:var(--ink-2); }
.group-title[data-tone="danger"]{ color:var(--danger); }
.group-title[data-tone="accent"]{ color:var(--accent); }
.group-line{ flex:1; height:1px; background:var(--line); }
.group-n{ font-size:11.5px; color:var(--muted); font-variant-numeric:tabular-nums; }

.task{
  display:flex; align-items:flex-start; gap:12px;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--r-md);
  padding:12px 14px;
  margin-bottom:8px;
  cursor:pointer;
  box-shadow:var(--shadow-1);
  transition:border-color var(--dur), box-shadow var(--dur), transform var(--dur), opacity var(--dur);
  position:relative; overflow:hidden;
  animation:rise .32s var(--ease) both;
}
@keyframes rise{ from{ opacity:0; transform:translateY(6px); } }
.task:hover{
  border-color:color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow:var(--shadow-2);
  transform:translateY(-1px);
}
.task::before{
  content:""; position:absolute; inset-inline-start:0; top:0; bottom:0;
  width:3px; background:var(--tone); opacity:0; transition:opacity var(--dur);
}
.task[data-pri="high"], .task[data-pri="urgent"]{ }
.task[data-pri="high"]::before{ --tone:var(--warn); opacity:1; }
.task[data-pri="urgent"]::before{ --tone:var(--danger); opacity:1; }
.task[data-overdue="1"]::before{ --tone:var(--danger); opacity:1; }
.task.is-done{ opacity:.5; }
.task.is-done .task-title{ text-decoration:line-through; text-decoration-thickness:1px; color:var(--muted); }
.task.is-removing{ opacity:0; transform:translateY(-4px) scale(.985); }

.check{
  width:20px; height:20px; flex:none; margin-top:1px;
  border:1.7px solid var(--line); border-radius:7px;
  background:var(--surface-2); cursor:pointer;
  display:grid; place-items:center;
  color:transparent;
  transition:var(--dur);
}
.check svg{ width:12px; height:12px; stroke-width:3; }
.check:hover{ border-color:var(--accent); background:var(--accent-sf); }
.task.is-done .check{ background:var(--ok); border-color:var(--ok); color:#fff; }

.task-main{ flex:1; min-width:0; }
.task-title{
  font-size:14.2px; font-weight:600; line-height:1.45;
  word-break:break-word;
}
.task-notes{
  font-size:12.5px; color:var(--muted); margin-top:2px;
  display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden;
}
.task-meta{ display:flex; flex-wrap:wrap; align-items:center; gap:6px; margin-top:7px; }

.meta{
  display:inline-flex; align-items:center; gap:4px;
  font-size:11.5px; font-weight:500;
  padding:2px 8px; border-radius:99px;
  background:var(--surface-3); color:var(--ink-2);
  white-space:nowrap;
}
.meta svg{ width:12px; height:12px; stroke-width:2; }
.meta[data-tone="danger"]{ background:var(--danger-sf); color:var(--danger); }
.meta[data-tone="warn"]{ background:var(--warn-sf); color:var(--warn); }
.meta[data-tone="ok"]{ background:var(--ok-sf); color:var(--ok); }
.meta[data-tone="accent"]{ background:var(--accent-sf); color:var(--accent); }
.meta[data-tone="info"]{ background:var(--info-sf); color:var(--info); }

.task-side{ display:flex; align-items:center; gap:4px; flex:none; opacity:0; transition:var(--dur); }
.task:hover .task-side, .task:focus-within .task-side{ opacity:1; }
.task-side .icon-btn{ width:28px; height:28px; }
.task-side .icon-btn svg{ width:14px; height:14px; }

.progress-mini{
  height:3px; border-radius:99px; background:var(--surface-3);
  margin-top:8px; overflow:hidden; max-width:220px;
}
.progress-mini span{ display:block; height:100%; background:var(--accent); border-radius:99px; transition:width .35s var(--ease); }

/* حالة فارغة */
.empty{
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  padding:70px 20px; text-align:center; gap:6px;
  animation:rise .4s var(--ease) both;
}
.empty-art{
  width:64px; height:64px; margin-bottom:8px;
  display:grid; place-items:center; border-radius:20px;
  background:var(--surface); border:1px solid var(--line);
  color:var(--accent); box-shadow:var(--shadow-1);
}
.empty-art svg{ width:28px; height:28px; stroke-width:1.5; }
.empty h3{ margin:0; font-size:16px; font-weight:650; }
.empty p{ margin:0; font-size:13px; color:var(--muted); max-width:340px; }
.empty .btn{ margin-top:12px; }

/* ============================================================
   اللوح الجانبي (المحرر)
   ============================================================ */
.scrim{
  position:fixed; inset:0; z-index:40;
  background:rgba(12,10,7,.42);
  backdrop-filter:blur(3px);
  opacity:0; pointer-events:none;
  transition:opacity .25s var(--ease);
}
.scrim.is-open{ opacity:1; pointer-events:auto; }

.drawer{
  position:fixed; top:0; bottom:0; inset-inline-end:0; z-index:50;
  width:min(var(--drawer-w), 100vw);
  display:flex; flex-direction:column;
  background:var(--surface);
  border-inline-start:1px solid var(--line);
  box-shadow:var(--shadow-3);
  transform:translateX(-102%);
  transition:transform .3s var(--ease);
  visibility:hidden;
}
html[dir="ltr"] .drawer{ transform:translateX(102%); }
.drawer.is-open{ transform:translateX(0); visibility:visible; }

.drawer-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:18px 20px 14px; border-bottom:1px solid var(--line-2); flex:none;
}
.drawer-head h2{ margin:0; font-size:17px; font-weight:700; letter-spacing:-.01em; }

.drawer-body{ flex:1; overflow-y:auto; padding:18px 20px; }

.drawer-foot{
  display:flex; align-items:center; gap:9px;
  padding:14px 20px; border-top:1px solid var(--line-2);
  background:var(--surface-2); flex:none;
}
.spacer{ flex:1; }

.field{ margin-bottom:15px; }
.lbl{
  display:block; margin-bottom:6px;
  font-size:12px; font-weight:600; color:var(--ink-2); letter-spacing:.01em;
}
.lbl-row{ display:flex; align-items:center; justify-content:space-between; }
.hint{ display:block; margin-top:5px; font-size:11.5px; color:var(--muted); line-height:1.5; }

.grid-2{ display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.quick-dates{ display:flex; flex-wrap:wrap; gap:6px; margin:-6px 0 15px; }

.checklist{ display:flex; flex-direction:column; gap:6px; }
.check-row{
  display:flex; align-items:center; gap:9px;
  background:var(--surface-2); border:1px solid var(--line);
  border-radius:var(--r-sm); padding:6px 10px;
}
.check-row .mini-check{
  width:17px; height:17px; flex:none;
  border:1.6px solid var(--line); border-radius:5px;
  background:var(--surface); cursor:pointer;
  display:grid; place-items:center; color:transparent;
}
.check-row .mini-check svg{ width:10px; height:10px; stroke-width:3.2; }
.check-row[data-done="1"] .mini-check{ background:var(--ok); border-color:var(--ok); color:#fff; }
.check-row[data-done="1"] input{ text-decoration:line-through; color:var(--muted); }
.check-row input{
  flex:1; min-width:0; border:none; background:none; outline:none;
  font:inherit; font-size:13px; color:var(--ink);
}
.check-row .icon-btn{ width:24px; height:24px; }
.check-row .icon-btn svg{ width:13px; height:13px; }

/* ============================================================
   النافذة المنبثقة
   ============================================================ */
.modal{
  position:fixed; inset:0; z-index:60;
  display:grid; place-items:center;
  padding:24px;
  background:rgba(12,10,7,.5); backdrop-filter:blur(4px);
  opacity:0; pointer-events:none;
  transition:opacity .22s var(--ease);
}
.modal.is-open{ opacity:1; pointer-events:auto; }

.modal-card{
  width:min(660px, 100%); max-height:min(86vh, 820px);
  display:flex; flex-direction:column;
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--r-xl); box-shadow:var(--shadow-3);
  overflow:hidden;
  transform:scale(.97) translateY(8px);
  transition:transform .25s var(--ease);
}
.modal.is-open .modal-card{ transform:none; }

.modal-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:18px 22px 14px;
}
.modal-head h2{ margin:0; font-size:18px; font-weight:700; letter-spacing:-.01em; }

.tabs{
  display:flex; gap:2px; padding:0 22px;
  border-bottom:1px solid var(--line); flex:none;
}
.tab{
  border:none; background:none; cursor:pointer;
  padding:9px 13px; font-size:13px; font-weight:600; color:var(--muted);
  border-bottom:2px solid transparent; margin-bottom:-1px;
  transition:var(--dur);
}
.tab:hover{ color:var(--ink); }
.tab.is-active{ color:var(--accent); border-bottom-color:var(--accent); }

.modal-body{ overflow-y:auto; padding:20px 22px 24px; }
.tab-panel{ display:none; animation:rise .25s var(--ease) both; }
.tab-panel.is-active{ display:block; }

.callout{
  background:var(--accent-sf); border:1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius:var(--r-md); padding:12px 14px; margin-bottom:16px;
}
.callout--soft{ background:var(--surface-2); border-color:var(--line); }
.callout strong{ display:block; font-size:13px; margin-bottom:3px; }
.callout p{ margin:0; font-size:12.6px; color:var(--ink-2); line-height:1.65; }

.sec-h{ font-size:13.5px; font-weight:700; margin:22px 0 8px; }
.muted{ color:var(--muted); font-size:12.6px; line-height:1.65; margin:0 0 10px; }

.steps{ margin:0 0 16px; padding-inline-start:20px; }
.steps li{ font-size:12.8px; color:var(--ink-2); line-height:1.75; margin-bottom:6px; }
.steps a{ color:var(--accent); font-weight:600; }
.steps code{
  display:inline-block; margin:4px 0 2px;
  background:var(--surface-3); border:1px solid var(--line);
  padding:3px 9px; border-radius:6px;
  font-family:ui-monospace, Consolas, monospace; font-size:12px;
  direction:ltr; unicode-bidi:embed;
}

.connect-row{ display:flex; flex-wrap:wrap; gap:9px; margin-top:6px; }
.account-line{ margin:12px 0 0; font-size:12.5px; color:var(--muted); }
.account-line strong{ color:var(--ink); }

.danger-zone{
  display:flex; align-items:center; justify-content:space-between; gap:14px;
  margin-top:22px; padding:13px 15px;
  border:1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  background:var(--danger-sf); border-radius:var(--r-md);
}
.danger-zone strong{ display:block; font-size:13px; }
.danger-zone small{ font-size:11.5px; color:var(--ink-2); }

/* ============================================================
   شاشة الدخول
   ============================================================ */
.gate{
  position:fixed; inset:0; z-index:90;
  display:grid; place-items:center;
  padding:24px;
  background:var(--bg);
}
.gate[hidden]{ display:none; }
.gate::before{
  content:""; position:absolute; inset:0; pointer-events:none;
  background:
    radial-gradient(900px 520px at 70% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 62%),
    radial-gradient(700px 420px at 10% 110%, color-mix(in srgb, var(--info) 10%, transparent), transparent 60%);
}
.gate-card{
  position:relative;
  width:min(380px, 100%);
  display:flex; flex-direction:column; align-items:center;
  gap:12px; text-align:center;
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--r-xl); padding:34px 28px 28px;
  box-shadow:var(--shadow-3);
  animation:rise .4s var(--ease) both;
}
.gate-mark{
  width:52px; height:52px; display:grid; place-items:center;
  border-radius:15px; margin-bottom:2px;
  background:linear-gradient(145deg, var(--accent-2), var(--accent));
  color:var(--accent-ink);
  box-shadow:0 6px 18px -6px color-mix(in srgb, var(--accent) 65%, transparent);
}
.gate-mark svg{ width:27px; height:27px; }
.gate-card h1{ margin:0; font-size:21px; font-weight:700; letter-spacing:-.02em; }
.gate-sub{ margin:0 0 6px; font-size:13px; color:var(--muted); }
.gate-card .input{ text-align:center; letter-spacing:.06em; }
.gate-btn{ width:100%; height:42px; }
.gate-error{
  margin:0; width:100%;
  font-size:12.5px; font-weight:500; color:var(--danger);
  background:var(--danger-sf); border-radius:var(--r-sm); padding:8px 10px;
}
.gate-error[hidden]{ display:none; }

/* ============================================================
   التنبيهات
   ============================================================ */
.toasts{
  position:fixed; bottom:22px; inset-inline-start:22px; z-index:80;
  display:flex; flex-direction:column; gap:8px;
  pointer-events:none;
}
.toast{
  display:flex; align-items:center; gap:10px;
  min-width:250px; max-width:380px;
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--r-md); padding:11px 14px;
  box-shadow:var(--shadow-2);
  font-size:13px; font-weight:500;
  pointer-events:auto;
  animation:toastIn .3s var(--ease) both;
}
.toast.is-out{ animation:toastOut .25s var(--ease) both; }
@keyframes toastIn{ from{ opacity:0; transform:translateY(10px) scale(.97); } }
@keyframes toastOut{ to{ opacity:0; transform:translateY(6px) scale(.98); } }
.toast-ico{ width:18px; height:18px; flex:none; }
.toast[data-kind="ok"] .toast-ico{ color:var(--ok); }
.toast[data-kind="err"] .toast-ico{ color:var(--danger); }
.toast[data-kind="info"] .toast-ico{ color:var(--info); }
.toast-x{ margin-inline-start:auto; }

/* ============================================================
   الاستجابة
   ============================================================ */
.only-mobile{ display:none; }

@media (max-width:1080px){
  .stats{ grid-template-columns:repeat(2,1fr); }
  .search{ width:170px; }
}

@media (max-width:860px){
  .app{ grid-template-columns:1fr; }
  .sidebar{
    position:fixed; top:0; bottom:0; inset-inline-start:0; z-index:55;
    width:min(var(--sidebar-w), 84vw);
    transform:translateX(102%);
    transition:transform .3s var(--ease);
    background:var(--surface);
    box-shadow:var(--shadow-3);
    padding-top:env(safe-area-inset-top);
    padding-bottom:env(safe-area-inset-bottom);
  }
  html[dir="ltr"] .sidebar{ transform:translateX(-102%); }
  .sidebar.is-open{ transform:translateX(0); }
  .only-mobile{ display:grid; }

  .topbar{
    flex-wrap:wrap; gap:10px;
    padding:calc(12px + env(safe-area-inset-top)) 16px 10px;
  }
  .page-head{ flex:1 1 auto; order:1; }
  .only-mobile{ order:0; }
  .topbar-tools{ order:2; width:100%; }
  .search{ flex:1; width:auto; height:42px; }
  .btn, .select{ height:42px; }
  .content{ padding:4px 16px calc(96px + env(safe-area-inset-bottom)); }
  .stats{ padding:0 16px 14px; }
  .page-title{ font-size:20px; }

  /* لا يوجد تمرير بالفأرة على اللمس — أظهر أزرار البطاقة دائمًا */
  .task-side{ opacity:1; }
  .task{ padding:14px; }
  .check{ width:24px; height:24px; }
  .task-side .icon-btn{ width:34px; height:34px; }

  /* منع تكبير الصفحة تلقائيًا عند التركيز على حقل في iOS */
  .input, .select, .search input, .check-row input{ font-size:16px; }
  .input-lg{ font-size:17px; }

  .drawer{
    width:100vw;
    border-inline-start:none;
    padding-top:env(safe-area-inset-top);
  }
  .drawer-foot{ padding-bottom:calc(14px + env(safe-area-inset-bottom)); }
  .drawer-body{ overscroll-behavior:contain; -webkit-overflow-scrolling:touch; }

  .modal{ padding:0; }
  .modal-card{
    width:100%; height:100dvh; max-height:100dvh;
    border-radius:0; border:none;
    padding-top:env(safe-area-inset-top);
  }
  .modal-body{ padding-bottom:calc(28px + env(safe-area-inset-bottom)); overscroll-behavior:contain; }
  .tabs{ overflow-x:auto; scrollbar-width:none; }
  .tabs::-webkit-scrollbar{ display:none; }
  .tab{ white-space:nowrap; }

  .toasts{
    inset-inline:16px; bottom:calc(16px + env(safe-area-inset-bottom));
    align-items:stretch;
  }
  .toast{ min-width:0; max-width:none; }
}

@media (max-width:560px){
  .stats{ grid-template-columns:1fr 1fr; gap:8px; }
  .grid-2{ grid-template-columns:1fr; }
  .seg{ grid-template-columns:repeat(2,1fr); }
  .btn span{ display:none; }
  .btn-primary span{ display:inline; }
  .select-wrap{ display:none; }
  .stat-val{ font-size:20px; }
  .danger-zone{ flex-direction:column; align-items:stretch; }
}

/* أجهزة اللمس عمومًا */
@media (hover:none){
  .task-side{ opacity:1; }
  .task:hover{ transform:none; box-shadow:var(--shadow-1); }
}

@media (prefers-reduced-motion:reduce){
  *{ animation-duration:.01ms !important; transition-duration:.01ms !important; }
}

/* مقسّم من خانتين — لاختيار مزوّد التقويم */
.seg-2{ grid-template-columns:1fr 1fr; }
