:root {
  --navy: #1e3a5f;
  --navy-dark: #152a45;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f6f8;
  --card: #ffffff;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --green: #15803d;
  --green-bg: #dcfce7;
  --blue: #1d4ed8;
  --blue-bg: #dbeafe;
  --gray-bg: #f3f4f6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 1px 3px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--navy); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
small, .muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--navy); color: #fff; padding: 10px 24px;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; }
.brand .ez { color: #fbbf24; }
.brand img { background: #fff; border-radius: 6px; padding: 2px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #cbd5e1; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.topbar nav a:hover { color: #fff; background: rgba(255,255,255,0.08); }
.topbar nav a.active { color: #fff; background: rgba(255,255,255,0.15); }

main { max-width: 1100px; margin: 0 auto; padding: 24px 24px 80px; }

/* ---------- Building blocks ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid.fit { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid #d1d5db; background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: #f9fafb; border-color: #9ca3af; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; padding: 4px 6px; color: var(--navy); }
.btn:disabled { opacity: 0.55; cursor: default; }

input[type=text], input[type=email], input[type=date], select, textarea {
  border: 1px solid #d1d5db; border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
label.field { display: block; }
label.check { display: flex; gap: 8px; align-items: baseline; cursor: pointer; }
label.check input { width: 16px; height: 16px; flex-shrink: 0; position: relative; top: 2px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 12px; margin: 0; display: grid; gap: 8px; }
legend { font-size: 13px; font-weight: 600; color: #374151; padding: 0 4px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: #374151; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.banner { border-radius: var(--radius); padding: 12px 16px; border: 1px solid; }
.banner.warn { background: var(--amber-bg); border-color: #fcd34d; color: #78350f; }
.banner.error { background: var(--red-bg); border-color: #fca5a5; color: #7f1d1d; }
.banner.info { background: var(--blue-bg); border-color: #93c5fd; color: #1e3a8a; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.badge.discount_cutoff { background: var(--amber-bg); color: var(--amber); }
.badge.deadline { background: var(--red-bg); color: var(--red); }
.badge.opens { background: var(--blue-bg); color: var(--blue); }
.badge.schedule { background: var(--gray-bg); color: #374151; }
.badge.cat { background: var(--gray-bg); color: #4b5563; font-weight: 500; text-transform: none; letter-spacing: 0; }
.badge.sample { background: #ede9fe; color: #5b21b6; }
.badge.ok { background: var(--green-bg); color: var(--green); }
.badge.err { background: var(--red-bg); color: var(--red); }
.badge.unreviewed { background: #fff; color: #c2410c; border: 1px solid #fdba74; }
.banner.review { background: #fff7ed; border-color: #fdba74; color: #7c2d12; }
.proof { color: var(--green); font-weight: 600; }
.proof a { color: var(--green) !important; }

/* ---------- Home ---------- */
.drop {
  display: block;
  border: 2px dashed #9ca3af; border-radius: var(--radius); background: #fff; padding: 32px 20px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--navy); background: #f0f4f9; }
.drop h2 { margin-bottom: 4px; }
.drop .icon { font-size: 34px; line-height: 1; margin-bottom: 8px; }

.show-card { display: block; text-decoration: none; color: inherit; transition: border-color .15s, transform .15s; }
.show-card:hover { border-color: #9ca3af; transform: translateY(-1px); }
.show-card h3 { font-size: 17px; margin-bottom: 2px; }
.progress { height: 6px; background: var(--gray-bg); border-radius: 999px; overflow: hidden; margin: 12px 0 8px; }
.progress > div { height: 100%; background: var(--green); }
.next-up { font-size: 14px; }

.upcoming { list-style: none; margin: 0; padding: 0; }
.upcoming li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.upcoming li:last-child { border-bottom: 0; }
.upcoming .when { width: 120px; flex-shrink: 0; font-weight: 600; }
.upcoming .when.overdue { color: var(--red); }
.upcoming .when.soon { color: var(--amber); }

/* ---------- Reading progress ---------- */
.reading .spinner { width: 22px; height: 22px; border: 3px solid #cbd5e1; border-top-color: var(--navy); border-radius: 50%; animation: spin 0.9s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.reading .thinking { color: var(--muted); font-style: italic; min-height: 1.5em; font-size: 14px; }
.bar { height: 8px; background: var(--gray-bg); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--navy); transition: width .2s; }

/* ---------- Show page ---------- */
.show-head h1 { margin: 4px 0; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat { padding: 14px 16px; }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 13px; color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid #d1d5db; border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid #d1d5db; }
.seg button.on { background: var(--navy); color: #fff; }
.toolbar select { width: auto; padding: 6px 10px; }

.month { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; margin: 24px 0 8px; }
.tasks { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.task { display: grid; grid-template-columns: 28px 92px 1fr auto; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: start; border-left: 4px solid transparent; }
.task:last-child { border-bottom: 0; }
.task.overdue { border-left-color: var(--red); background: #fffafa; }
.task.soon { border-left-color: #f59e0b; }
.task.closed { opacity: 0.55; }
.task.closed .title { text-decoration: line-through; }
.task input[type=checkbox] { width: 20px; height: 20px; margin-top: 2px; cursor: pointer; accent-color: var(--green); }
.task .date b { display: block; font-size: 15px; }
.task .date small { display: block; }
.task .date .rel { font-weight: 600; font-size: 12px; }
.task .date .rel.overdue { color: var(--red); }
.task .date .rel.soon { color: var(--amber); }
.task .title { font-weight: 600; }
.task .details { margin: 2px 0 6px; color: #374151; font-size: 14px; }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); align-items: center; }
.task .meta a { color: var(--muted); }
.task .money { color: var(--amber); font-weight: 600; }
.task .side { display: flex; gap: 6px; align-items: center; }
.task .side select { width: 150px; padding: 5px 8px; font-size: 13px; }
.task .note { font-size: 13px; background: #fffbeb; border-radius: 6px; padding: 4px 8px; margin-top: 6px; }
.unverified { color: var(--amber); }

.menu { position: relative; }
.menu > button:not(.btn) { border: 0; background: none; cursor: pointer; padding: 4px 8px; border-radius: 6px; font-size: 18px; line-height: 1; color: var(--muted); }
.menu > button:not(.btn):hover { background: var(--gray-bg); }
.menu .items { display: none; position: absolute; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,.12); min-width: 210px; z-index: 5; padding: 4px; }
.menu.open .items { display: block; }
.menu .items button, .menu .items a { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; color: var(--ink); text-decoration: none; font-size: 14px; }
.menu .items button:hover, .menu .items a:hover { background: var(--gray-bg); }

.addresses pre { font: inherit; white-space: pre-wrap; margin: 6px 0; background: var(--gray-bg); border-radius: 6px; padding: 8px 10px; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-plain li:last-child { border-bottom: 0; }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.simple td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 25px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(17, 24, 39, 0.45); }
dialog form { padding: 20px; }
dialog h2 { margin-bottom: 12px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog .pick { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
dialog .pick:has(input:checked) { border-color: var(--navy); background: var(--blue-bg); }
dialog .pick input { margin-top: 4px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---------- Who's using it ---------- */
.who { border: 1px solid rgba(255,255,255,0.25); background: none; color: #e2e8f0; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; margin-right: 6px; }
.who:hover { background: rgba(255,255,255,0.1); color: #fff; }
body.share-mode .topbar nav, body.signed-out .topbar nav { display: none; }
.signin { max-width: 440px; margin: 40px auto 0; }
.signin input[name="code"] { font-size: 22px; letter-spacing: 6px; max-width: 200px; }

/* ---------- Show page tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--navy); border-bottom-color: var(--navy); }
.tabs .count { background: var(--gray-bg); color: var(--muted); border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 2px; }
#tab-body { min-height: 120px; }

.banner.changed { background: #fef2f2; border-color: #fca5a5; color: #7f1d1d; }
.conflict { color: var(--red); font-weight: 600; }
.card.doc h3 { font-size: 16px; }

/* Budget */
.budget-bar { height: 12px; }
.cat-bars { display: grid; gap: 8px; margin-top: 12px; }
.cat-bar { display: grid; grid-template-columns: 150px 1fr 100px; gap: 10px; align-items: center; font-size: 14px; }
.cat-bar b { text-align: right; }
.cat-bar .bar > div { background: #2563eb; }

/* Shipping */
.shipments { display: grid; gap: 10px; }
.shipment { border: 1px solid var(--line); border-left: 4px solid #9ca3af; border-radius: 8px; padding: 10px 12px; }
.shipment.in_transit { border-left-color: #2563eb; }
.shipment.delivered { border-left-color: var(--green); }
.shipment.problem { border-left-color: var(--red); background: #fffafa; }
.shipment select { width: auto; padding: 4px 8px; font-size: 13px; }
.shipment .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.shipment .meta a { color: var(--muted); }
.shipment .note { font-size: 13px; background: #fffbeb; border-radius: 6px; padding: 4px 8px; margin-top: 6px; }

/* Activity */
.activity li { display: grid; grid-template-columns: 130px 1fr; gap: 10px; font-size: 14px; }
.activity .when { color: var(--muted); white-space: nowrap; }

/* Show-day view */
.onsite h1 { font-size: 24px; }
.onsite .card h2 { font-size: 17px; margin-bottom: 6px; }
.onsite .card.today { border: 2px solid var(--navy); }
.onsite li { font-size: 16px; }
.onsite li.done { color: var(--muted); text-decoration: line-through; }
.onsite pre { font: inherit; white-space: pre-wrap; margin: 4px 0; }
.onsite .shipment { margin-top: 8px; }

/* Shared read-only view */
.task.share { grid-template-columns: 28px 92px 1fr; }
.task.share .check { font-size: 18px; }

/* ---------- Review step ---------- */
.review { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 16px; align-items: start; }
.review-date { font-size: 14px; font-weight: 700; color: var(--amber); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 4px; }
.review-item h2 { font-size: 20px; }
.review-item blockquote { margin: 0; padding: 10px 14px; background: var(--gray-bg); border-left: 4px solid var(--navy); border-radius: 6px; font-style: italic; }
.review-item blockquote small { font-style: normal; }
.review-pdf { position: sticky; top: 64px; display: grid; gap: 6px; }
.review-pdf iframe { width: 100%; height: calc(100vh - 120px); min-height: 420px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.review-pdf a { font-size: 13px; }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  .topbar { gap: 8px; }
  .topbar .brand { font-size: 16px; gap: 8px; }
  .topbar nav a { padding: 6px 8px; }
  main { padding: 16px 16px 60px; }
  .task { grid-template-columns: 24px 1fr; }
  .task .date { grid-column: 2; }
  .task .body { grid-column: 1 / -1; }
  .task .side { grid-column: 1 / -1; }
  .task .side select { flex: 1; width: auto; }
  .review { grid-template-columns: 1fr; }
  .btn { white-space: normal; text-align: center; }
  table.simple { display: block; overflow-x: auto; }
  .who { padding: 4px 8px; margin-right: 0; }
  .who .who-name { display: none; }
  .topbar nav a { padding: 6px 7px; font-size: 14px; }
  .topbar nav { gap: 2px; }
  .cat-bar { grid-template-columns: 110px 1fr 80px; }
  .activity li { grid-template-columns: 1fr; gap: 0; }
  .task.share { grid-template-columns: 24px 1fr; }
  .review-pdf { position: static; }
  .review-pdf iframe { height: 60vh; min-height: 0; }
}
