/* Layout and components. Colours come from /theme.css tokens.
   Type, shapes and chrome follow the suite look shared with fintracker. */

:root {
  --radius: 18px;
  --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 8% -10%, var(--glow, transparent), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-family: var(--serif); font-weight: 500; letter-spacing: -0.03em; }
h2 { font-size: 1.2rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--selection, var(--accent-soft)); }

/* ---------- controls ---------- */

button, .button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--wash, var(--surface-alt)); }
button:disabled { opacity: 0.6; cursor: default; }
button.primary, .button.primary {
  background: var(--accent-fill, var(--accent));
  border-color: transparent;
  color: var(--on-accent);
}
button.primary:hover, .button.primary:hover { background: var(--accent-fill, var(--accent)); filter: brightness(1.06); }
button.danger { background: transparent; border-color: var(--danger-line, var(--negative)); color: var(--negative); }
button.danger:hover { background: var(--negative-soft, var(--surface-alt)); }
button.link {
  border: 0;
  background: none;
  padding: 0;
  min-height: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.wide { width: 100%; }

.icon { display: inline-flex; line-height: 0; }
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-color: transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover { color: var(--text); background: var(--wash, var(--surface-alt)); border-color: transparent; }
/* "add" buttons: outlined circle, as in cc-tracker */
.icon-btn.accent { width: 40px; height: 40px; flex: none; border-color: var(--border); color: var(--text); }
.icon-btn.accent:hover { border-color: var(--border); }

input[type="text"], input[type="password"], input[type="url"], select, textarea {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input, var(--surface));
  width: 100%;
  min-width: 0;
}
input::placeholder { color: var(--muted); opacity: 0.8; }
input.invalid { border-color: var(--negative) !important; color: var(--negative); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 0.78rem; color: var(--muted); }
.hint { color: var(--muted); margin: 0; font-size: 0.9rem; }
.form-error { color: var(--negative); margin: 0; min-height: 1.2em; font-size: 0.9rem; }
.form-actions { display: flex; justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; }
.inline-form select { width: auto; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: max(12px, env(safe-area-inset-top)) 22px 12px;
  background: var(--top, color-mix(in srgb, var(--bg) 88%, transparent));
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.bar-right { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--brand);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.15rem;
  letter-spacing: -0.03em;
}
/* suite mark: two stacked cards */
.mark { width: 22px; height: 16px; position: relative; display: inline-block; flex: none; }
.mark::before, .mark::after {
  content: "";
  position: absolute;
  border-radius: 3px;
  border: 1.5px solid var(--accent-fill, var(--accent));
}
.mark::before { inset: 3px 0 0 4px; background: #3a3122; }
.mark::after { inset: 0 4px 3px 0; background: #2a2418; }

/* page heading: title left, page actions (add / return / ⋮) right */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 18px; }
.kicker { margin: 0 0 6px; color: var(--accent); font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; }
.title { font-size: clamp(2.1rem, 4vw, 3.2rem); line-height: 1.1; overflow-wrap: anywhere; }
.head-links { display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-end; gap: 8px; }
.head-links .icon-btn { width: 40px; height: 40px; flex: none; border-color: var(--border); color: var(--muted); }
.head-links .icon-btn:hover, .head-links .icon-btn[aria-expanded="true"] { color: var(--text); background: var(--wash, var(--surface-alt)); }
.head-links .icon-btn.accent { color: var(--text); font-size: 1.45rem; }

.save-btn[data-state="saved"] { color: var(--muted); }
.save-btn[data-state="pending"] { color: var(--accent); }
.save-btn[data-state="done"] { color: var(--positive); }
.save-btn[data-state="saving"] { color: var(--accent); }
.save-btn[data-state="saving"] svg { animation: spin 0.9s linear infinite; }
.save-btn[data-state="error"], .save-btn[data-state="conflict"] { color: var(--negative); }
.save-btn[data-state="offline"] { color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- popup menus ---------- */

.popup {
  position: absolute;
  z-index: 50;
  min-width: 220px;
  max-width: calc(100vw - 16px);
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.menu-item {
  display: flex;
  width: 100%;
  justify-content: flex-start;
  gap: 10px;
  border: 0;
  background: none;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--text);
}
.menu-item:hover { background: var(--wash, var(--surface-alt)); color: var(--accent-hover); }
.menu-item .icon { color: var(--muted); }
.menu-label { flex: 1; text-align: left; }
.menu-row { display: flex; align-items: center; }
.menu-row .menu-item { flex: 1; }
.menu-side { width: 32px; height: 32px; }
.menu-side svg { width: 17px; height: 17px; }
.menu-sub .menu-item { padding-left: 40px; min-height: 32px; }
.menu-item.pending { background: var(--accent-soft); font-weight: 600; }
.menu-note { max-width: 240px; padding: 4px 10px 6px 40px; font-size: 0.78rem; color: var(--muted); }
.menu-heading { padding: 6px 12px 4px; font-size: 0.78rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.14em; }

/* ---------- views ---------- */

.view { max-width: 1152px; margin: 0 auto; padding: 28px 16px 72px; }
@media (min-width: 1240px) { .view.wide-view { max-width: 80vw; } }
.loading, .empty { text-align: center; color: var(--muted); margin-top: 48px; }
.empty .icon { vertical-align: middle; }

/* checkboxes */
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }

/* tables: every cell centred, rows striped */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 13px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}
td { padding: 6px 8px; vertical-align: middle; text-align: center; }
/* faint column separators on every table */
th + th, td + td { border-left: 1px solid color-mix(in srgb, var(--border) 55%, transparent); }
tbody tr.even { background: var(--surface); }
tbody tr.odd { background: var(--surface-alt); }
tbody tr:hover { background: color-mix(in srgb, var(--text) 7%, var(--surface)); }
.col-act { width: 1%; white-space: nowrap; text-align: center; }
.del-btn:hover { color: var(--negative); }
.archive-btn:hover { color: var(--accent); }

