/* Dark-first palette (warm orange accent, per the user's request to look
 * like ~/Projects/journal's structure but visually distinct from its
 * gold/mustard accent), with a light override. Vanilla CSS, no
 * preprocessor -- no build step for the whole frontend (see
 * static/js/vendor/), so this file follows suit. */
:root {
  --bg: #1c1410;
  --bg-elevated: #241a14;
  --bg-input: #2a1f18;
  --text: #f3ece6;
  --text-muted: #b8a99c;
  --border: #3a2c22;
  --accent: #f2872e;
  --accent-text: #1c1410;
  --danger: #e5637a;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fbf7f3;
    --bg-elevated: #ffffff;
    --bg-input: #ffffff;
    --text: #2a1f18;
    --text-muted: #7a6a5c;
    --border: #e7ddd3;
    --accent: #c2570e;
    --accent-text: #ffffff;
    --danger: #b23a52;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; min-height: 100dvh; }
#app { min-height: 100vh; min-height: 100dvh; }

a { color: inherit; }
h1, h2, h3 { margin: 0 0 0.5rem; }

.hidden { display: none !important; }
.loading, .error { padding: 1rem 0; color: var(--text-muted); }
.error { color: var(--danger); }
.muted { color: var(--text-muted); }

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border-radius: var(--radius);
  border: none;
  padding: 0.6rem 1rem;
}
button:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-icon { background: transparent; color: var(--text-muted); border: none; padding: 0.25rem 0.5rem; font-size: 0.9rem; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

input[type="text"], input[type="password"], input[type="number"], input[type="file"], textarea, select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  font-family: inherit;
  font-size: 1rem;
}
label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--text-muted); }
.checkbox-field { flex-direction: row; align-items: center; gap: 0.5rem; margin-top: 0.6rem; }
.checkbox-field input[type="checkbox"] { width: auto; }

/* ---------------- Login / setup / register ---------------- */

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem;
}
.login-screen h1 { letter-spacing: 0.02em; color: var(--accent); }
.setup-intro { margin: -0.75rem 0 0; max-width: 320px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; width: 100%; max-width: 320px; }
.login-switch { font-size: 0.85rem; color: var(--text-muted); text-align: center; }
.login-switch button { background: none; border: none; padding: 0; color: var(--accent); font-size: inherit; text-decoration: underline; }

/* ---------------- App shell / nav ---------------- */

.app-shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.topnav {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; flex-shrink: 0; color: var(--accent); }
/* Real button chrome, not text that merely highlights on hover -- a
 * visible border/background at rest so these read as buttons rather
 * than plain links, matching .btn-ghost elsewhere in the app. */
.nav-links { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.nav-links a {
  text-decoration: none;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
}
.nav-links a:hover { border-color: var(--accent); }
.nav-links a.nav-link-active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
#logout-btn { margin-left: auto; flex-shrink: 0; }

.view-container { flex: 1; padding: 1rem; max-width: 900px; width: 100%; margin: 0 auto; }

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

.bills-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; }
.bill-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.bill-card {
  display: block;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  text-decoration: none;
  color: var(--text);
}
.bill-card:hover { border-color: var(--accent); }
.bill-card-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.bill-card-title { font-weight: 600; }
.bill-card-total { font-weight: 700; color: var(--accent); }
.bill-card-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.empty-state { color: var(--text-muted); text-align: center; padding: 3rem 1rem; }

/* ---------------- New bill capture ---------------- */

.capture-form { display: flex; flex-direction: column; gap: 1.1rem; max-width: 480px; }
.photo-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
}
.photo-dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-dropzone.has-file { border-color: var(--accent); color: var(--text); }
.photo-preview { max-width: 100%; max-height: 220px; border-radius: var(--radius); display: block; margin: 0 auto 0.5rem; }

/* ---------------- Bill detail / editor ---------------- */

.bill-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.bill-title-input { font-size: 1.3rem; font-weight: 700; border: none; background: none; padding: 0.2rem 0; flex: 1; min-width: 0; }
.bill-title-input:focus { outline: 1px solid var(--accent); border-radius: var(--radius); }

/* Photo above the content on narrow/mobile viewports (source order:
 * photo column comes first), beside it on wide/desktop viewports. Sized
 * to actually be readable -- receipt text is small -- not a tiny
 * thumbnail; clicking/tapping it opens an in-page zoomed overlay (see
 * .lightbox-* below) rather than navigating to a new tab, so whatever
 * was open in the item list underneath is never lost. */
.bill-layout { display: flex; flex-direction: column; gap: 1.5rem; }
.bill-photo-col { display: flex; flex-direction: column; gap: 0.4rem; }
.bill-photo-button {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: zoom-in;
}
.bill-photo-large {
  display: block;
  width: 100%;
  max-height: 75vh;
  object-fit: contain;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.bill-main-col { min-width: 0; flex: 1; }

/* Full-viewport in-page zoom overlay -- deliberately not a new tab/
 * page: closing it (backdrop click, the X, or Esc) returns to exactly
 * whatever state the item list/tax-tip form was already in, since
 * nothing here ever navigated away. */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  z-index: 50;
  cursor: zoom-out;
}
.lightbox-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius); }
.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 51;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.1rem;
}

