/* The diary. A weekly planner spread: seven columns separated by rules, not cards.
   One bold element, the day letter (א׳–ש׳) set large in Frank Ruhl,
   with a highlighter swipe behind today's. Everything else stays quiet. */

:root {
  --paper: #F2F4F7;
  --sheet: #FFFFFF;
  --ink: #1B2A3D;
  --ink-2: #5B6B7F;
  --ink-3: #8C99A8;
  --rule: #DCE2E9;
  --hl: #FFE45C;
  --hl-ink: #1B2A3D;
  --shabbat: #EEEAF8;
  --overdue: #B4462F;
  --blue: #2F6BD8; --green: #23946A; --pink: #CF4A8B; --orange: #DB7B23; --violet: #7656D6; --gray: #77828F;
  --radius-s: 6px; --radius-l: 16px;
  --shadow: 0 12px 40px rgba(27, 42, 61, .18);
  --f-ui: "Assistant", "Segoe UI", Arial, sans-serif;
  --f-display: "Frank Ruhl Libre", "David", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #11161D; --sheet: #19212B; --ink: #E3E8EE; --ink-2: #9AA8B8; --ink-3: #6B7888;
    --rule: #26303C; --hl: #E9CB3B; --hl-ink: #11161D; --shabbat: #1B1A2B; --overdue: #F08A72;
    --blue: #6A9BF0; --green: #4DC195; --pink: #EB7FB3; --orange: #F0A156; --violet: #A38BF0; --gray: #9AA6B3;
    --shadow: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font: 400 16px/1.45 var(--f-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--ink-2); }

/* ── buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
  background: none; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.ghost { border-color: var(--rule); }
.btn.ghost:hover { background: var(--sheet); }
.btn.danger { color: var(--overdue); }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center;
  border: 0; background: none; border-radius: 50%; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { background: var(--sheet); }
.icon-btn svg, .fab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle[r="1.4"] { fill: currentColor; stroke: none; }

/* ── header ──────────────────────────────────────────── */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 24px 10px;
  position: sticky; top: 0; z-index: 5; background: var(--paper);
}
.title { flex: 1; min-width: 0; }
.title h1 { margin: 0; font: 500 26px/1.15 var(--f-display); letter-spacing: -.01em; }
.title p { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.weeknav { display: flex; align-items: center; gap: 2px; }
.tools { display: flex; gap: 2px; }

.offline { margin: 0 24px 8px; padding: 8px 12px; border-radius: var(--radius-s); background: var(--sheet); color: var(--ink-2); font-size: 14px; border: 1px dashed var(--rule); }

/* ── the week ────────────────────────────────────────── */
.week {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 300px;
  margin: 0 24px 40px; border-top: 1px solid var(--rule);
  min-height: calc(100vh - 110px);
}
.day {
  border-inline-start: 1px solid var(--rule);
  padding: 14px 12px 12px; display: flex; flex-direction: column; min-width: 0;
  transition: background-color .15s;
}
.day:first-child { border-inline-start: 0; }
.day.shabbat { background: var(--shabbat); }
.day.drop { background: color-mix(in srgb, var(--hl) 22%, transparent); }

.day-head { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 10px; }
.letter {
  font: 900 54px/0.9 var(--f-display); letter-spacing: -.02em; position: relative; z-index: 0;
  padding: 0 4px; margin-inline-start: -4px;
}
.day.past .letter { color: var(--ink-3); }
/* the highlighter swipe: slightly tilted, uneven ends, like a real highlighter */
.day.today .letter::before {
  content: ""; position: absolute; z-index: -1; inset: 38% -6px 4% -8px;
  background: var(--hl); border-radius: 3px 10px 4px 12px / 8px 4px 10px 4px;
  transform: rotate(-2.5deg); opacity: .95;
}
.day.today .letter { color: var(--hl-ink); }
.day-meta { display: flex; flex-direction: column; line-height: 1.2; padding-bottom: 3px; min-width: 0; }
.day-meta .greg { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.day-meta .heb { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-name { display: none; }

.cal { display: flex; flex-direction: column; gap: 2px; margin: 0 0 8px; font-size: 13px; color: var(--ink-2); }
.cal .hol { color: var(--violet); font-weight: 600; }
.cal .hol.major { color: var(--ink); }
.cal .times { font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.item {
  display: flex; align-items: flex-start; gap: 8px; padding: 6px 6px; border-radius: var(--radius-s);
  cursor: pointer; position: relative; min-width: 0;
}
.item:hover { background: color-mix(in srgb, var(--sheet) 80%, transparent); }
.day.shabbat .item:hover { background: color-mix(in srgb, var(--sheet) 55%, transparent); }
.item .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item .t { display: block; }
.item .sub { display: block; color: var(--ink-2); font-size: 13px; }
.item.dragging { opacity: .4; }

/* events: a short gel-pen bar along the leading edge */
.item.event { padding-inline-start: 12px; }
.item.event::before {
  content: ""; position: absolute; inset-inline-start: 2px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px;
  background: var(--c, var(--blue));
}
.item.event .time { font-size: 13px; font-weight: 700; color: var(--c, var(--blue)); font-variant-numeric: tabular-nums; display: block; }
.item.allday { background: color-mix(in srgb, var(--c, var(--blue)) 12%, transparent); }
.item.allday::before { display: none; }
.item.allday { padding-inline-start: 8px; }

/* tasks: a hand-drawn-looking ring that fills when done */
.check-btn {
  flex: none; width: 20px; height: 20px; margin-top: 2px; border-radius: 50%;
  border: 1.8px solid var(--c, var(--ink-2)); background: none; padding: 0; cursor: pointer;
  display: grid; place-items: center;
}
.check-btn svg { width: 12px; height: 12px; stroke: var(--paper); stroke-width: 3; fill: none; opacity: 0; }
.item.done .check-btn { background: var(--c, var(--ink-2)); }
.item.done .check-btn svg { opacity: 1; }
.item.done .t { text-decoration: line-through; text-decoration-color: var(--ink-3); color: var(--ink-3); }
.item.priority .t { font-weight: 700; }
.item.priority .t::after { content: " ★"; color: var(--orange); font-size: 12px; }
.item .rec { color: var(--ink-3); font-size: 12px; margin-inline-start: 4px; }

.list + .list { margin-top: 6px; }

.add {
  margin-top: auto; padding-top: 8px;
}
.add input {
  width: 100%; border: 0; border-bottom: 1px solid transparent; background: none; padding: 8px 6px; border-radius: 0;
  color: var(--ink);
}
.add input::placeholder { color: var(--ink-3); }
.add input:focus { outline: none; border-bottom-color: var(--ink-2); }
.add .hint { font-size: 12px; color: var(--ink-3); padding: 2px 6px 0; display: none; }
.add input:focus + .hint { display: block; }

.overdue { margin: 0 0 10px; padding: 8px 8px 6px; border-radius: var(--radius-s); border: 1px dashed color-mix(in srgb, var(--overdue) 50%, transparent); }
.overdue-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 13px; color: var(--overdue); font-weight: 700; margin-bottom: 2px; }
.overdue-head button { border: 0; background: none; color: var(--overdue); font-weight: 600; font-size: 13px; cursor: pointer; padding: 2px 4px; text-decoration: underline; text-underline-offset: 2px; }
.overdue .sub.when { color: var(--overdue); }

/* ── the weekly panel ───────────────────────────────── */
.panel { border-inline-start: 1px solid var(--rule); padding: 14px 16px; display: flex; flex-direction: column; gap: 22px; }
.panel h2 { margin: 0 0 6px; font: 500 20px/1.2 var(--f-display); }
.panel .progress { font-size: 13px; color: var(--ink-2); margin: -2px 0 6px; }
.panel section.drop { background: color-mix(in srgb, var(--hl) 22%, transparent); border-radius: var(--radius-s); }
.panel textarea {
  width: 100%; min-height: 180px; resize: vertical; border: 1px solid var(--rule); border-radius: var(--radius-s);
  background: var(--sheet); padding: 10px; line-height: 1.6;
}
.panel .saved { font-size: 12px; color: var(--ink-3); height: 16px; }

/* ── mobile day strip + FAB ─────────────────────────── */
.strip { display: none; }
.fab { display: none; }

/* ── dialogs ─────────────────────────────────────────── */
dialog.sheet {
  border: 0; padding: 0; border-radius: var(--radius-l); background: var(--sheet); color: var(--ink);
  width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow); max-height: calc(100dvh - 40px);
}
dialog.sheet::backdrop { background: rgba(17, 22, 29, .35); }
dialog.sheet form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font: 500 22px/1.2 var(--f-display); }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--ink-2); }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
dialog input:not([type=radio]):not([type=checkbox]), dialog select, dialog textarea {
  border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--paper); padding: 9px 10px; min-height: 42px; width: 100%;
}
dialog textarea { line-height: 1.5; resize: vertical; }
.title-input { font-size: 20px !important; font-weight: 600; border: 0 !important; border-bottom: 1px solid var(--rule) !important; border-radius: 0 !important; background: none !important; padding-inline: 0 !important; }
.title-input:focus { outline: none; border-bottom-color: var(--ink) !important; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.row .nodate { flex: 0 0 auto; padding-bottom: 10px; }
.seg { display: inline-flex; align-self: flex-start; border: 1px solid var(--rule); border-radius: 999px; padding: 3px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 16px; border-radius: 999px; color: var(--ink-2); font-weight: 600; font-size: 15px; }
.seg input:checked + span { background: var(--ink); color: var(--paper); }
.seg input:focus-visible + span { outline: 2px solid var(--blue); }
.colors { border: 0; padding: 0; margin: 0; display: flex; gap: 10px; align-items: center; }
.colors legend { font-size: 14px; color: var(--ink-2); float: right; margin-inline-end: 8px; }
.colors label { cursor: pointer; }
.colors input { position: absolute; opacity: 0; }
.colors i { display: block; width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--sheet); outline: 2px solid transparent; }
.colors input:checked + i { outline-color: var(--ink); }
.colors input:focus-visible + i { outline-color: var(--blue); }
.c-blue { background: var(--blue); } .c-green { background: var(--green); } .c-pink { background: var(--pink); }
.c-orange { background: var(--orange); } .c-violet { background: var(--violet); } .c-gray { background: var(--gray); }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-actions .danger { margin-inline-start: auto; }
.delete-choice { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--rule); padding-top: 12px; }
.delete-choice p { margin: 0; }
body:not(.k-event) .only-event, body.k-event .only-task, body.k-event .nodate { display: none; }
dialog hr { border: 0; border-top: 1px solid var(--rule); width: 100%; margin: 4px 0; }