.choice { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.choice input { margin-top: 3px; flex: none; }
.choice > span { display: flex; flex-direction: column; gap: 2px; }
input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); }
code { font: 0.85em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-alt); padding: 1px 5px; border-radius: 5px; }
.key-reveal { display: flex; flex-direction: column; gap: 6px; }
.key-reveal input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre.diff {
  margin: 0;
  max-height: 50vh;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-sunk);
  font: 0.8rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
pre.diff span { display: block; white-space: pre; }
pre.diff .diff-head { color: var(--muted); }
pre.diff .del { color: var(--negative); background: color-mix(in srgb, var(--negative) 10%, transparent); }
pre.diff .add { color: var(--positive); background: color-mix(in srgb, var(--positive) 10%, transparent); }

button.danger-outline { color: var(--negative); }
button.danger-outline:hover { border-color: var(--negative); }

/* ---------- user settings ---------- */

.settings-view { display: flex; flex-direction: column; gap: 18px; max-width: 760px; margin: 0 auto; }
.card { padding: 16px 18px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.card > h2 { font-size: 1.45rem; }
.narrow-form { max-width: 360px; }
.narrow-form .form-actions { justify-content: flex-start; }
input[type="password"] { width: 100%; }

/* ---------- dialogs ---------- */

.modal {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.modal.wide { width: min(860px, calc(100vw - 32px)); }
.modal::backdrop { background: var(--backdrop, rgb(20 12 5 / 45%)); }
.modal-head h2 { font-size: 1.45rem; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 4px 18px; }
.modal-body { padding: 8px 18px 18px; }
.modal-body p { margin: 0; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 0 18px 16px; }
.skipped { max-height: 240px; overflow: auto; margin: 0; padding-left: 18px; font-size: 0.85rem; color: var(--muted); }

#toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 100;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.has-undo #toast { bottom: calc(max(20px, env(safe-area-inset-bottom)) + 56px); }

#undo-bar {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 100;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
  white-space: nowrap;
}
#undo-bar .icon-btn { color: var(--bg); }
.undo-btn {
  position: relative;
  overflow: hidden;
  min-height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  border: 0;
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
}
.undo-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--accent, currentColor);
  transform-origin: left;
  animation: undo-run linear forwards;
}
@keyframes undo-run { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .undo-timer { animation-timing-function: steps(30); } }
#toast.error { background: var(--surface); color: var(--negative); box-shadow: inset 0 0 0 1px var(--danger-line, var(--negative)), var(--shadow); }

