:root {
  --bg: #f1f4f3; --surface: #ffffff; --surface2: #e8eeec; --text: #14201e; --muted: #5a6b68;
  --line: #cfd9d6; --primary: #0b5d57; --primary-text: #ffffff; --accent: #b87a00; --danger: #b3261e; --danger-bg: #fbe9e7;
  --warn: #8a5a00; --warn-bg: #fff3d6; --ok: #1b6e3a; --ok-bg: #e2f3e8; --disabled: #d9dedc; --friday: #b3261e;
  --shadow: 0 2px 10px rgba(0, 0, 0, .12); --backdrop: rgba(10, 20, 18, .5);
  --c0: #0b5d57; --c1: #7a3fb0; --c2: #b8620a; --c3: #1d62c9; --c4: #a31d6a; --c5: #5d6b00;
  --font: system-ui, -apple-system, "SF Arabic", "Segoe UI", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1615; --surface: #17211f; --surface2: #202d2b; --text: #e8f0ee; --muted: #9db0ac;
    --line: #2f4340; --primary: #3fb5aa; --primary-text: #07201d; --accent: #e0a526; --danger: #ff8a80; --danger-bg: #3b1f1d;
    --warn: #ffd37a; --warn-bg: #3a2e12; --ok: #7ee0a0; --ok-bg: #16301f; --disabled: #2a3331; --friday: #ff8a80;
    --shadow: 0 2px 12px rgba(0, 0, 0, .5); --backdrop: rgba(0, 0, 0, .65);
    --c0: #4fd0c4; --c1: #c79bf0; --c2: #f0a860; --c3: #7fb2ff; --c4: #f58cc3; --c5: #c5d85a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
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: 16px; line-height: 1.6;
  min-height: 100vh; overscroll-behavior-y: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
@supports (min-height: 100dvh) { body { min-height: 100dvh; } }
body.modal-open { overflow: hidden; }
.noscript { padding: 16px; }
button, input, select, textarea { font: inherit; font-size: 16px; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* دکمه‌ها */
.btn {
  min-height: 44px; min-width: 44px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-appearance: none; appearance: none; touch-action: manipulation;
}
.btn:active { filter: brightness(.94); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.small { font-size: 14px; padding: 6px 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ورود */
.login { max-width: 420px; margin: 0 auto; padding: 48px 20px 24px; }
.login h1 { margin: 12px 0 4px; font-size: 28px; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; display: block; }
.field { display: block; margin: 14px 0; }
.field > span { display: block; font-weight: 600; margin-bottom: 4px; }
.input, .select {
  width: 100%; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
.select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1.5l6 6 6-6' fill='none' stroke='%23778' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-position: 14px 50%; background-size: 14px 9px; background-repeat: no-repeat; padding-inline-start: 38px; }
.input[dir="ltr"] { text-align: left; }
.error { background: var(--danger-bg); color: var(--danger); border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-weight: 600; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.okmsg { background: var(--ok-bg); color: var(--ok); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }

/* صفحه اصلی */
.page { max-width: 640px; margin: 0 auto; padding: 0 14px 40px; }
.appbar { display: flex; align-items: center; gap: 10px; padding: 14px 0 8px; }
.appbar h1 { font-size: 22px; margin: 0; flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 12px 0; }
.card h2 { font-size: 17px; margin: 0 0 8px; }
.datebig { font-size: 22px; font-weight: 700; margin: 4px 0 10px; }
.draft { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.draft:first-of-type { border-top: 0; }
.draft .info { flex: 1; min-width: 0; }
.draft .title { font-weight: 700; }
.empty { color: var(--muted); padding: 8px 0; }

/* ویرایشگر */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 8px 12px 8px; padding-top: calc(8px + env(safe-area-inset-top)); margin: calc(-1 * env(safe-area-inset-top)) 0 0;
  box-shadow: var(--shadow);
}
.topbar .r1 { display: flex; align-items: center; gap: 8px; }
.topbar .ttl { flex: 1; min-width: 0; }
.topbar .ttl b { display: block; font-size: 17px; line-height: 1.3; }
.topbar .ttl small { color: var(--muted); }
.topbar .r2 { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; background: var(--surface2); white-space: nowrap; }
.pill.saved { background: var(--ok-bg); color: var(--ok); }
.pill.dirty { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--danger-bg); color: var(--danger); }
.loc { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin: 10px 0; overflow: hidden; }
.loc > .lh {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 52px; background: transparent; border: 0; text-align: start; font-weight: 700;
}
.loc > .lh .nm { flex: 1; }
.loc > .lh .chev { transition: transform .15s; display: inline-block; }
.loc > .lh[aria-expanded="true"] .chev { transform: rotate(90deg); }
.badge { min-width: 26px; padding: 0 8px; text-align: center; border-radius: 999px; background: var(--primary); color: var(--primary-text); font-size: 14px; font-weight: 700; }
.badge.zero { background: var(--surface2); color: var(--muted); }
.cells { border-top: 1px solid var(--line); }
.cell {
  display: block; width: 100%; text-align: start; padding: 10px 14px; min-height: 56px; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.cell:last-child { border-bottom: 0; }
.cell:active { background: var(--surface2); }
.cell .sh { display: flex; gap: 8px; align-items: baseline; font-weight: 600; }
.cell .sh .tm { color: var(--muted); font-weight: 400; font-size: 14px; direction: ltr; unicode-bidi: isolate; }
.cell .sh .add { margin-inline-start: auto; color: var(--primary); font-size: 22px; line-height: 1; }
.cell.disabled { background: var(--disabled); color: var(--muted); cursor: not-allowed; }
.cell .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  display: inline-flex; flex-direction: column; padding: 4px 10px; border-radius: 10px; background: var(--surface2);
  border-inline-start: 5px solid var(--cc, var(--primary)); line-height: 1.35; max-width: 100%;
}
.chip .pn { font-weight: 600; }
.chip .pm { font-size: 13px; color: var(--muted); }
.chip.dup { outline: 2px solid var(--accent); }
.c0 { --cc: var(--c0); } .c1 { --cc: var(--c1); } .c2 { --cc: var(--c2); } .c3 { --cc: var(--c3); } .c4 { --cc: var(--c4); } .c5 { --cc: var(--c5); }
.tag { display: inline-block; padding: 0 8px; border-radius: 8px; font-size: 13px; border: 1px solid var(--cc, var(--line)); color: var(--text); background: transparent; }
.tag::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--cc, var(--muted)); margin-inline-end: 5px; }

/* برگه */
.backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: var(--backdrop); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column;
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow); animation: up .2s ease-out;
  padding-bottom: env(safe-area-inset-bottom);
}
@supports (height: 100dvh) { .sheet { max-height: 90dvh; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet > header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.sheet > header h2 { flex: 1; margin: 0; font-size: 17px; line-height: 1.4; }
.sheet > header small { display: block; color: var(--muted); font-weight: 400; font-size: 13px; }
.sheet .sbody { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px 16px; flex: 1 1 auto; }
.sheet .sfoot { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.sheet .sfoot .btn { flex: 1 1 40%; }
.sheet .sfoot .btn.wide { flex-basis: 100%; }
.guide { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 10px; font-weight: 600; margin-bottom: 10px; }
.person { padding: 10px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .pn { font-weight: 700; }
.person .acts { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.person .acts .btn { flex: 1; min-width: 80px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; min-height: 40px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
.tab[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 700; }
.results { list-style: none; margin: 0; padding: 0; }
.res {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: start; min-height: 52px; padding: 8px 6px; border: 0; border-bottom: 1px solid var(--line); background: transparent;
  border-inline-start: 5px solid var(--cc, var(--line));
}
.res .nm { flex: 1; min-width: 0; }
.res .nm b { display: block; }
.res .nm small { color: var(--muted); }
.res.taken { opacity: .55; }
.res .warnb { font-size: 13px; background: var(--warn-bg); color: var(--warn); padding: 0 8px; border-radius: 8px; }
.opts { display: grid; gap: 8px; }
.opt { min-height: 48px; text-align: start; padding: 8px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); }
.opt[aria-checked="true"], .opt.sel { border-color: var(--primary); background: var(--surface2); font-weight: 700; }
.opt[disabled] { opacity: .45; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.sbody h3 { font-size: 15px; margin: 14px 0 6px; color: var(--muted); }

/* تقویم */
.cal-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.cal-head .t { flex: 1; text-align: center; font-weight: 700; font-size: 18px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: 13px; color: var(--muted); padding: 4px 0; }
.cal .wd.fri { color: var(--friday); font-weight: 700; }
.cal .d { min-height: 44px; border-radius: 10px; border: 1px solid transparent; background: var(--surface2); font-weight: 600; padding: 0; }
.cal .d.fri { color: var(--friday); }
.cal .d.today { border-color: var(--accent); }
.cal .d.sel { background: var(--primary); color: var(--primary-text); }
.cal .blank { min-height: 44px; }

/* اعلان */
.toast {
  position: fixed; z-index: 80; right: 12px; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: 460px; margin: 0 auto;
  background: #1b2826; color: #fff; padding: 10px 14px; border-radius: 14px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center;
}
.toast.top { bottom: auto; top: calc(12px + env(safe-area-inset-top)); }
.toast .msg { flex: 1; }
.toast .btn { min-height: 40px; background: transparent; color: #ffd37a; border-color: #ffd37a; }
.issues { list-style: none; margin: 8px 0; padding: 0; }
.issues li { padding: 8px 10px; border-radius: 10px; margin-bottom: 6px; font-size: 15px; }
.issues li.error { background: var(--danger-bg); color: var(--danger); font-weight: 400; margin: 0 0 6px; }
.issues li.warn { background: var(--warn-bg); color: var(--warn); }
.sum { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.mono { direction: ltr; text-align: left; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
textarea.json { width: 100%; min-height: 120px; direction: ltr; font-family: ui-monospace, Menlo, monospace; font-size: 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