@media (min-width: 860px) {
  .bill-layout { flex-direction: row; align-items: flex-start; }
  .bill-photo-col {
    /* Genuinely large on desktop, not a sidebar thumbnail -- there's
     * plenty of screen to spare, so use it: roughly half the content
     * width rather than a fixed narrow column. */
    flex: 1 1 0;
    max-width: 640px;
    position: sticky;
    top: calc(0.75rem + 3.25rem); /* below the sticky topnav */
  }
  .bill-main-col { flex: 1 1 0; }
  .bill-photo-large { max-height: calc(100vh - 4.5rem); }
}

.panel { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.panel-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 0.75rem; }

.people-bar { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.person-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.85rem;
}
.person-chip-remove { background: none; border: none; color: var(--text-muted); padding: 0; font-size: 0.9rem; line-height: 1; }
.add-person-form { display: flex; gap: 0.4rem; align-items: center; }
.add-person-form input { width: 160px; }

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.item-row { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.85rem; background: var(--bg-input); }
.item-row-top { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.6rem; }
.item-name-input { flex: 3; }
.item-price-input { flex: 1; min-width: 5rem; }
.item-assign-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.assign-chip {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
}
.assign-chip-active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.uneven-toggle { font-size: 0.78rem; color: var(--text-muted); background: none; border: none; text-decoration: underline; padding: 0.2rem 0; }
.weight-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.5rem; }
.weight-field { display: flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; color: var(--text-muted); }
.weight-field input { width: 4rem; padding: 0.3rem 0.4rem; }

.add-item-form { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.add-item-form input[name="name"] { flex: 3; }
.add-item-form input[name="price"] { flex: 1; min-width: 5rem; }

/* auto-fit/minmax rather than a viewport media-query breakpoint: the
 * actual available width here isn't the viewport's -- it's whatever's
 * left of .bill-main-col after the sticky photo sidebar (see
 * .bill-photo-col) eats its fixed 380px on desktop, which a
 * `@media (max-width: 560px)` check can't see at all. A wide viewport
 * with the photo panel open could still leave this grid narrower than
 * 560px, and the two fields' inputs would overflow their column
 * uncorrected -- this is exactly the bug that was reported. Letting
 * the grid track count respond to its own real content width fixes it
 * regardless of what's eating space elsewhere on the page. */
.tax-tip-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; }
.tax-tip-field { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.tax-tip-inputs { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.tax-tip-inputs input { width: 5rem; min-width: 4rem; }
.tax-tip-note { font-size: 0.78rem; color: var(--text-muted); }
.total-backsolve { margin-top: 0.6rem; padding-top: 0.6rem; border-top: 1px dashed var(--border); }
.total-backsolve input { width: 6rem; min-width: 4.5rem; }

.breakdown-table { width: 100%; border-collapse: collapse; }
.breakdown-table th, .breakdown-table td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.breakdown-table th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
.breakdown-name { font-weight: 600; }
.breakdown-total { font-weight: 700; color: var(--accent); }
.breakdown-items-detail { font-size: 0.78rem; color: var(--text-muted); }
.unassigned-warning { margin-top: 0.75rem; padding: 0.6rem 0.8rem; border-radius: var(--radius); background: rgba(242, 135, 46, 0.12); border: 1px solid var(--accent); font-size: 0.85rem; }

.share-box { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.share-box input[type="text"] { flex: 1; min-width: 200px; }

/* ---------------- Profile ---------------- */

.invite-code-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  width: fit-content;
}

/* ---------------- Static share page (/s/<token>) ---------------- */
/* No JS on this page at all -- see app/templates/share.html -- but it
 * shares this stylesheet, which is plain CSS and works fine either way. */

.share-page { max-width: 700px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.share-page h1 { color: var(--accent); margin: 0; }
.share-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.share-meta { color: var(--text-muted); font-size: 0.85rem; margin: 0.4rem 0 1.5rem; }
.share-message {
  background: rgba(242, 135, 46, 0.12);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
  white-space: pre-wrap;
  word-break: break-word;
}
.share-photo-link { display: block; margin-top: 0.5rem; cursor: zoom-in; }
.share-photo {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.share-items-list { list-style: none; margin: 0 0 1.5rem; padding: 0; }
.share-items-list li { display: flex; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.share-totals { display: flex; justify-content: flex-end; gap: 1.5rem; margin-bottom: 2rem; color: var(--text-muted); font-size: 0.9rem; }
.share-totals strong { color: var(--text); }
.share-person-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 0.9rem; }
.share-person-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.5rem; }
.share-person-header .name { font-weight: 700; font-size: 1.05rem; }
.share-person-header .total { font-weight: 700; color: var(--accent); font-size: 1.1rem; }
.share-person-items { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; color: var(--text-muted); }
.share-person-items li { display: flex; justify-content: space-between; padding: 0.15rem 0; }
.share-person-charges { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.4rem; }