/* ---------- login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  padding: 28px 24px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card .brand { justify-content: center; margin-bottom: 6px; }
.login-card .brand h1 { font-size: 1.6rem; font-weight: 500; }
.or { text-align: center; color: var(--muted); font-size: 0.85rem; }
.login-foot { display: flex; justify-content: center; }
.boot-error { text-align: center; margin-top: 30vh; color: var(--negative); }

/* User settings: a titled part of a card (Export/import, Home region, Add region). */
.sub-section { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.sub-section h3 { margin: 0; font-size: 0.95rem; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.form-actions { flex-wrap: wrap; gap: 8px; }
.settings-view .form-actions { justify-content: flex-start; }
.settings-view .form-actions .button { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }

/* ---------- lists ---------- */

textarea { padding: 8px 12px; resize: vertical; min-height: 72px; line-height: 1.4; }
.invisible { visibility: hidden; }
.sheet .col-num { width: 1%; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.sheet .col-act .icon-btn { width: 34px; height: 34px; }
/* Lists overview: the Title column reads left to right. */
.overview th:first-child, .overview td.col-title { text-align: left; padding-left: 16px; }
.list-link { font-weight: 600; color: var(--text); text-decoration: none; }
.list-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.cell-text { display: inline-block; min-height: 34px; line-height: 34px; }
.tag { display: inline-block; margin-left: 8px; padding: 0 8px; border-radius: 999px; font-size: 0.72rem; color: var(--muted); background: var(--wash, var(--surface-alt)); vertical-align: middle; }

/* items */
.items .col-check { width: 1%; }
.items .col-image { width: 1%; }
.items th .icon-cell { display: inline-flex; vertical-align: middle; }
.items th .icon-cell svg { width: 16px; height: 16px; }
.items .item-name { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.items a.item-name:hover { color: var(--accent); }
.items a.item-name svg { width: 15px; height: 15px; color: var(--muted); }
.item-desc { margin-top: 2px; font-size: 0.85rem; color: var(--muted); white-space: pre-line; overflow-wrap: anywhere; }
.items tr.checked .item-name { text-decoration: line-through; color: var(--muted); }
.items tr.checked .thumb { opacity: 0.55; }
.thumb-btn { padding: 0; min-height: 0; border: 0; border-radius: 10px; background: none; }
.thumb { display: block; width: 56px; height: 56px; object-fit: cover; border-radius: 10px; background: var(--surface-sunk); }
.list-foot { display: flex; justify-content: center; margin-top: 16px; }
.full-image { display: block; max-width: 100%; max-height: 75vh; margin: 0 auto; border-radius: 12px; }

/* item form */
.image-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.thumb-wrap { position: relative; }
.form-thumb { display: block; width: 96px; height: 96px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-sunk); }
.thumb-remove { position: absolute; top: -10px; right: -10px; width: 28px; height: 28px; background: var(--surface); border-color: var(--border); color: var(--negative); }
.thumb-remove svg { width: 15px; height: 15px; }
.thumb-remove:hover { background: var(--negative-soft); }
#item-form .hint:empty { display: none; }

/* search */
.head-links .filter-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.search-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 0 6px 0 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--input, var(--surface)); }
.search-bar .icon { color: var(--muted); }
.search-bar svg { width: 16px; height: 16px; }
.search-input { flex: 1; min-width: 0; min-height: 40px; border: 0; background: none; outline: none; }
.search-bar:focus-within { border-color: var(--accent); }
.match-hint { margin-top: 2px; font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }

/* tags */
.tag-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 8px; vertical-align: middle; }
.tag-chip { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border: 0; border-radius: 999px; font-size: 0.75rem; color: var(--accent); background: var(--accent-soft); }
button.tag-chip:hover { background: var(--accent-soft); filter: brightness(1.15); text-decoration: underline; }
.list-tags { margin: -8px 0 14px; }
.list-tags .tag-chips { margin-left: 0; }
/* Lists page: tags sit quietly on their own line under the title. */
.overview td.col-title { padding-top: 8px; padding-bottom: 8px; line-height: 1.3; }
.overview .tag-chips { display: flex; gap: 2px 10px; margin: 3px 0 0; }
.overview .tag-chip { min-height: 0; padding: 0; border-radius: 0; background: none; font-size: 0.72rem; letter-spacing: 0.01em; color: var(--muted); }
.overview button.tag-chip:hover { background: none; filter: none; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.overview .match-hint { margin-top: 3px; }
.list-name { font-weight: 600; }

/* palette */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; min-height: 0; padding: 0; border: 2px solid var(--border); border-radius: 50%; }
.swatch:hover { transform: scale(1.08); }
.swatch[aria-checked="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); }
.swatch-default { background: linear-gradient(135deg, #e4b56a 50%, #171a20 50%); }

/* palette dock: bottom left of every page */
.palette-dock { position: fixed; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 90; }
.palette-btn { width: 42px; height: 42px; border: 1px solid var(--border); background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.palette-btn:hover, .palette-btn[aria-expanded="true"] { background: var(--surface); color: var(--accent-hover); border-color: var(--accent); }
.palette-panel { position: absolute; left: 0; bottom: calc(100% + 10px); width: min(300px, calc(100vw - 32px)); padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }

/* API keys */
.key-reveal { display: flex; flex-direction: column; gap: 6px; }
.key-reveal input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.settings-view code { overflow-wrap: anywhere; }

@media (max-width: 720px) {
  .view { padding: 18px 8px 64px; }
  .topbar { padding-inline: 14px; }
  td { padding: 4px; }
  th { padding: 10px 4px; font-size: 0.68rem; letter-spacing: 0.02em; }
  .sheet .col-act .icon-btn { width: 30px; height: 34px; }
  .thumb { width: 44px; height: 44px; }
}
