:root {
  color-scheme: light dark;
  --bg: #f5f5f2;
  --card-bg: #fff;
  --border: #ddd;
  --text: #1a1a1a;
  --muted: #666;
  --accent: #1a5c3a;
  --accent-contrast: #fff;
  --danger: #b3261e;
  --dir-in: #1a5c3a;
  --dir-out: #b3261e;
  /* One color per settlement status, so every rung of the ladder reads at
     a glance -- badge class is the raw status string (see
     _card_macro.html), 'debts' for is_debt rows. */
  --badge-active: #b3261e;
  --badge-inmail: #8a6d00;
  --badge-history: #666;
  --badge-debt: #5b3a9c;
  --badge-need-contact: #d35400;
  --badge-winner-contacted: #16a085;
  --badge-tracking-sent: #34495e;
  --badge-delivered: #66bb6a;
  --badge-delivered-text: #123d14;
  --badge-awaiting: #f1c40f;
  --badge-awaiting-text: #4a3800;
  --badge-tracking-received: #4fc3f7;
  --badge-tracking-received-text: #063954;
  --badge-received: #1b5e20;
  /* Supply module: one color per item status / fulfillment status.
     .badge.sold reuses --accent below (declared inline since it's already
     themed); .badge.tracking_sent and .badge.shipped reuse the settlement
     badges of the same name above -- both domains mean the same real-world
     thing, so sharing the class/color is a feature, not a collision. */
  --badge-supply-unlisted: #8a6d00;
  --badge-supply-listed: #34495e;
  --badge-supply-declined: #666;
  /* .badge.accepted reuses --badge-winner-contacted's teal -- both mark a
     positive interim step before the item/shipment is actually live. */
  font-size: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --card-bg: #212426;
    --border: #35393c;
    --text: #eee;
    --muted: #aaa;
    --accent: #4caf7d;
    --accent-contrast: #08130d;
    --dir-in: #4caf7d;
    --dir-out: #ff6b5b;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 84px;
}
header.topbar {
  position: sticky;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
}
header.topbar h1 { font-size: 1.1rem; margin: 0; }
header.topbar a.logout { color: var(--accent-contrast); font-size: 0.85rem; text-decoration: underline; }

nav.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  position: sticky;
  top: 48px;
  z-index: 4;
}
nav.tabs a {
  flex: 1;
  text-align: center;
  padding: 12px 4px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
}
nav.tabs a.active { color: var(--accent); font-weight: 600; border-bottom: 2px solid var(--accent); }

/* Settings page's sub-tabs (account.html/initSettingsTabs) -- same
   underline-active look as nav.tabs above, but scoped to the page content
   instead of the fixed top nav, and horizontally scrollable rather than
   evenly squeezed -- there are more of these than fit comfortably at
   phone width, and scrolling reads better than truncated labels. */
.subtabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.subtabs button {
  flex: 0 0 auto;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}
.subtabs button.active { color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); }

main { padding: 12px; max-width: 640px; margin: 0 auto; }

.totals-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.totals-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.totals-bar .bar-unit {
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 36px;
  flex-shrink: 0;
}
.totals-bar .bar-metric {
  flex: 1;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
}
.totals-bar .bar-metric b {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 14px;
}
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.status-chip-count {
  font-size: 0.85rem;
  font-weight: 700;
}

.search-box {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 16px;
}

.sort-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

/* Profile list row: name-only, links to the Profile detail page (see
   person_detail.html) -- unlike settlement/supply cards, this is a plain
   div (not a <details>), since there's nothing to expand in place any
   more. The edit icon sits outside the name link so tapping it doesn't
   also navigate to the detail page. */
