/* styles.css — 300 يوم */
:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --card-2: #f1f1ee;
  --text: #1c1c1e;
  --text-2: #5c5c62;
  --text-3: #8e8e93;
  --border: #e4e4e0;
  --border-2: #d4d4cf;
  --accent: #3b6f8a;
  --accent-ink: #ffffff;
  --accent-soft: #e5eef3;
  --accent-mid: #9dbfd0;
  --accent-deep: #2b5569;
  --sand: #e9e3d6;
  --sand-ink: #6f6352;
  --calm: #e3eae4;
  --calm-ink: #4c6657;
  --warm: #f0e9df;
  --warm-ink: #7a6a55;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Arabic", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --tabbar-h: 58px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414; --card: #1e1e1f; --card-2: #262628; --text: #f2f2f0; --text-2: #b3b3b0; --text-3: #7d7d7a;
    --border: #2c2c2e; --border-2: #3a3a3c; --accent: #7fb3c9; --accent-ink: #0f1a20; --accent-soft: #22323b;
    --accent-mid: #4a7a90; --accent-deep: #a9cedd; --sand: #3a352c; --sand-ink: #d9cdb6; --calm: #27312a; --calm-ink: #b8cdbd;
    --warm: #352f27; --warm-ink: #d6c7b2; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141414; --card: #1e1e1f; --card-2: #262628; --text: #f2f2f0; --text-2: #b3b3b0; --text-3: #7d7d7a;
  --border: #2c2c2e; --border-2: #3a3a3c; --accent: #7fb3c9; --accent-ink: #0f1a20; --accent-soft: #22323b;
  --accent-mid: #4a7a90; --accent-deep: #a9cedd; --sand: #3a352c; --sand-ink: #d9cdb6; --calm: #27312a; --calm-ink: #b8cdbd;
  --warm: #352f27; --warm-ink: #d6c7b2; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
  min-height: 100vh; min-height: 100dvh;
}
h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.skip-link { position: absolute; top: -40px; right: 8px; background: var(--card); padding: 8px; border-radius: 8px; }
.skip-link:focus { top: calc(var(--sat) + 8px); z-index: 50; }

.app-header {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  padding: calc(var(--sat) + 10px) calc(16px + var(--sar)) 8px calc(16px + var(--sal));
  border-bottom: 1px solid var(--border);
}
.app-header-inner { max-width: 640px; margin: 0 auto; }
#screen-title { font-size: 26px; font-weight: 700; letter-spacing: -0.2px; }
#screen-sub { font-size: 14px; margin-top: 2px; }

.view {
  max-width: 640px; margin: 0 auto;
  padding: 14px calc(16px + var(--sar)) calc(var(--tabbar-h) + var(--sab) + 24px) calc(16px + var(--sal));
  outline: none;
}

.tabbar {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 10;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tabbar-h) + var(--sab));
  padding: 0 var(--sar) var(--sab) var(--sal);
  background: var(--card); border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; color: var(--text-3); font-size: 11px; padding: 6px 2px; min-width: 44px; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--accent); }

/* بطاقات */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card.is-muted { opacity: 0.6; }
.card-title { font-size: 17px; font-weight: 600; }
.section-title { font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: 0.3px; margin: 18px 4px 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: var(--card); color: var(--text);
  font-size: 15px; font-weight: 500; cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { opacity: 0.75; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-soft { background: var(--accent-soft); color: var(--accent-deep); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.btn-danger { color: var(--sand-ink); border-color: var(--sand); background: var(--sand); }
.btn.is-on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-group .btn { flex: 1 1 auto; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--border-2); background: var(--card); font-size: 14px; cursor: pointer;
}
.chip.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep); }
.chip.is-on::before { content: "✓"; font-size: 12px; }
.chip-static { cursor: default; min-height: 28px; padding: 2px 10px; font-size: 12px; background: var(--card-2); border-color: transparent; color: var(--text-2); }

/* الشارات */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--card-2); color: var(--text-2); white-space: nowrap; }
.badge-full { background: var(--accent); color: var(--accent-ink); }
.badge-min { background: var(--accent-soft); color: var(--accent-deep); }
.badge-partial { background: var(--warm); color: var(--warm-ink); }
.badge-rest { background: var(--calm); color: var(--calm-ink); }
.badge-opt { background: var(--card-2); color: var(--text-3); }
.badge-soft { background: var(--sand); color: var(--sand-ink); }

