:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1b1d22;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #2f6fec;
  --accent-soft: #e7eefd;
  --danger: #d93636;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --card: #20232a;
    --text: #eceef2;
    --muted: #9aa1ad;
    --line: #2f333c;
    --accent: #5b8cff;
    --accent-soft: #26324d;
    --danger: #ff6b6b;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link { background: none; border: none; color: var(--accent); padding: 8px 4px; }
button.danger { color: var(--danger); }
button.small { padding: 4px 10px; font-size: 14px; }
button.wide { display: block; width: 100%; margin-top: 8px; }

input, textarea {
  font: inherit;
  font-size: 16px; /* 16px stops iPhone zooming in on focus */
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 110px; display: block; }

.muted { color: var(--muted); }
.tiny { font-size: 13px; }
.err { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 6px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

/* ---------- lock ---------- */
.lock {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 20px) 24px calc(env(safe-area-inset-bottom) + 20px);
  overflow-y: auto;
}
.lock-box { width: 100%; max-width: 360px; text-align: center; }
.lock-box h2 { margin: 8px 0 6px; }
.lock-box input { margin-top: 10px; text-align: center; }
.lock-icon { font-size: 40px; }
.code {
  font: 600 24px/1.3 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 2px;
  background: var(--card);
  border: 1px dashed var(--accent);
  border-radius: 12px;
  padding: 16px 8px;
  margin: 14px 0;
  user-select: all;
  -webkit-user-select: all;
}
.tip {
  margin-top: 28px; text-align: left; font-size: 13px; color: var(--muted);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}

/* ---------- header / tabs ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 14px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; font-size: 20px; margin: 0; }
.top button { padding: 6px 10px; font-size: 13px; }

.banner {
  display: block; width: calc(100% - 28px); margin: 10px 14px 0;
  background: #fff4d6; border: 1px solid #f0d58a; color: #6b5200;
  font-size: 14px; text-align: left;
}
@media (prefers-color-scheme: dark) {
  .banner { background: #3a3220; border-color: #6b5a2a; color: #f3dc9a; }
}

main { padding: 12px 14px calc(84px + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: none; border-radius: 0; background: none;
  padding: 14px 4px; font-size: 14px; color: var(--muted);
}
.tabs button.on { color: var(--accent); font-weight: 600; }

/* ---------- calendar ---------- */
.month-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.month-nav button { padding: 4px 16px; font-size: 22px; line-height: 1.2; }
.month-label { flex: 1; text-align: center; font-size: 17px; font-weight: 600; }

.weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 4px;
}
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; touch-action: pan-y; }
.cell {
  display: flex; flex-direction: column; align-items: stretch;
  min-width: 0; min-height: 58px;
  padding: 4px 3px; border-radius: 8px;
  text-align: left; overflow: hidden;
}
.cell .num { font-size: 13px; font-weight: 600; text-align: center; align-self: center; min-width: 22px; height: 22px; line-height: 22px; }
.cell .snip {
  font-size: 10px; line-height: 1.2; color: var(--muted);
  margin-top: 2px; overflow: hidden; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.cell.other { opacity: .4; }
.cell.has { background: var(--accent-soft); }
.cell.today .num { background: var(--accent); color: #fff; border-radius: 999px; }
.cell.sel { outline: 2px solid var(--accent); outline-offset: -2px; }

.day-panel { margin-top: 14px; }
.day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; }
#dayNote { min-height: 160px; }
#daySaved { min-height: 1.3em; margin-top: 4px; }

/* ---------- job lists ---------- */
.add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.add-row button { flex: none; }
#oldSearch { margin-bottom: 12px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.card { display: block; width: 100%; text-align: left; padding: 12px 14px; }
.card-title { font-weight: 600; }
.card-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.card-snip { font-size: 14px; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- sheets ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.sheet-title { font-weight: 600; padding-right: 8px; }
.sheet-body { padding: 14px 14px calc(30px + env(safe-area-inset-bottom)); }
.sheet-body h3 { margin: 22px 0 6px; font-size: 16px; }
.sheet-body h3:first-child { margin-top: 0; }
.sheet-body > input, #pwForm input, #importPwWrap input { margin-top: 8px; }

.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; margin-right: 6px; }
.pill.active { background: var(--accent-soft); color: var(--accent); }
.pill.old { background: var(--line); color: var(--muted); }

.title-input { font-size: 20px; font-weight: 600; border-color: transparent; background: transparent; padding: 6px 4px; }
.title-input:focus { background: var(--card); }
#jobMeta { padding: 0 4px; }

.prev { margin-top: 14px; }
.toggle {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 15px;
}
.toggle input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
#prevNotes { margin-top: 8px; border-left: 3px solid var(--line); padding-left: 10px; }
.round-head { font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
.round-head:first-child { margin-top: 4px; }

.add-note { margin-top: 14px; }
.add-note textarea { min-height: 80px; }
.add-note button { margin-top: 8px; width: 100%; }

.notes { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.note { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.note.past { background: transparent; }
.note-when { font-size: 12px; color: var(--muted); }
.note-text { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.note-btns { display: flex; gap: 14px; margin-top: 4px; }
.note-btns button { padding: 2px 0; font-size: 14px; }
.note textarea { margin-top: 6px; min-height: 80px; }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60;
  background: #1b1d22; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; max-width: 90vw; text-align: center;
}
