/* ============================================================
   Sticky — a small window that should feel like paper on a desk,
   not a web page. Sized to live at ~380px wide, but it scales up
   to a full phone screen without changing character.
   ============================================================ */

:root {
  color-scheme: light dark;

  --paper:      #fdf6dd;
  --paper-2:    #f9edc8;
  --edge:       #e8d9a8;
  --ink:        #2f2a1d;
  --ink-soft:   #6d6449;
  --ink-faint:  #9b9078;
  --accent:     #b8860b;
  --accent-ink: #4a3805;
  --shadow:     0 1px 2px rgba(60,50,20,.10), 0 6px 18px rgba(60,50,20,.10);

  --p1: #c0392b;
  --p2: #b8860b;
  --p3: #6b7f8a;

  --overdue:  #c0392b;
  --today:    #b8600b;

  --radius: 10px;
  --tap: 40px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI",
          system-ui, Roboto, "Helvetica Neue", sans-serif;
}

:root[data-theme="dark"],
html.dark {
  --paper:      #211f1a;
  --paper-2:    #2a2721;
  --edge:       #3b372e;
  --ink:        #ece6d6;
  --ink-soft:   #b3ab96;
  --ink-faint:  #7d765f;
  --accent:     #e0b64a;
  --accent-ink: #f5e2ac;
  --shadow:     0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.35);
  --p1: #e8695a;
  --p2: #e0b64a;
  --p3: #8fa6b2;
  --overdue: #e8695a;
  --today:   #e0a04a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #211f1a;
    --paper-2:    #2a2721;
    --edge:       #3b372e;
    --ink:        #ece6d6;
    --ink-soft:   #b3ab96;
    --ink-faint:  #7d765f;
    --accent:     #e0b64a;
    --accent-ink: #f5e2ac;
    --shadow:     0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.35);
    --p1: #e8695a;
    --p2: #e0b64a;
    --p3: #8fa6b2;
    --overdue: #e8695a;
    --today:   #e0a04a;
  }
}

* { box-sizing: border-box; }

/* Several panels below set display: flex/grid, which would otherwise beat the
   browser's own rule for [hidden] and leave invisible panels catching clicks. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { display: flex; }

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-height: 100vh;
  background:
    linear-gradient(var(--paper), var(--paper));
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------------- title bar ---------------- */

.bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--edge);
  -webkit-app-region: drag;            /* lets you drag the frameless window */
  padding-top: max(8px, env(safe-area-inset-top));
  flex: none;
}

.grip {
  width: 14px; height: 10px;
  background-image: radial-gradient(var(--ink-faint) 1px, transparent 1px);
  background-size: 4px 4px;
  opacity: .6;
}

.bar-title { display: flex; align-items: baseline; gap: 5px; margin-right: auto; }
.count { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.count-label { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .07em; }

.bar-actions { display: flex; gap: 2px; -webkit-app-region: no-drag; }

.icon-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 0; border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px; line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(128,110,60,.14); color: var(--ink); }

.sync {
  position: absolute; left: 0; top: 0;
  width: 100%; height: 2px;
  background: transparent;
  transition: background .3s;
}
.sync.live  { background: linear-gradient(90deg, transparent, var(--accent), transparent); opacity: .55; }
.sync.error { background: var(--overdue); opacity: .8; }
.sync.busy  { background: var(--accent); opacity: .35; }

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

.auth { padding: 34px 22px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.auth-title { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.auth-sub { margin: 0 0 8px; color: var(--ink-soft); font-size: 13px; }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-msg { min-height: 18px; margin: 4px 0 0; font-size: 12.5px; color: var(--overdue); }
.auth-msg.ok { color: var(--accent-ink); }
.auth-hint { margin-top: 18px; font-size: 12px; color: var(--ink-faint); line-height: 1.5; }

.setup-step { margin: 4px 0 2px; font-size: 13.5px; color: var(--ink-soft); line-height: 1.55; }
.setup-step code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .92em; background: rgba(128,110,60,.16);
  padding: 1px 4px; border-radius: 4px; color: var(--ink);
}
.setup-code { position: relative; margin: 6px 0 10px; }
.setup-code pre {
  margin: 0; padding: 11px 12px;
  background: var(--paper-2);
  border: 1px solid var(--edge);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px; line-height: 1.6;
  color: var(--ink);
  overflow-x: auto;
  white-space: pre;
}
.copy-btn {
  position: absolute; top: 7px; right: 7px;
  border: 1px solid var(--edge); background: var(--paper);
  color: var(--ink-soft); border-radius: 6px;
  font: inherit; font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase;
  padding: 4px 8px; cursor: pointer;
}
.copy-btn:hover { color: var(--ink); border-color: var(--accent); }

.field {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--paper-2);
  color: var(--ink);
  font: inherit;
  font-size: 16px;               /* 16px stops iOS zooming on focus */
}
.field:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit; font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #221a02; }
.btn.ghost { background: transparent; color: var(--ink-soft); border-color: var(--edge); }
.btn:hover { filter: brightness(1.05); }

/* ---------------- main ---------------- */