.person-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
}
.person-row .person-link {
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}
.person-row .person-link .person {
  font-weight: 600;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Reminder list row (Home tab / a Profile's Reminders section) -- same
   shape as .person-row above: a plain (non-expanding) card, short title
   flex-1, edit pencil at the end. The title itself is a <button> (not a
   link) since tapping it opens the actions dialog rather than navigating
   anywhere -- see _reminder_macro.html. */
.reminder-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
}
.reminder-row .reminder-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.reminder-row .critical-mark { flex-shrink: 0; }
.reminder-row .reminder-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reminder-body-text { font-size: 0.9rem; color: var(--text); white-space: pre-line; margin: 10px 0 0; }

section.group { margin-bottom: 20px; }
section.group h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 8px 2px;
}

/* Cards are <details> elements: the whole card is the tap target to
   expand/collapse (tracking #, dates, status actions live in the
   collapsed-away part), except the edit link, which stops propagation so
   it navigates to the full edit page instead of toggling the card. */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  overflow: hidden;
}
.card summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 14px;
}
.card summary::-webkit-details-marker { display: none; }
.card summary::marker { content: ""; }

.card-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-row1 .dir-icon { font-size: 1.2rem; }
.card-row1 .dir-label {
  display: inline-block;
  min-width: 2.4em;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-align: center;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1.5px solid currentColor;
  white-space: nowrap;
}
.card-row1 .dir-label.in { color: var(--dir-in); }
.card-row1 .dir-label.out { color: var(--dir-out); }
.card-row1 .person { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-row1 .qty { font-weight: 600; white-space: nowrap; }
.card-row1 .edit-link { color: var(--muted); text-decoration: none; font-size: 1.1rem; padding: 4px; }

/* Manual drag-reorder handle (see app.js's initDragReorder) -- sits last
   in card-row1, so it lands top-right of the card same as the edit link
   next to it. touch-action:none stops the browser's own scroll gesture
   from competing with a touch-drag started on the handle; the handle's
   own onclick (_card_macro.html) stops a plain tap from toggling the
   <details> open, same guard as .edit-link's. */
.card-row1 .drag-handle {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  padding: 4px 6px;
  cursor: grab;
  touch-action: none;
  flex-shrink: 0;
}
.card-row1 .drag-handle:active { cursor: grabbing; }
.card.dragging {
  opacity: 0.6;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.card-row1 .chevron {
  color: var(--muted);
  font-size: 0.75rem;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.card[open] .card-row1 .chevron { transform: rotate(180deg); }

.card-row2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
/* Row 3 is the same shape as row 2 (one line, muted, truncates instead of
   wrapping or growing the card) but only ever holds row.details -- kept as
   its own row so a long carrier status on row 2 and a long details string
   here don't fight each other for space and both get to show as much as
   they can before ellipsizing. */
.card-row3 { display: flex; margin-top: 6px; }
.card-row2 .details-inline, .card-row3 .details-inline {
  font-size: 0.85rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tracking shown right on the collapsed card (_card_macro.html) --
   flex:0 0 auto overrides .details-inline's own flex:1/ellipsis (in case
   row.details is also present and would otherwise fight it for space) so
   the tracking number/link always stays fully visible and never gets
   truncated. */
.card-row2 .track-inline { flex: 0 0 auto; color: var(--muted); }
.card-row2 .track-link-inline {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.badge {
  display: inline-block;
  flex-shrink: 0;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
}
.badge.need_to_contact_winner { background: var(--badge-need-contact); }
.badge.winner_contacted { background: var(--badge-winner-contacted); }
.badge.need_to_ship { background: var(--badge-active); }
.badge.shipped { background: var(--badge-inmail); }
.badge.tracking_sent { background: var(--badge-tracking-sent); }
.badge.delivered_outgoing, .badge.delivered_incoming {
  background: var(--badge-delivered);
  color: var(--badge-delivered-text);
}
.badge.awaiting_tracking {
  background: var(--badge-awaiting);
  color: var(--badge-awaiting-text);
}
.badge.tracking_received {
  background: var(--badge-tracking-received);
  color: var(--badge-tracking-received-text);
}
.badge.received { background: var(--badge-received); }
.badge.history { background: var(--badge-history); }
.badge.debts { background: var(--badge-debt); }
.badge.paid, .badge.won { background: var(--accent); }
.badge.unpaid { background: var(--badge-active); }
.badge.lost { background: var(--danger); }

/* Phase 2 shared debt items: .badge.shared marks a row already linked to
   a friend's own mirrored row; .badge.pending marks one still awaiting
   their accept/decline (reuses the tracking-awaited yellow, same
   "something's still needed" meaning as .badge.awaiting_tracking). */
.badge.shared { background: var(--accent); color: var(--accent-contrast); }
.badge.pending { background: var(--badge-awaiting); color: var(--badge-awaiting-text); }

/* Supply module -- item status ladder + fulfillment ladder. */
.badge.unlisted { background: var(--badge-supply-unlisted); }
.badge.accepted { background: var(--badge-winner-contacted); }
.badge.listed { background: var(--badge-supply-listed); }
.badge.sold { background: var(--accent); color: var(--accent-contrast); }
.badge.declined { background: var(--badge-supply-declined); }
.badge.label_created { background: var(--badge-need-contact); }
.badge.packaged { background: var(--badge-tracking-received); color: var(--badge-tracking-received-text); }

/* Account page's Friends section: a pending-request or accepted-friend
   row, same flex shape as .person-row but with an action button (or two)
   at the end instead of an edit pencil. */
.friend-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
}
.friend-row .friend-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
}
.friend-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.friend-row form { margin: 0; }
.friend-actions button {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.82rem;
}
.friend-actions button.muted {
  background: none;
  border-color: var(--muted);
  color: var(--muted);
}
.friend-actions button.danger {
  background: none;
  border-color: var(--danger);
  color: var(--danger);
}

/* Nav tab "unseen" indicator (Supply module's in-app notification tier). */
.nav-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  margin-left: 3px;
  vertical-align: super;
}

.card-expanded { padding: 0 14px 12px; }
.debt-line { padding: 10px 0; border-top: 1px solid var(--border); }
.debt-line:first-child { border-top: none; padding-top: 0; }
.tracking { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.track-link { margin-left: 8px; color: var(--accent); text-decoration: none; font-weight: 600; }
.dates { font-size: 0.78rem; color: var(--muted); margin-top: 6px; }

/* Shipping-label / item photo attachments (see photos.py) -- thumbnail
   strip with a small delete "x" overlaid on each, and (below, via
   .photo-upload-label) a file input styled to match .settle-btn instead of
   showing the browser's default file-picker control. */
.card-photos:not(:empty) { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.card-photo { position: relative; width: 72px; height: 72px; flex: 0 0 auto; }
.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}
.photo-delete-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  line-height: 20px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
}
/* Label/Delivery photos are the two shared-with-your-friend slots (see
   photos.py's kind= param) -- this badge is what distinguishes one from an
   ordinary private photo on the same card, for both the uploader and
   whoever it's shared with. */
.photo-kind-badge {
  position: absolute;
  bottom: 2px;
  left: 2px;
  right: 2px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.62rem;
  text-align: center;
  line-height: 1.3;
}
.photo-upload-label { cursor: pointer; }
.photo-upload-label input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.card-actions button, .settle-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.85rem;
}
/* Phase 2's delete-for-both action (accept_shared_delete) -- the one
   card-level button that's actually destructive, so it gets the danger
   treatment already used elsewhere (account.html's Remove/Revoke). */