/* شريط التقدم */
.bar { height: 8px; background: var(--card-2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.bar > span { display: block; height: 100%; background: var(--accent-mid); border-radius: 999px; transition: width .25s ease; }
.bar > span.is-full { background: var(--accent); }
.bar-lg { height: 12px; }

/* بطاقة الهدف */
.goal { padding: 12px 14px; }
.goal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.goal-name { font-size: 16px; font-weight: 600; }
.goal-meta { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.goal-note { font-size: 13px; color: var(--text-3); margin-top: 4px; }
.goal-today { font-size: 13px; color: var(--accent-deep); margin-top: 4px; }
.goal-value { font-size: 14px; margin-top: 6px; display: flex; justify-content: space-between; }
.goal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.goal-actions .btn { flex: 1 1 auto; min-width: 64px; }
.goal.is-rest .goal-actions, .goal.is-rest .bar { display: none; }

/* الصفحة الرئيسية */
.day-hero { padding: 16px; }
.day-num { font-size: 32px; font-weight: 700; letter-spacing: -0.5px; }
.day-num small { font-size: 16px; font-weight: 500; color: var(--text-2); }
.day-state { font-size: 15px; margin-top: 8px; }
.day-explain { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.notice { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 14px; border: 1px solid transparent; }
.notice-calm { background: var(--calm); color: var(--calm-ink); }
.notice-sand { background: var(--sand); color: var(--sand-ink); }
.notice-accent { background: var(--accent-soft); color: var(--accent-deep); }
.notice .btn { margin-top: 8px; }
.hard-row { display: flex; gap: 8px; margin: 4px 0 14px; }

/* شبكة 300 يوم */
.grid300 { display: grid; grid-template-columns: repeat(15, 1fr); gap: 4px; direction: rtl; }
.cell { aspect-ratio: 1; border-radius: 4px; background: var(--card-2); border: 1px solid transparent; padding: 0; cursor: pointer; min-width: 0; }
.cell[data-state="partial"] { background: var(--warm); }
.cell[data-state="minimum"] { background: var(--accent-mid); }
.cell[data-state="full"] { background: var(--accent); }
.cell.is-future { background: transparent; border-color: var(--border); }
.cell.is-today { outline: 2px solid var(--accent-deep); outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--text-2); margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-left: 5px; background: var(--card-2); }
.legend .l-partial::before { background: var(--warm); }
.legend .l-min::before { background: var(--accent-mid); }
.legend .l-full::before { background: var(--accent); }
.legend .l-future::before { background: transparent; border: 1px solid var(--border); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat-v { font-size: 22px; font-weight: 700; }
.stat-l { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.journey { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-3); margin-top: 8px; flex-wrap: wrap; }
.journey b { color: var(--text); font-weight: 600; }
.journey .arrow { opacity: 0.5; }
.journey .is-phase { color: var(--accent-deep); font-weight: 700; }

/* نماذج */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input[type="text"], .field input[type="number"], .field input[type="date"], .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-2);
  background: var(--card); color: var(--text); font-size: 16px; appearance: none; -webkit-appearance: none;
}
.field textarea { min-height: 90px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.field .hint { font-size: 12px; color: var(--text-3); }
.switch-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch { position: relative; width: 50px; height: 30px; border-radius: 999px; background: var(--border-2); border: 0; cursor: pointer; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.is-on { background: var(--accent); }
.switch.is-on::after { transform: translateX(-20px); }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .t { font-weight: 500; }
.list-row .s { font-size: 13px; color: var(--text-2); }
.list-row.is-tappable { cursor: pointer; }
.weekday-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.weekday-picker .chip { min-height: 36px; padding: 4px 10px; font-size: 13px; }
.weekday-picker .chip.is-on::before { content: none; }

/* الورقة السفلية */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.35); }
.sheet-panel {
  position: absolute; bottom: 0; right: 0; left: 0; max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}
.sheet-handle { width: 36px; height: 5px; border-radius: 3px; background: var(--border-2); margin: 2px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { font-size: 19px; font-weight: 700; }
.sheet-body { overflow: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
.sheet-body > .card { margin-top: 0; }

.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + var(--sab) + 14px); right: 50%; transform: translateX(50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60;
  max-width: calc(100% - 32px); text-align: center; box-shadow: 0 4px 14px rgba(0,0,0,0.18);
}
.toast[hidden] { display: none; }

.num { font-variant-numeric: tabular-nums; unicode-bidi: isolate; }
.empty { text-align: center; color: var(--text-3); padding: 24px 8px; font-size: 14px; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.kv { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-2); }
.inline-list { display: flex; flex-wrap: wrap; gap: 6px; }
.subject-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.subject-row:last-child { border-bottom: 0; }
.subject-row .t { flex: 1; font-size: 15px; }
.subject-row .acts { display: flex; gap: 6px; }

@media (min-width: 480px) { .grid300 { grid-template-columns: repeat(20, 1fr); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