.main { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.add {
  position: relative;
  display: flex; flex-direction: column; gap: 7px;
  padding: 10px 10px 9px;
  flex: none;
  border-bottom: 1px solid var(--edge);
}

.add-top { display: flex; gap: 6px; }

.add-input {
  flex: 1; min-width: 0;
  min-height: var(--tap);
  padding: 9px 12px;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--paper-2);
  color: var(--ink);
  font: inherit; font-size: 16px;
}
.add-input::placeholder { color: var(--ink-faint); }
.add-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.add-btn {
  width: var(--tap); min-height: var(--tap);
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: #221a02;
  font-size: 20px; font-weight: 700; line-height: 1;
  cursor: pointer; flex: none;
}
.add-btn:hover { filter: brightness(1.06); }

/* the four field boxes */
.add-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.fld { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fld-label {
  font-size: 9.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-faint); padding-left: 2px;
}
.fld select, .fld input {
  width: 100%; min-width: 0;
  min-height: 34px;
  padding: 6px 7px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  background: var(--paper-2);
  color: var(--ink);
  font: inherit; font-size: 13px;
}
.fld select:focus, .fld input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.fld input[type="date"], .fld input[type="time"] { font-variant-numeric: tabular-nums; }
/* a date/time input with no value should read as empty, not as a stack of dashes */
.fld input:not(:focus):invalid { color: var(--ink-faint); }

.new-project {
  width: 100%;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--paper-2);
  color: var(--ink);
  font: inherit; font-size: 13px;
}
.new-project:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.quickdates { display: flex; flex-wrap: wrap; gap: 4px; }
.qd {
  border: 1px solid var(--edge);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 4px 9px;
  font: inherit; font-size: 11px;
  cursor: pointer;
}
.qd:hover { border-color: var(--accent); color: var(--ink); }
.qd[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #221a02; font-weight: 600; }
.qd-clear { margin-left: auto; color: var(--ink-faint); }
.qd-clear:hover { color: var(--overdue); border-color: var(--overdue); }

/* ---------------- controls ---------------- */

.controls {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 10px 8px;
  flex: none;
}

.seg { display: flex; background: var(--paper-2); border: 1px solid var(--edge); border-radius: 8px; padding: 2px; }
.seg-btn {
  border: 0; background: transparent;
  padding: 5px 8px; border-radius: 6px;
  font: inherit; font-size: 11.5px; color: var(--ink-soft);
  cursor: pointer; white-space: nowrap;
}
.seg-btn[aria-pressed="true"] { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.10); }

.chip-btn {
  margin-left: auto;
  border: 1px solid var(--edge); background: var(--paper-2);
  border-radius: 8px; padding: 6px 9px;
  font: inherit; font-size: 11.5px; color: var(--ink-soft);
  cursor: pointer; display: flex; align-items: center; gap: 4px;
  max-width: 45%;
}
.chip-btn.on { color: var(--ink); font-weight: 600; border-color: var(--accent); }
.chip-btn > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { font-size: 9px; opacity: .7; flex: none; }

.filters { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 10px 8px; flex: none; }
.f-chip {
  border: 1px solid var(--edge); background: var(--paper-2);
  border-radius: 999px; padding: 5px 10px;
  font: inherit; font-size: 11.5px; color: var(--ink-soft);
  cursor: pointer;
}
.f-chip[aria-pressed="true"] { background: var(--accent); color: #221a02; border-color: var(--accent); font-weight: 600; }

/* ---------------- list ---------------- */

.list { flex: 1; overflow-y: auto; padding: 0 6px 8px; -webkit-overflow-scrolling: touch; }

.group-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: baseline; gap: 6px;
  padding: 8px 6px 4px;
  background: linear-gradient(var(--paper) 70%, transparent);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-soft);
}
.group-head .n { font-weight: 500; color: var(--ink-faint); letter-spacing: 0; text-transform: none; }
.group-head.warn { color: var(--overdue); }

.item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 8px 8px 6px;
  border-radius: 8px;
  border-left: 3px solid transparent;
  cursor: default;
}
.item:hover { background: var(--paper-2); }
.item.p1 { border-left-color: var(--p1); }
.item.p2 { border-left-color: var(--p2); }
.item.p3 { border-left-color: var(--p3); }
.item.done .title { text-decoration: line-through; color: var(--ink-faint); }
.item.done { opacity: .62; }
.item.flash { animation: flash 1.1s ease-out; }
@keyframes flash {
  0%   { background: rgba(184,134,11,.30); }
  100% { background: transparent; }
}

.check {
  flex: none;
  width: 19px; height: 19px; margin-top: 1px;
  border: 1.5px solid var(--ink-faint);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  display: grid; place-items: center;
  color: transparent;
  font-size: 12px; line-height: 1;
  padding: 0;
}
.check:hover { border-color: var(--accent); }
.check[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: #221a02; }

.body { flex: 1; min-width: 0; }

.title {
  font-size: 13.5px; line-height: 1.35;
  word-break: break-word;
  cursor: text;
  border-radius: 4px;
  padding: 1px 3px; margin: -1px -3px;
}
.title:focus { outline: 2px solid var(--accent); outline-offset: 0; background: var(--paper-2); }

.meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 3px; }
.meta:empty { display: none; }