.card-actions button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.status-menu { display: flex; gap: 6px; flex: 1 1 auto; }
.status-menu select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--muted);
  font-size: 0.85rem;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1.8rem;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 6;
}

dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: min(92vw, 420px);
  max-height: 85vh;
  overflow-y: auto;
  color: var(--text);
  background: var(--card-bg);
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
.dialog-body { padding: 18px; }
.dialog-body h2 { margin-top: 0; }

form.stacked label { display: block; font-size: 0.85rem; margin: 12px 0 4px; }
form.stacked input[type=text],
form.stacked input[type=number],
form.stacked input[type=email],
form.stacked input[type=password],
form.stacked select,
form.stacked textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
form.stacked .row { display: flex; gap: 8px; }
form.stacked .row > * { flex: 1; }

/* Live address-suggestion dropdown wrapped around the Address field (see
   static/app.js's handleAddressInput/address_lookup.py) -- positioned
   relative so .address-suggestions below can float directly under the
   input regardless of where the wrapper sits on the page. Empty and
   invisible (no border/shadow of its own) until a suggestion is actually
   rendered into it, so an address field with no query typed, or with
   Geoapify unconfigured, looks exactly like a plain input. */
.address-autocomplete { position: relative; }
.address-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 7;
  max-height: 220px;
  overflow-y: auto;
  border-radius: 8px;
}
.address-suggestions:empty { border: none; }
.address-suggestions:not(:empty) {
  border: 1px solid var(--border);
  background: var(--card-bg);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  margin-top: 4px;
}
.address-suggestion {
  padding: 10px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.address-suggestion:last-child { border-bottom: none; }
.address-suggestion:hover,
.address-suggestion:focus {
  background: var(--bg);
  outline: none;
}

/* Add Entry form's Debt/Shipment + Outgoing/Incoming segmented toggles
   (see _add_entry_dialog.html, zones.resolve_is_debt) -- a pressed button
   shows the current value directly, instead of a checkbox whose label
   text flips to describe whichever state isn't currently picked. */
form.stacked .seg-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
form.stacked .seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  flex: 1;
  min-width: 140px;
}
form.stacked .seg.seg-narrow { max-width: 190px; }
form.stacked .seg button {
  flex: 1;
  border: none;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 10px 8px;
  cursor: pointer;
}
form.stacked .seg button + button { border-left: 1px solid var(--border); }
form.stacked .seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }
form.stacked .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Section labels grouping the Add Entry form's fields (Who / Item) --
   purely visual breathing room between groups, no fieldset semantics
   needed since nothing here is mutually exclusive. */