.search-form input[type=search] { font-size: 18px; }
.search-results { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.search-results li button { width: 100%; text-align: start; border: 0; background: none; padding: 10px 6px; border-bottom: 1px solid var(--rule); cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.search-results li button:hover { background: var(--paper); }
.search-results .d { color: var(--ink-2); font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.search-results .empty { color: var(--ink-2); padding: 10px 6px; }

.toast {
  position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); inset-inline-start: 50%; transform: translate(50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(50%, 0); pointer-events: auto; }
.toast button { background: none; border: 0; color: var(--hl); font-weight: 700; margin-inline-start: 10px; cursor: pointer; }

/* ── login ──────────────────────────────────────────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-mark { font: 900 72px/1 var(--f-display); position: relative; z-index: 0; align-self: flex-start; padding: 0 8px; }
.login-mark::before { content: ""; position: absolute; z-index: -1; inset: 40% -4px 6% -6px; background: var(--hl); transform: rotate(-3deg); border-radius: 3px 10px 4px 12px / 8px 4px 10px 4px; }
.login h1 { margin: 0 0 6px; font: 500 30px/1.1 var(--f-display); }
.login label { display: flex; flex-direction: column; gap: 4px; color: var(--ink-2); font-size: 14px; }
.login input { border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--sheet); padding: 10px; min-height: 44px; }
.login-err { color: var(--overdue); min-height: 1.4em; margin: 0; font-size: 14px; }

/* ── medium: the panel moves under the week ─────────── */
@media (max-width: 1360px) {
  .week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .panel { grid-column: 1 / -1; border-inline-start: 0; border-top: 1px solid var(--rule); display: grid; grid-template-columns: 1fr 1fr; gap: 32px; padding: 20px 0; }
  .letter { font-size: 46px; }
}

/* ── phone: days stack, a sticky strip of letters on top ─ */
@media (max-width: 900px) {
  .top { padding: max(10px, env(safe-area-inset-top)) 16px 6px; gap: 4px; }
  .title h1 { font-size: 22px; }
  .title p { font-size: 13px; }
  #thisWeek { padding: 0 10px; }
  .offline { margin: 0 16px 8px; }
  .strip {
    display: grid; grid-template-columns: repeat(7, 1fr); position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 4;
    background: var(--paper); padding: 0 12px 8px; border-bottom: 1px solid var(--rule);
  }
  .strip button {
    border: 0; background: none; cursor: pointer; padding: 6px 0 4px; border-radius: 10px;
    display: flex; flex-direction: column; align-items: center; gap: 1px; position: relative; z-index: 0; color: var(--ink);
  }
  .strip .l { font: 900 22px/1 var(--f-display); }
  .strip .n { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
  .strip .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); opacity: 0; }
  .strip .has .dot { opacity: 1; }
  .strip .today .l { position: relative; }
  .strip .today .l::before { content: ""; position: absolute; z-index: -1; inset: 40% -5px 0 -5px; background: var(--hl); transform: rotate(-3deg); border-radius: 3px 8px 3px 8px; }
  .strip .today .l { color: var(--hl-ink); }
  .strip .sat { background: var(--shabbat); }

  .week { display: block; margin: 0 0 96px; border-top: 0; min-height: 0; }
  .day { border-inline-start: 0; border-bottom: 1px solid var(--rule); padding: 14px 16px 8px; scroll-margin-top: 130px; }
  .day-head { align-items: center; margin-bottom: 6px; }
  .letter { font-size: 40px; }
  .day-name { display: inline; font-weight: 700; }
  .day-meta .greg { font-weight: 400; color: var(--ink-2); font-size: 13px; }
  .day-meta .top-line { font-size: 16px; }
  .item { padding: 8px 6px; }
  .add input { padding: 10px 6px; }
  .panel { display: flex; padding: 20px 16px; border-top: 0; }
  .fab {
    display: grid; place-items: center; position: fixed; z-index: 6;
    inset-inline-start: 18px; bottom: max(20px, calc(env(safe-area-inset-bottom) + 8px));
    width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--ink); color: var(--paper);
    box-shadow: var(--shadow); cursor: pointer;
  }
  .fab svg { width: 26px; height: 26px; stroke-width: 2.2; }
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--radius-l) var(--radius-l) 0 0; max-height: 92dvh; }
  dialog.sheet form { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}

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