/* Lists — hand-written, dark, mobile-first */
:root {
  --bg: #12151c;
  --bg2: #1a1e28;
  --bg3: #222836;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #7aa2f7;
  --accent2: #9ece6a;
  --danger: #f7768e;
  --warn: #e0af68;
  --border: #2c3444;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(0,0,0,.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; color: inherit; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; width: 100%; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

/* Top bar */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: rgba(18,21,28,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
#topbar-title { font-weight: 700; font-size: 17px; }
.spacer { flex: 1; }
#topbar button, #topbar a {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 10px; font-size: 18px; background: var(--bg2);
}
#topbar button:active, #topbar a:active { background: var(--bg3); }

/* Layout */
#app { max-width: 680px; margin: 0 auto; padding: 16px 14px 40px; }
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

/* Login */
#login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
#login .card { padding: 28px 24px; }
#login h1 { font-size: 22px; margin-bottom: 4px; }
#login p.sub { color: var(--muted); margin-bottom: 20px; font-size: 14px; }
#login label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.btn-primary {
  width: 100%; margin-top: 22px; padding: 13px;
  background: var(--accent); color: #0b0e14; font-weight: 700;
  border-radius: 10px;
}
.btn-primary:active { filter: brightness(.9); }
.toggle-line { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.err { color: var(--danger); font-size: 14px; margin-top: 12px; min-height: 20px; }

/* Dashboard */
.dash-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dash-head h2 { font-size: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.list-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 14px; text-align: left; position: relative;
}
.list-card:active { background: var(--bg3); }
.list-card .emoji { font-size: 34px; display: block; margin-bottom: 8px; }
.list-card .name { font-weight: 700; font-size: 15px; word-break: break-word; }
.list-card .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--bg3); color: var(--muted); margin-top: 8px; text-transform: capitalize;
}
.badge.grocery { color: #9ece6a; }
.badge.todo { color: #7aa2f7; }
.badge.packing { color: #bb9af7; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; font-size: 15px; }
#new-list-btn {
  display: grid; place-items: center; min-height: 110px;
  border: 2px dashed var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: 15px;
}
#new-list-btn:active { background: var(--bg2); }

/* List view */
.list-head { margin-bottom: 14px; }
.list-head .row1 { display: flex; align-items: center; gap: 10px; }
.list-head .emoji { font-size: 28px; }
.list-head h2 { font-size: 20px; flex: 1; word-break: break-word; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 10px; background: var(--bg2); font-size: 17px;
}
.icon-btn:active { background: var(--bg3); }
.list-head .role { font-size: 12px; color: var(--muted); }
.add-row { display: flex; gap: 8px; margin-bottom: 16px; }
.add-row input { flex: 1; }
.add-row button { width: 52px; border-radius: 10px; background: var(--accent); color: #0b0e14; font-size: 22px; font-weight: 700; }

.cat-section { margin-top: 18px; }
.cat-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 6px; margin-bottom: 4px;
}
.cat-head .cnt { background: var(--bg3); border-radius: 12px; padding: 1px 8px; font-size: 11px; }
.item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; border-radius: 10px;
}
.item:active { background: var(--bg3); }
.item + .item { border-top: 1px solid var(--border); }
.item .check {
  width: 26px; height: 26px; flex: none;
  border: 2px solid var(--border); border-radius: 50%;
  font-size: 13px; color: transparent;
}
.item.done .check { background: var(--accent2); border-color: var(--accent2); color: #0b0e14; }
.item .text { flex: 1; font-size: 16px; }
.item.done .text { text-decoration: line-through; color: var(--muted); }
.item.archived { opacity: .55; }
.item .hint { font-size: 12px; color: var(--muted); white-space: nowrap; }
.item .hint .arrow { color: var(--accent); }
.item .warn-flag { color: var(--warn); font-size: 13px; }
.item .menu-btn { color: var(--muted); font-size: 16px; padding: 2px 6px; }
.cat-section .item .text.editing { display: none; }
.inline-edit { flex: 1; }
.item .hint-actions { display: none; }
.item .menu-btn:focus + .hint-actions, .item .menu-btn:active + .hint-actions { display: block; }

/* item action popover */
.popover {
  position: absolute; right: 8px; margin-top: 4px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); z-index: 10; min-width: 150px; padding: 4px;
}
.popover button { display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 7px; font-size: 14px; }
.popover button:active { background: var(--bg2); }
.popover button.danger { color: var(--danger); }

.toolbar { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.chip {
  padding: 7px 12px; border-radius: 20px; font-size: 13px;
  background: var(--bg2); border: 1px solid var(--border); color: var(--muted);
}
.chip.on { color: var(--text); border-color: var(--accent); }

/* Modal */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 440px; max-height: 85vh; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; box-shadow: var(--shadow);
}
.modal h3 { font-size: 17px; margin-bottom: 14px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.modal .btn-primary { margin-top: 16px; }
.modal .cancel { width: 100%; margin-top: 8px; padding: 10px; color: var(--muted); border-radius: 10px; background: var(--bg3); }
.emoji-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.emoji-picker button { width: 40px; height: 40px; border-radius: 9px; font-size: 21px; background: var(--bg3); }
.emoji-picker button.on { outline: 2px solid var(--accent); }
.row-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.row-list .row { display: flex; align-items: center; gap: 10px; background: var(--bg3); border-radius: 10px; padding: 8px 12px; }
.row-list .row .who { flex: 1; font-size: 14px; }
.row-list .row select { width: auto; padding: 6px 8px; font-size: 13px; }
.row-list .row .x { color: var(--danger); font-size: 15px; padding: 4px; }
.add-user-row { display: flex; gap: 8px; margin-top: 12px; }
.add-user-row input { flex: 1; }
.add-user-row select { width: auto; padding: 10px 8px; }
.add-user-row button { background: var(--accent); color: #0b0e14; border-radius: 10px; padding: 0 14px; font-weight: 700; }
.cat-manage .row .edit-form { display: none; }

/* Stats */
.stat-controls { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.stat-controls select { width: auto; padding: 8px 10px; font-size: 14px; }
table.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
table.stats th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.stats td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
table.stats tr:last-child td { border-bottom: none; }
table.stats tr.clickable:active { background: var(--bg3); }
.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar { background: var(--accent); opacity: .85; border-radius: 4px; min-width: 2px; height: 18px; }
.count-num { width: 28px; text-align: right; font-weight: 700; }
.month-bars { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin: 12px 0; }
.month-bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.month-bars .mb { width: 100%; max-width: 26px; background: var(--accent); border-radius: 4px 4px 0 0; }
.month-bars .lbl { font-size: 10px; color: var(--muted); transform: rotate(-35deg); white-space: nowrap; }
.dup-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; background: var(--bg3); margin-top: 8px; font-size: 14px; }
.dup-row .names { flex: 1; }
.dup-row .names .sim { color: var(--muted); font-size: 12px; }
.dup-row button { background: var(--warn); color: #0b0e14; border-radius: 8px; padding: 6px 12px; font-weight: 700; font-size: 13px; }
.stat-meta { font-size: 13px; color: var(--muted); }
.stat-meta b { color: var(--text); }

/* Toast */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 18px; font-size: 14px; z-index: 100; box-shadow: var(--shadow);
  max-width: 90vw; text-align: center;
}
#toast.error { border-color: var(--danger); color: var(--danger); }

@media (min-width: 768px) {
  #app { padding-top: 28px; }
}