form.stacked .section-head {
  margin: 20px 0 2px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
form.stacked .section-head:first-of-type { border-top: none; padding-top: 0; }

/* Address & tracking disclosure -- collapsed by default (most entries get
   these filled by a profile pick or address autocomplete rather than
   typed by hand), opened automatically the moment Shipment is picked
   (app.js's setEntryType) since it matters more there. Never auto-closes,
   so nothing already typed in it gets hidden without the user choosing to
   hide it. */
form.stacked details.addr-box { margin-top: 16px; }
form.stacked details.addr-box summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
}
form.stacked details.addr-box summary::-webkit-details-marker { display: none; }
form.stacked details.addr-box summary .chev { display: inline-block; transition: transform 0.15s ease; font-size: 0.75rem; }
form.stacked details.addr-box[open] summary .chev { transform: rotate(90deg); }
form.stacked details.addr-box[open] summary { border-style: solid; border-radius: 8px 8px 0 0; }
form.stacked details.addr-box .addr-inner {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 4px 12px 14px;
}
form.stacked details.addr-box .addr-inner label:first-child { margin-top: 12px; }

form.stacked .checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
form.stacked .checkbox-row input { width: auto; }
form.stacked .actions { display: flex; gap: 10px; margin-top: 18px; }
form.stacked .actions button, form.stacked .actions a {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  text-align: center;
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
  font-size: 1rem;
}
form.stacked .actions button.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
form.stacked .actions button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.shipment-label {
  white-space: pre-line;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  font-size: 1.05rem;
  line-height: 1.5;
}

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #ffe6e6; color: #7a0000; font-size: 0.9rem; }
.empty { color: var(--muted); font-size: 0.9rem; padding: 8px 2px; }

.auth-wrap { max-width: 360px; margin: 40px auto; padding: 0 16px; }