.tag {
  font-size: 10.5px; line-height: 1;
  padding: 3px 6px; border-radius: 999px;
  background: rgba(128,110,60,.14);
  color: var(--ink-soft);
  white-space: nowrap;
}
.tag.due.overdue { background: rgba(192,57,43,.16); color: var(--overdue); font-weight: 600; }
.tag.due.today   { background: rgba(184,96,11,.16);  color: var(--today);   font-weight: 600; }
.tag.pri1 { color: var(--p1); }
.tag.pri2 { color: var(--p2); }
.tag.pri3 { color: var(--p3); }
.tag.note { font-style: italic; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tag.siri { background: transparent; border: 1px solid var(--edge); color: var(--ink-faint); letter-spacing: .04em; }

.row-actions { display: flex; gap: 1px; opacity: 0; flex: none; transition: opacity .12s; }
.item:hover .row-actions, .item:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }

.mini {
  width: 26px; height: 26px;
  border: 0; border-radius: 6px; background: transparent;
  color: var(--ink-faint); cursor: pointer;
  font-size: 12px; line-height: 1;
  display: grid; place-items: center; padding: 0;
}
.mini:hover { background: rgba(128,110,60,.18); color: var(--ink); }
.mini.del:hover { color: var(--overdue); }

/* inline editor — same controls as the add form */
.editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 8px;
  padding: 8px;
  background: var(--paper-2);
  border: 1px solid var(--edge);
  border-radius: 8px;
}
.editor .fld-label { font-size: 9px; }
.editor input, .editor select {
  width: 100%; min-width: 0;
  border: 1px solid var(--edge); border-radius: 6px;
  background: var(--paper); color: var(--ink);
  font: inherit; font-size: 12.5px; padding: 6px 7px;
  min-height: 32px;
}
.editor .e-notes-wrap, .editor .e-newproj-wrap { grid-column: 1 / -1; }
.editor .editor-done { grid-column: 1 / -1; justify-self: end; }
.editor .editor-done button {
  border: 0; background: var(--accent); color: #221a02;
  border-radius: 6px; padding: 6px 14px; font: inherit; font-size: 12px;
  font-weight: 600; cursor: pointer; min-height: 30px;
}

/* ---------------- empty / footer ---------------- */

.empty {
  margin: 26px 18px; text-align: center;
  color: var(--ink-faint); font-size: 12.5px; line-height: 1.6;
}
.empty-mark { display: block; font-size: 24px; color: var(--accent); opacity: .55; margin-bottom: 6px; }
.empty em { color: var(--ink-soft); }

.foot {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border-top: 1px solid var(--edge);
  background: var(--paper-2);
  flex: none;
}
.link-btn { border: 0; background: transparent; color: var(--ink-soft); font: inherit; font-size: 11.5px; cursor: pointer; padding: 4px 0; }
.link-btn:hover { color: var(--ink); text-decoration: underline; }
.foot-count { margin-left: auto; font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* ---------------- menu / sheet / toast ---------------- */

.menu {
  position: absolute; right: 8px; top: 40px; z-index: 20;
  min-width: 176px; padding: 5px;
  background: var(--paper-2);
  border: 1px solid var(--edge); border-radius: 10px;
  box-shadow: var(--shadow);
}
.menu-item {
  display: block; width: 100%;
  border: 0; background: transparent;
  text-align: left; padding: 8px 10px; border-radius: 7px;
  font: inherit; font-size: 12.5px; color: var(--ink); cursor: pointer;
}
.menu-item:hover { background: rgba(128,110,60,.16); }
.menu-item.danger { color: var(--overdue); }
.menu-sep { border: 0; border-top: 1px solid var(--edge); margin: 4px 2px; }

.sheet {
  position: absolute; inset: 0; z-index: 30;
  background: rgba(20,16,6,.42);
  display: grid; place-items: center;
  padding: 16px;
}
.sheet-inner {
  width: 100%; max-width: 340px;
  background: var(--paper); border: 1px solid var(--edge);
  border-radius: 12px; padding: 16px;
  box-shadow: var(--shadow);
  max-height: 100%; overflow-y: auto;
}
.sheet h2 { margin: 0 0 10px; font-size: 15px; }
.help-list { margin: 0 0 12px; font-size: 12.5px; }
.help-list dt { margin-top: 8px; }
.help-list dd { margin: 2px 0 0 0; color: var(--ink-soft); }
.help-eg {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px; background: var(--paper-2);
  border: 1px solid var(--edge); border-radius: 7px;
  padding: 8px; color: var(--ink-soft); margin: 0 0 12px;
}
code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .92em;
  background: rgba(128,110,60,.15);
  padding: 1px 4px; border-radius: 4px;
}

.toast {
  position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%);
  z-index: 40;
  background: var(--ink); color: var(--paper);
  padding: 8px 13px; border-radius: 999px;
  font-size: 12px; box-shadow: var(--shadow);
  max-width: 88%; text-align: center;
  pointer-events: none;      /* never swallow a click meant for the list */
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
