/* تصميم بأسلوب Apple (iOS / macOS): خط النظام، ألوان النظام، أشرطة ضبابية، قوائم مجمّعة */
:root {
  --ws: #007AFF;
  --ws-soft: color-mix(in srgb, var(--ws) 14%, transparent);
  --bg: #F2F2F7;           /* systemGroupedBackground */
  --card: #FFFFFF;         /* secondarySystemGroupedBackground */
  --fill: rgba(118,118,128,.12);  /* tertiarySystemFill */
  --text: #000000;
  --muted: rgba(60,60,67,.6);     /* secondaryLabel */
  --line: rgba(60,60,67,.18);     /* separator */
  --bar: rgba(249,249,249,.78);
  --danger: #FF3B30; --warn: #FF9500; --ok: #34C759;
  --radius: 12px;
  --seg-on: #FFFFFF;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Arabic", "Geeza Pro", system-ui, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #000000; --card: #1C1C1E; --fill: rgba(118,118,128,.24); --text: #FFFFFF;
    --muted: rgba(235,235,245,.6); --line: rgba(84,84,88,.6); --bar: rgba(22,22,24,.78);
    --danger: #FF453A; --warn: #FF9F0A; --ok: #30D158; color-scheme: dark; --seg-on: #636366;
  }
}
:root[data-theme=dark] {
  --bg: #000000; --card: #1C1C1E; --fill: rgba(118,118,128,.24); --text: #FFFFFF;
  --muted: rgba(235,235,245,.6); --line: rgba(84,84,88,.6); --bar: rgba(22,22,24,.78);
  --danger: #FF453A; --warn: #FF9F0A; --ok: #30D158; color-scheme: dark; --seg-on: #636366;
}
@media (min-width: 900px) { :root { --bg: #F5F5F7; } }
@media (min-width: 900px) and (prefers-color-scheme: dark) { :root:not([data-theme=light]) { --bg: #1E1E1E; --card: #2C2C2E; } }
@media (min-width: 900px) { :root[data-theme=dark] { --bg: #1E1E1E; --card: #2C2C2E; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; min-width: 0; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.4 var(--font); letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
/* المحتوى المكتوب بأي لغة يأخذ اتجاهه من أول حرف (عربي/إنجليزي مختلط) */
input, textarea, .item .title, .preview, .list-card .nm, .ws-chip, .crumb { unicode-bidi: plaintext; }

/* ---------- أيقونات Lucide ---------- */
.i { width: 1.1em; height: 1.1em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.18em; }
[dir=ltr] .chev .i, [dir=ltr] [data-back] .i { transform: scaleX(-1); }


/* ---------- الدخول ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); text-align: center; }
.auth-logo { width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(135deg, #34AADC, #5856D6); color: #fff; box-shadow: 0 8px 24px rgba(88,86,214,.3); }
.auth-logo .i { width: 38px; height: 38px; stroke-width: 2.6; }
.auth-card h1 { margin: 4px 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.auth-card form { display: grid; gap: 10px; margin-top: 24px; }
.msg { min-height: 1.2em; font-size: 15px; margin: 4px 0 0; }
.msg.err { color: var(--danger); } .msg.ok { color: var(--ok); }

/* ---------- حقول وأزرار ---------- */
input, textarea, select { width: 100%; padding: 11px 14px; border: 0; border-radius: 10px; background: var(--card); outline: none;
  font-size: 17px; -webkit-appearance: none; appearance: none; }
.sheet input, .sheet textarea, .sheet select { background: var(--fill); }
select { background-image: none; }
input:focus, textarea:focus, select:focus { box-shadow: 0 0 0 2px var(--ws); }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input[type=checkbox] { width: auto; -webkit-appearance: auto; appearance: auto; accent-color: var(--ws); }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; cursor: pointer; font-weight: 600; font-size: 16px; background: var(--fill); color: var(--ws);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; min-height: 44px; }
.btn:active { opacity: .6; }
.btn.primary { background: var(--ws); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 15px; min-height: 36px; border-radius: 9px; }
.btn .i { width: 17px; height: 17px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.icon-btn { border: 0; background: transparent; padding: 8px; cursor: pointer; border-radius: 10px; color: var(--ws);
  display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; }
.icon-btn .i { width: 23px; height: 23px; }
.icon-btn:active { opacity: .5; }

/* ---------- الشريط العلوي (ضبابي) ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--line); padding: calc(var(--safe-t) + 4px) 12px 8px; }
.top-row { display: flex; align-items: center; justify-content: space-between; }
.ws-current { font-weight: 700; font-size: 22px; display: flex; gap: 8px; align-items: center; padding-inline: 4px; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; flex: 1; }
.ws-current span { overflow: hidden; text-overflow: ellipsis; }
.ws-current .i { color: var(--ws); width: 24px; height: 24px; }
.ws-current .crumb { color: var(--muted); font-weight: 600; font-size: 17px; }
.top-actions { display: flex; }
.ws-switch, .ws-sub { display: flex; gap: 8px; margin-top: 6px; overflow-x: auto; scrollbar-width: none; padding-inline: 4px; }
.ws-switch::-webkit-scrollbar, .ws-sub::-webkit-scrollbar, .filters::-webkit-scrollbar { display: none; }
.ws-chip { flex: 0 0 auto; border: 0; background: var(--fill); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 15px;
  display: flex; gap: 6px; align-items: center; min-height: 36px; }
.ws-chip .i { width: 17px; height: 17px; color: var(--c); }
.ws-chip.active { background: var(--c); color: #fff; }
.ws-chip.active .i { color: #fff; }
.badge { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 12px; font-weight: 600; min-width: 18px; line-height: 18px; text-align: center; }
.ws-chip.active .badge { background: rgba(255,255,255,.28); }
/* المساحات الفرعية: شريط مقسّم بأسلوب iOS */
.ws-sub { background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; margin-inline: 4px; }
.ws-sub button { flex: 1 0 auto; border: 0; background: transparent; border-radius: 7px; padding: 6px 12px; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.ws-sub button.on { background: var(--seg-on); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 .5px rgba(0,0,0,.04); }
.ws-sub .badge { font-size: 11px; }
.search-bar { margin-top: 8px; padding-inline: 4px; }
.search-bar input { background: var(--fill); padding: 8px 12px; border-radius: 10px; }

/* ---------- المحتوى ---------- */
.view { padding: 12px 16px calc(120px + var(--safe-b)); max-width: 760px; margin: 0 auto; }
.section-title { font-size: 13px; color: var(--muted); font-weight: 400; margin: 22px 16px 7px; display: flex; justify-content: space-between; align-items: center; text-transform: none; }
.section-title:first-child { margin-top: 4px; }
.section-title span { display: inline-flex; align-items: center; gap: 5px; }
.section-title .i { width: 15px; height: 15px; }
/* قوائم مجمّعة بأسلوب iOS: بطاقة واحدة بفواصل رفيعة */
.list { display: grid; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.item { background: var(--card); padding: 11px 16px; display: flex; gap: 12px; align-items: flex-start; cursor: pointer; position: relative; }
.item + .item::before { content: ""; position: absolute; top: 0; inset-inline-start: 52px; inset-inline-end: 0; border-top: .5px solid var(--line); }
.item:active { background: var(--fill); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 400; line-height: 1.35; word-wrap: break-word; }
.item .sub { font-size: 14px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 3px 10px; }
.item .sub span { display: inline-flex; align-items: center; gap: 4px; }
.item .sub .i { width: 14px; height: 14px; }
.item .sub .late { color: var(--danger); }
.item .sub .soon { color: var(--warn); }
.item.done .title { color: var(--muted); }
.prio3 { color: var(--danger); } .prio2 { color: var(--warn); }
/* دائرة الإنجاز مثل تطبيق التذكيرات */
.check { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%; border: 1.6px solid rgba(128,128,128,.55); background: transparent;
  cursor: pointer; margin-top: 0; display: grid; place-items: center; color: #fff; padding: 0; transition: transform .12s; }
.check:active { transform: scale(.88); }
.check.p3 { border-color: var(--danger); } .check.p2 { border-color: var(--warn); }
.item.done .check { background: var(--ws); border-color: var(--ws); }
.check .i { width: 14px; height: 14px; stroke-width: 3; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--ws-soft); color: var(--ws); font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 48px 12px; }
.empty .big .i { width: 46px; height: 46px; stroke-width: 1.4; opacity: .5; }
.empty p { margin: 10px 0 0; }
.note-card .preview { font-size: 15px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.avatar { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 16px;
  background: linear-gradient(180deg, #A5A5AA, #86868B); color: #fff; margin-inline-start: -4px; }
.item:has(.avatar) + .item::before { inset-inline-start: 64px; }
/* عناصر التحكم المقسّمة (Segmented Control) */
.filters { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.filters button { flex: 1 0 auto; border: 0; background: transparent; padding: 6px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; font-weight: 500; white-space: nowrap; }
.filters button.active { background: var(--seg-on); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 .5px rgba(0,0,0,.04); }

/* ---------- الإضافة السريعة ---------- */
.quick { display: flex; gap: 8px; margin-bottom: 14px; }
.quick input { background: var(--card); }
.quick .btn { white-space: nowrap; }

/* ---------- شريط التبويبات (ضبابي) ---------- */
.tabs { position: fixed; bottom: 0; inset-inline: 0; z-index: 20; display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line); padding-bottom: var(--safe-b); }
.tabs button { border: 0; background: transparent; padding: 7px 0 5px; display: grid; gap: 2px; justify-items: center;
  font-size: 10px; font-weight: 500; color: #8E8E93; cursor: pointer; }
.tabs button .i { width: 25px; height: 25px; stroke-width: 1.8; }
.tabs button.active { color: var(--ws); }
.tabs button.active .i { stroke-width: 2.3; }
.fab { display: grid; place-items: center; position: fixed; z-index: 21; inset-inline-end: 18px; bottom: calc(70px + var(--safe-b)); width: 56px; height: 56px;
  border-radius: 50%; border: 0; background: var(--ws); color: #fff; cursor: pointer; box-shadow: 0 6px 20px color-mix(in srgb, var(--ws) 40%, transparent); }
.fab .i { width: 28px; height: 28px; stroke-width: 2.4; }
.fab:active { transform: scale(.94); }

/* ---------- الماك والشاشات الكبيرة: شريط جانبي مثل تطبيقات macOS ---------- */
@media (min-width: 900px) {
  html, body { font-size: 15px; }
  input, textarea, select { font-size: 15px; padding: 8px 12px; border-radius: 8px; }
  #app { display: grid; grid-template-columns: 230px 1fr; grid-template-rows: auto 1fr; min-height: 100dvh; }
  .top { grid-column: 1 / -1; padding: 10px 20px; }
  .tabs { position: sticky; top: 120px; align-self: start; grid-row: 2; grid-column: 1; display: grid; grid-template-columns: 1fr;
    border: 0; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; padding: 12px 10px; gap: 2px; }
  .tabs button { grid-auto-flow: column; justify-content: start; gap: 9px; font-size: 14px; padding: 6px 10px; border-radius: 7px; color: var(--text); }
  .tabs button .i { width: 18px; height: 18px; color: var(--ws); }
  .tabs button.active { background: var(--fill); color: var(--text); font-weight: 600; }
  .view { grid-column: 2; padding: 20px 28px 48px; width: 100%; }
  .item { padding: 9px 14px; }
  .fab { bottom: 28px; width: 48px; height: 48px; }
  .btn { min-height: 34px; padding: 7px 14px; font-size: 14px; border-radius: 8px; }
  .btn.small { min-height: 28px; padding: 4px 10px; font-size: 13px; border-radius: 7px; }
  .icon-btn { min-width: 34px; min-height: 34px; }
  .icon-btn .i { width: 19px; height: 19px; }
}

/* ---------- النافذة السفلية (Sheet) ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; animation: fade .2s; }
.sheet { position: fixed; z-index: 41; inset-inline: 0; bottom: 0; max-height: 94dvh; overflow-y: auto; background: var(--bg);
  border-radius: 12px 12px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); animation: up .3s cubic-bezier(.2,.9,.3,1); -webkit-overflow-scrolling: touch; }
@media (min-width: 700px) { .sheet { inset-inline: auto; left: 50%; transform: translateX(-50%); width: 540px; bottom: auto; top: 6vh; max-height: 88vh; border-radius: 14px;
  animation: pop .2s; box-shadow: 0 20px 60px rgba(0,0,0,.3), 0 0 0 .5px var(--line); } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) scale(.96); } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .backdrop { animation: none; } }
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 2px; font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; letter-spacing: -0.02em; }
.sheet h2 .i { color: var(--ws); }
.sheet .ws-tag { font-size: 13px; color: var(--muted); margin-bottom: 14px; display: flex; align-items: center; gap: 5px; }
.sheet .ws-tag .i { width: 14px; height: 14px; color: var(--ws); }
.sheet form { display: grid; gap: 10px; }
.sheet label { font-size: 13px; color: var(--muted); display: grid; gap: 5px; padding-inline: 4px; }
.sheet label > input, .sheet label > select { color: var(--text); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; justify-content: space-between; margin-top: 8px; flex-wrap: wrap; }
.actions .end { display: flex; gap: 8px; }
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; flex-wrap: nowrap; overflow-x: auto; }
.seg button { flex: 1 0 auto; border: 0; background: transparent; border-radius: 7px; padding: 7px 10px; cursor: pointer; font-size: 14px; color: var(--text); white-space: nowrap; }
.seg button.on { background: var(--seg-on); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.actions-bar { background: transparent; padding: 0; gap: 8px; flex-wrap: wrap; }
.related { margin-top: 18px; }
.related h3 { font-size: 13px; color: var(--muted); font-weight: 400; margin: 14px 16px 7px; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { width: 44px; height: 44px; border-radius: 10px; border: 0; background: var(--fill); cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.emoji-pick button.on { color: #fff; background: var(--ws); }
.emoji-pick button .i { width: 21px; height: 21px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 0; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--c); cursor: pointer; }
.swatches button.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--c); }

/* مجموعات الإعدادات بأسلوب iOS */
.group-title { font-size: 13px; color: var(--muted); margin: 22px 16px 7px; }
.group { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.group.pad { padding: 12px 16px; }
.group .segmented { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; }
.group .segmented button { flex: 1; border: 0; background: transparent; border-radius: 7px; padding: 7px; cursor: pointer; font-size: 14px; }
.group .segmented button.on { background: var(--seg-on); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.group-row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; cursor: pointer; position: relative; min-height: 44px; }
.group-row + .group-row::before { content: ""; position: absolute; top: 0; inset-inline-start: 56px; inset-inline-end: 0; border-top: .5px solid var(--line); }
.group-row:active { background: var(--fill); }
.group-row.sub { padding-inline-start: 40px; }
.group-row.sub + .group-row::before, .group-row.sub::before { inset-inline-start: 84px; }
.group-row.add { color: var(--ws); }
.group-row .grow { flex: 1; }
.group-row .sw { width: 29px; height: 29px; border-radius: 7px; background: var(--c); color: #fff; display: grid; place-items: center; flex: none; }
.group-row .sw .i { width: 17px; height: 17px; }
.group-row .chev { color: var(--muted); opacity: .6; }
.group-row .chev .i { width: 16px; height: 16px; }
.group-foot { margin: 7px 16px 0; }
.feed { font-size: 12px !important; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* نافذة تأكيد بأسلوب iOS */
.alert-wrap { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.35); display: grid; place-items: center; animation: fade .15s; }
.alert { width: 270px; background: var(--bar); -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px); border-radius: 14px; text-align: center; overflow: hidden; }
.alert p { margin: 0; padding: 18px 16px 14px; font-size: 15px; font-weight: 600; }
.alert input { width: calc(100% - 32px); margin: 0 16px 14px; background: var(--card); font-size: 15px; padding: 7px 10px; border-radius: 7px; }
.alert-btns { display: flex; border-top: .5px solid var(--line); }
.alert-btns button { flex: 1; border: 0; background: transparent; padding: 11px; font-size: 17px; color: var(--ws); cursor: pointer; }
.alert-btns button + button { border-inline-start: .5px solid var(--line); font-weight: 600; }
.alert-btns .destructive { color: var(--danger); }

.toast { position: fixed; z-index: 60; top: calc(var(--safe-t) + 10px); left: 50%; transform: translateX(-50%);
  background: var(--bar); color: var(--text); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 500; max-width: 90vw; text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.15), 0 0 0 .5px var(--line); animation: fade .2s; }
.settings-list { display: grid; gap: 10px; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 6px 0; }
.hint .i { color: var(--ok); }

/* ---------- القوائم المعنونة ---------- */
.lists-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; }
.list-card { background: var(--card); border: 0; border-radius: var(--radius); padding: 12px; cursor: pointer; display: grid; gap: 4px; text-align: start; justify-items: start; }
.list-card:active { opacity: .7; }
.list-card .ic { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--ws); color: #fff; margin-bottom: 6px; }
.list-card .ic .i { width: 18px; height: 18px; }
.list-card .nm { font-weight: 600; line-height: 1.3; }
.list-card .ct { font-size: 13px; color: var(--muted); }
.list-card.add { background: transparent; border: 1.5px dashed var(--line); place-items: center; justify-items: center; color: var(--ws); min-height: 110px; }
.list-card.add .ic { background: var(--ws-soft); color: var(--ws); }
.list-head { display: flex; align-items: center; gap: 4px; margin: -4px -8px 10px; }
.list-head h2 { margin: 0; font-size: 28px; font-weight: 700; flex: 1; display: flex; align-items: center; gap: 10px; letter-spacing: -0.02em; color: var(--ws); }
.list-head h2 .i { width: 26px; height: 26px; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
