/* DESK Buddy phone app — paper-and-ink aesthetic to match the e-ink panel.
   No framework. Mobile-first, 44px+ touch targets, dark-mode aware, safe-area
   insets for notched iPhones. */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --ink: #191919;
  --muted: #78756c;
  --line: #e5e2d8;
  --danger: #b3372f;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1d1d1c;
    --ink: #f0eee7;
    --muted: #99968c;
    --line: #2e2d29;
    --danger: #e0655c;
  }
}

/* Attribute must beat any display rule below. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

input {
  font-family: inherit;
  font-size: 17px; /* >=16px prevents iOS zoom-on-focus */
  color: var(--ink);
}

/* ---------- auth screen ---------- */

#auth {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-box {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  padding-bottom: env(safe-area-inset-bottom);
}

.auth-mark { color: var(--ink); margin: 0 auto; }

.auth-box h1 {
  font-size: 22px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-box p { color: var(--muted); font-size: 15px; }

#auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

#token-input {
  height: 50px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
}
#token-input:focus { outline: none; border-color: var(--ink); }

.hint { font-size: 13px; }
.hint code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- top bar (title + pinned add input) ---------- */

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
}

#topbar .bar,
#topbar #add-form {
  max-width: 560px;
  margin: 0 auto;
}

#topbar .bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

#topbar h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

#settings-btn {
  width: 44px;
  height: 44px;
  margin-right: -11px; /* visually align icon with content edge */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: var(--ink);
}
#settings-btn:active { background: var(--line); }

#add-form { display: flex; gap: 8px; }

#add-input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
#add-input:focus { outline: none; border-color: var(--ink); }
#add-input::placeholder, #token-input::placeholder { color: var(--muted); }

#add-form button {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 28px;
  font-weight: 400;
  line-height: 1;
}
#add-form button:active { opacity: 0.8; }

/* ---------- lists ---------- */

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px calc(56px + env(safe-area-inset-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

ul { list-style: none; }

li.todo {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 2px 2px 2px 0;
}
li.todo + li.todo { border-top: 1px solid var(--line); }
li.todo.pending { opacity: 0.55; }

/* checkbox: 48px touch target around a 24px drawn box */
.check {
  flex: none;
  width: 48px;
  align-self: stretch;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.box {
  position: relative;
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--ink);
  border-radius: 7px;
}

li.done .box { background: var(--ink); }
li.done .box::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 1px;
  width: 6px;
  height: 12px;
  border: solid var(--surface);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.t {
  flex: 1;
  min-width: 0;
  padding: 10px 2px;
}

.t .text {
  font-size: 17px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.sub {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
}
.sub .env { display: inline-flex; flex: none; }
.sub svg { width: 14px; height: 10px; }
.sub span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

li.done .t { color: var(--muted); }
li.done .t .text { text-decoration: line-through; }

.del {
  flex: none;
  width: 44px;
  align-self: stretch;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 17px;
}
.del:active { color: var(--danger); }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  padding: 40px 12px;
}

/* ---------- done today ---------- */

#done-section { margin-top: 22px; }

#done-toggle {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#done-toggle .chev { transition: transform 0.18s ease; }
#done-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }

#done-toggle .count {
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--line);
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0;
}

#done-section .card { margin-top: 6px; }

/* ---------- settings sheet ---------- */

#sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.45);
  animation: fade-in 0.2s ease;
}

#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-width: 560px;
  margin: 0 auto;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 18px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slide-up 0.25s ease;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sheet-head h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

#sheet-close {
  width: 44px;
  height: 44px;
  margin-right: -12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 17px;
  border-radius: 12px;
}

.field { margin: 16px 0; }

.field label,
.field .field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
.field input:focus { outline: none; border-color: var(--ink); }
.field input::placeholder { color: var(--muted); opacity: 0.8; }

.forward-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 6px 6px 14px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
}

.forward-row code {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  overflow-wrap: anywhere;
}

#copy-btn {
  flex: none;
  height: 44px;
  padding: 0 16px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
}
#copy-btn:active { background: var(--line); }

.btn-primary {
  width: 100%;
  height: 50px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 17px;
  font-weight: 600;
  margin-top: 6px;
}
.btn-primary:active { opacity: 0.8; }
.btn-primary:disabled { opacity: 0.5; }

.text-btn {
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 15px;
}

/* ---------- settings: display section ---------- */

.section-head {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* segmented control (text size, density) */
.seg {
  display: flex;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
}

.seg button {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.seg button + button { border-left: 1.5px solid var(--line); }

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

/* toggle rows (whole row is the switch — easy 48px target) */
.toggle-group { margin: 16px 0; }

.toggle-row {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
}

.toggle-row + .toggle-row { border-top: 1px solid var(--line); }

.toggle-label { font-size: 15px; font-weight: 500; }

.switch {
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.15s ease;
}

.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}

.toggle-row[aria-checked="true"] .switch { background: var(--ink); }
.toggle-row[aria-checked="true"] .switch .knob { transform: translateX(20px); }

.toggle-hint {
  padding: 2px 0 8px;
  font-size: 13px;
  color: var(--muted);
}

/* label-left / select-right row (refresh interval) */
.row-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}

.row-field label {
  margin-bottom: 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}

.row-field select,
.quiet-times select {
  font-family: inherit;
  font-size: 16px; /* >=16px prevents iOS zoom-on-focus */
  color: var(--ink);
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

/* quiet hours time pickers */
.quiet-times {
  display: flex;
  gap: 10px;
  margin: 4px 0 16px;
}

.time-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.time-col > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.time-col select { width: 100%; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: 86vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  text-align: center;
  animation: fade-in 0.15s ease;
}

/* ---------- motion ---------- */

@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
