:root {
  --paper: #f3ede2;
  --card: #fbf8f2;
  --ink: #1f1a14;
  --muted: #7a6f62;
  --rule: #ddd3c3;
  --accent: #b94a24;
  --accent-soft: #f2dccf;
  --sage: #4f6f52;
  --sage-soft: #dde6d6;
  --amber: #a86d12;
  --amber-soft: #f4e5c4;
  --display: "Fraunces", Georgia, serif;
  --body: "Atkinson Hyperlegible", "Avenir Next", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(31, 26, 20, 0.06) 1px, transparent 0) 0 0 / 22px 22px,
    var(--paper);
  color: var(--ink);
  font: 17px/1.4 var(--body);
  min-height: 100dvh;
}

h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; letter-spacing: -0.01em; }

.eyebrow {
  margin: 0 0 2px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

button { font: inherit; color: inherit; cursor: pointer; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--rule);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}

input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
label > input, label > select, label > textarea { margin-top: 5px; }

/* Login */
#login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%);
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 6px 6px 0 var(--ink);
}
.login-card h1 { font-size: 44px; margin-bottom: 22px; }
.error { color: var(--accent); min-height: 1.4em; margin: 10px 0 0; font-size: 15px; }

/* App shell */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px 12px;
  background: linear-gradient(var(--paper) 75%, rgba(243, 237, 226, 0));
}
.top h1 { font-size: 34px; }

.live {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--rule);
  margin-bottom: 12px;
  transition: background 0.3s;
}
.live.on { background: var(--sage); box-shadow: 0 0 0 4px var(--sage-soft); }
.live.pulse { animation: pulse 0.8s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(79, 111, 82, 0.6); } 100% { box-shadow: 0 0 0 12px rgba(79, 111, 82, 0); } }

main { padding: 0 16px calc(110px + var(--safe-bottom)); }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(6px + var(--safe-bottom));
  background: rgba(251, 248, 242, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1.5px solid var(--ink);
}
.tabs button {
  background: none;
  border: 0;
  padding: 6px 0;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tabs .glyph { font-size: 20px; line-height: 1; }
.tabs button.active { color: var(--ink); font-weight: 700; }
.tabs button.active .glyph { color: var(--accent); }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 9;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform 0.1s;
}
.fab:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.fab[hidden] { display: none; }

/* Sections and rows */
.section { margin: 8px 0 22px; animation: rise 0.35s ease-out both; }
.section:nth-child(2) { animation-delay: 0.05s; }
.section:nth-child(3) { animation-delay: 0.1s; }
.section:nth-child(4) { animation-delay: 0.15s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.section h3 {
  font-size: 15px;
  font-family: var(--body);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  margin: 0 4px 8px;
}
.count { font-family: var(--display); color: var(--ink); letter-spacing: 0; }

.card {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 14px;
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px dashed var(--rule);
}
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 700; overflow-wrap: anywhere; }
.row .meta { font-size: 14px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.row .tap { background: none; border: 0; padding: 0; text-align: left; flex: 1; min-width: 0; }

.empty { padding: 18px 14px; color: var(--muted); font-style: italic; }
.empty.big { text-align: center; padding: 40px 20px; font-family: var(--display); font-style: normal; font-size: 20px; color: var(--ink); }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.red { background: var(--accent-soft); color: var(--accent); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--sage-soft); color: var(--sage); }
.badge.plain { background: var(--paper); color: var(--muted); }

.date-block {
  width: 48px;
  text-align: center;
  border-right: 1px dashed var(--rule);
  padding-right: 10px;
  flex-shrink: 0;
}
.date-block .day { font-family: var(--display); font-size: 24px; font-weight: 700; line-height: 1; }
.date-block .mon { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }

.done-btn {
  border: 1.5px solid var(--ink);
  background: var(--sage-soft);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.done-btn:active { background: var(--sage); color: #fff; }

.stepper { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.stepper button {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: #fff;
  font-size: 20px;
  line-height: 1;
}
.stepper button:active { background: var(--ink); color: #fff; }
.stepper .qty { min-width: 46px; text-align: center; font-family: var(--display); font-weight: 700; font-size: 18px; }
.stepper .qty small { display: block; font-family: var(--body); font-weight: 400; font-size: 11px; color: var(--muted); }

/* Items toolbar */
.toolbar { position: sticky; top: 92px; z-index: 4; padding: 0 0 10px; background: var(--paper); }
.search { position: relative; }
.search input { padding-left: 38px; border-color: var(--ink); background: var(--card); }
.search::before { content: "\2315"; position: absolute; left: 13px; top: 8px; font-size: 20px; color: var(--muted); }
.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.chip {
  border: 1.5px solid var(--ink);
  background: transparent;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 14px;
  white-space: nowrap;
}
.chip.active { background: var(--ink); color: var(--paper); }

.loc-head {
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 16px 4px 6px;
  font-weight: 700;
}

.settings { margin-top: 30px; font-size: 14px; color: var(--muted); }
.settings code {
  display: block;
  margin: 6px 0 10px;
  padding: 10px;
  background: var(--card);
  border: 1px dashed var(--rule);
  border-radius: 8px;
  font-size: 12px;
  overflow-wrap: anywhere;
  color: var(--ink);
}
.settings button { margin-right: 8px; }

button.primary {
  width: 100%;
  padding: 13px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
}
button.ghost {
  padding: 8px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
}

/* Sheet */
dialog {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  padding: 0 20px calc(20px + var(--safe-bottom));
  border: 0;
  border-top: 1.5px solid var(--ink);
  border-radius: 20px 20px 0 0;
  background: var(--card);
  color: var(--ink);
  max-height: 92dvh;
}
dialog[open] { animation: sheet-up 0.25s ease-out; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
dialog::backdrop { background: rgba(31, 26, 20, 0.4); }

.sheet-head {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 16px 0 14px;
  margin-bottom: 8px;
  background: var(--card);
  border-bottom: 1px dashed var(--rule);
}
.sheet-head h2 { font-size: 20px; text-align: center; }
.sheet-head .link:last-child { justify-self: end; }
.link { background: none; border: 0; color: var(--accent); padding: 4px 0; justify-self: start; }
.link.strong { font-weight: 700; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

button.danger {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}
button.danger[hidden] { display: none; }

@media (min-width: 700px) {
  main { max-width: 640px; margin: 0 auto; }
  .top { max-width: 672px; margin: 0 auto; }
}

select {
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231f1a14' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
  padding-right: 32px;
}

.pw-field { position: relative; display: block; margin-top: 5px; }
.pw-field input { margin-top: 0; padding-right: 48px; }
.pw-toggle {
  position: absolute;
  right: 4px; top: 50%;
  transform: translateY(-50%);
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; background: none;
  color: var(--muted);
}
.pw-toggle[aria-pressed="true"] { color: var(--ink); }
.pw-toggle[aria-pressed="true"] .slash { display: none; }

.hint { font-size: 14px; color: var(--muted); margin: 4px 4px 0; }

.search-row { display: flex; gap: 8px; }
.search-row .search { flex: 1; }
.scan-btn {
  width: 46px;
  flex-shrink: 0;
  display: grid; place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
}
.scan-btn:active { transform: translate(1px, 1px); }

.scan-thumb {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  margin-bottom: 14px;
}
.scan-status { text-align: center; color: var(--muted); padding: 24px 0; animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.45; } }
.scan-list { display: grid; gap: 10px; margin-bottom: 8px; }
.scan-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border: 1.5px solid var(--rule);
  border-radius: 12px;
  background: #fff;
}
.scan-row:has(.scan-keep:not(:checked)) { opacity: 0.45; }
.scan-keep { width: 22px; height: 22px; margin-top: 12px; accent-color: var(--accent); -webkit-appearance: auto; appearance: auto; flex-shrink: 0; }
.scan-fields { flex: 1; min-width: 0; display: grid; gap: 8px; }
.scan-fields input, .scan-fields select { padding: 9px 10px; }
.scan-grid { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; }
.scan-exp { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 13px; }
.scan-exp input { margin-top: 0; }
button[type=submit]:disabled { opacity: 0.35; }

.quick-add { flex: 1; }
.quick-add input { border-color: var(--ink); background: var(--card); }
.check-btn {
  width: 28px; height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: #fff;
  position: relative;
}
.is-checked .check-btn { background: var(--sage); border-color: var(--sage); }
.is-checked .check-btn::after {
  content: "";
  position: absolute;
  left: 9px; top: 4px;
  width: 6px; height: 12px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.is-checked .title { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.section h3 .link { font-size: 14px; letter-spacing: 0; text-transform: none; }
.scan-grid.two { grid-template-columns: 1fr 1fr; }

/* Assistant */
.ask-fab {
  position: fixed;
  left: 18px;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 9;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: var(--card);
  color: var(--ink);
  display: grid; place-items: center;
  box-shadow: 3px 3px 0 var(--ink);
}
.ask-fab:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

#chat {
  height: 88dvh;
  display: none;
  flex-direction: column;
  padding-bottom: calc(12px + var(--safe-bottom));
}
#chat[open] { display: flex; }
.chat-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 16px 0 12px;
  border-bottom: 1px dashed var(--rule);
}
.chat-head h2 { font-size: 20px; }
.chat-head-right { justify-self: end; display: flex; gap: 12px; align-items: center; }
.live-toggle {
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  padding: 3px 12px;
  font-size: 13px;
  font-weight: 700;
}
.live-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; animation: breathe 1.6s ease-in-out infinite; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px 0; display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.user { align-self: flex-end; background: var(--ink); color: var(--paper); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: #fff; border: 1.5px solid var(--rule); border-bottom-left-radius: 4px; }
.bubble.pending { color: var(--muted); animation: breathe 1.4s ease-in-out infinite; }
.bubble.error { align-self: flex-start; background: var(--accent-soft); color: var(--accent); }
.bubble.hint { align-self: center; max-width: 100%; color: var(--muted); font-size: 14px; text-align: center; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; padding-top: 10px; border-top: 1px dashed var(--rule); }
.chat-form textarea { resize: none; max-height: 120px; border-color: var(--ink); }
.chat-mic, .chat-send {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  display: grid; place-items: center;
}
.chat-mic { background: #fff; }
.chat-mic.on { background: var(--accent); border-color: var(--accent); color: #fff; animation: breathe 1.2s ease-in-out infinite; }
.chat-send { background: var(--ink); color: var(--paper); font-size: 20px; }
.settings-gap { margin-top: 22px; }
.chat-status { min-height: 1.3em; margin: 0; font-size: 13px; color: var(--muted); text-align: center; }
.chat-mic.speaking { background: var(--sage-soft); border-color: var(--sage); }
.chat-memory { flex: 1; overflow-y: auto; padding: 12px 0; }
.chat-memory[hidden], .chat-log[hidden] { display: none !important; }
.memory-form { display: flex; gap: 8px; margin: 10px 0 14px; }
.memory-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px dashed var(--rule); }
.memory-row span { flex: 1; overflow-wrap: anywhere; }
.checkin-note { padding: 14px; line-height: 1.45; }
.chat-attach {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: #fff;
  display: grid; place-items: center;
}
.chat-attachments { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 8px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%;
  padding: 4px 6px 4px 4px;
  border: 1.5px solid var(--rule);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
}
.attach-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.attach-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.attach-chip.uploading { opacity: 0.55; }
.bubble-photo { display: block; max-width: 100%; max-height: 220px; border-radius: 10px; margin-bottom: 6px; }
.bubble-file { display: block; margin-bottom: 6px; color: inherit; font-weight: 700; text-decoration: underline; overflow-wrap: anywhere; }
