:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --ink: #23292f;
  --muted: #6a717a;
  --line: #e4dfd3;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e5efe9;
  --danger: #a3332b;
  --danger-soft: #f8e6e3;
  --warn: #8a5a00;
  --warn-soft: #fbf0d6;
  --ok-soft: #e5efe9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(35, 41, 47, .06);
}

/* "Auto" follows the device; Light and Dark are chosen from the account menu. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171a1c;
    --surface: #1f2427;
    --ink: #e8e6df;
    --muted: #9aa1a8;
    --line: #333a3f;
    --accent: #7fb8a4;
    --accent-ink: #12201b;
    --accent-soft: #23342d;
    --danger: #f0a39b;
    --danger-soft: #3a2422;
    --warn: #f0c870;
    --warn-soft: #3a3016;
    --ok-soft: #23342d;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
    --bg: #171a1c;
    --surface: #1f2427;
    --ink: #e8e6df;
    --muted: #9aa1a8;
    --line: #333a3f;
    --accent: #7fb8a4;
    --accent-ink: #12201b;
    --accent-soft: #23342d;
    --danger: #f0a39b;
    --danger-soft: #3a2422;
    --warn: #f0c870;
    --warn-soft: #3a3016;
    --ok-soft: #23342d;
    --shadow: none;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-weight: 600; line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

.wrap { max-width: 64rem; margin: 0 auto; padding: 0 1rem; }

/* header: top bar on small screens, left sidebar on wide ones */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.side-inner { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1.25rem; padding: .6rem 1rem; max-width: 64rem; margin: 0 auto; }
.brand { font-family: Georgia, serif; font-size: 1.15rem; font-weight: 600; color: var(--ink); text-decoration: none; margin-right: .5rem; }
.nav { display: flex; flex-wrap: wrap; gap: .15rem; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: .35rem .7rem; border-radius: 999px; }
.nav a:hover { background: var(--accent-soft); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

@media (min-width: 860px) {
  .shell { display: flex; min-height: 100vh; }
  .site-header { position: sticky; top: 0; align-self: flex-start; height: 100vh; flex: 0 0 14.5rem; border-bottom: 0; border-right: 1px solid var(--line); overflow-y: auto; }
  .side-inner { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 1rem; height: 100%; padding: 1.5rem 1rem 1.25rem; max-width: none; margin: 0; }
  .brand { font-size: 1.3rem; padding: 0 .7rem; margin: 0; }
  .nav { flex: 1 1 auto; flex-direction: column; flex-wrap: nowrap; gap: .2rem; }
  .nav a { padding: .55rem .8rem; border-radius: 8px; }
  .content { flex: 1; min-width: 0; }
}

main.wrap { padding-top: 1.5rem; padding-bottom: 4rem; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.crumbs { color: var(--muted); font-size: .9rem; margin-bottom: .25rem; }
.crumbs a { color: var(--muted); }

/* cards and layout helpers */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card > :last-child { margin-bottom: 0; }
.grid-2 { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.stack > * + * { margin-top: .75rem; }
.mt { margin-top: 1rem; }
.inline { display: inline; margin: 0; }
.nowrap { white-space: nowrap; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: .5rem 0; }
.sr { position: absolute; left: -9999px; }

/* buttons */
.btn { display: inline-block; font: inherit; cursor: pointer; text-decoration: none; padding: .5rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); line-height: 1.3; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-small { padding: .3rem .7rem; font-size: .9rem; }

/* forms */
.field { margin-bottom: 1rem; }
.field label, .label { display: block; font-weight: 600; margin-bottom: .25rem; }
.hint { color: var(--muted); font-size: .88rem; margin-top: .2rem; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search], input[type=number], input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem;
}
textarea { min-height: 12rem; resize: vertical; }
textarea.tall { min-height: 22rem; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; vertical-align: -.15rem; margin-right: .4rem; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.error-text { color: var(--danger); font-size: .9rem; margin-top: .25rem; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-grid .full { grid-column: 1 / -1; }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: 1rem; }
.filters .field { margin: 0; flex: 1 1 10rem; }
.filters .field.grow { flex: 3 1 14rem; }
.filters .field.fit { flex: 0 0 auto; }

/* flash */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--line); }
.flash.ok { background: var(--ok-soft); }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* lists and tables */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem .75rem; border-bottom: 1px solid var(--line); }
table.list td { padding: .7rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list a.title { font-weight: 600; text-decoration: none; }
table.list a.title:hover { text-decoration: underline; }

ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }

.badge { display: inline-block; font-size: .78rem; padding: .1rem .55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.gray { background: var(--line); color: var(--muted); }
.badge.red { background: var(--danger-soft); color: var(--danger); }

.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--accent-soft); padding: .1rem .35rem; border-radius: 4px; overflow-wrap: anywhere; }
.copy-box { display: block; padding: .5rem .7rem; }

.row.spread { justify-content: space-between; }
.callout { border-color: var(--warn); background: var(--warn-soft); }
.callout .muted { color: var(--ink); opacity: .75; }

/* dashboard quick-action tiles */
.tiles { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); margin-top: .75rem; }
.tile { display: flex; flex-direction: column; gap: .2rem; min-height: 5.5rem; padding: .9rem 1rem; border-radius: var(--radius); color: #fff; text-decoration: none; }
.tile strong { font-size: 1.02rem; }
.tile span { font-size: .88rem; opacity: .92; }
.tile:hover { filter: brightness(1.08); }
.tile:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.tile-amber { background: #b45f06; }
.tile-green { background: #2f6b4f; }
.tile-blue { background: #2b5fb0; }
.tile-plum { background: #6e3d9a; }
.tile-teal { background: #1f6f78; }
.tile-slate { background: #4a5560; }
.tiles-wide { grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); }

/* bare pages (sign in, setup) */
.bare { max-width: 30rem; margin: 0 auto; padding: 3rem 1rem; }
.bare.wide { max-width: 38rem; }
.bare h1 { text-align: center; margin-bottom: 1.25rem; }

.checks { list-style: none; padding: 0; margin: 0 0 1rem; }
.checks li { padding: .3rem 0; }
.checks .pass::before { content: "✓ "; color: var(--accent); font-weight: 700; }
.checks .fail::before { content: "✗ "; color: var(--danger); font-weight: 700; }

@media (max-width: 640px) {
  .side-inner { gap: .25rem .5rem; }
  .brand { order: 1; flex: 1; margin-right: 0; }
  .nav { order: 3; flex: 0 0 100%; justify-content: space-between; margin: 0 -.35rem; }
  .nav { gap: 0; }
  .nav a { padding: .35rem .3rem; font-size: .88rem; }
}

@media (max-width: 520px) {
  h1 { font-size: 1.45rem; }
  dl.facts { grid-template-columns: 1fr; gap: 0; }
  dl.facts dd { margin-bottom: .6rem; }
}

/* account menu (top right) */
.topbar { display: flex; justify-content: flex-end; padding-top: .75rem; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; border-radius: 999px; display: block; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: .95rem; object-fit: cover; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.avatar-lg { width: 6rem; height: 6rem; font-size: 1.8rem; }
.photo-row { gap: 1.25rem; align-items: flex-start; }
.menu-panel { position: absolute; right: 0; top: calc(100% + .4rem); z-index: 20; min-width: 15rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0, 0, 0, .18); padding: .35rem; }
.menu-panel a, .menu-panel .menu-item { display: block; width: 100%; text-align: left; padding: .5rem .7rem; border-radius: 6px; color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; }
.menu-panel a:hover, .menu-panel .menu-item:hover { background: var(--accent-soft); }
.menu-panel form { margin: 0; }
.menu-who { display: flex; flex-direction: column; padding: .5rem .7rem .6rem; border-bottom: 1px solid var(--line); margin-bottom: .25rem; overflow-wrap: anywhere; }
.theme-row { display: flex; gap: .25rem; padding: .4rem .35rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: .25rem 0; }
.theme-row button { flex: 1; font: inherit; font-size: .88rem; padding: .35rem .2rem; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.theme-row button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* two-step setup */
.qr-box { max-width: 15rem; margin: .75rem 0 1rem; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.qr { display: block; width: 100%; height: auto; }
ul.codes { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .5rem; }
ul.codes code { display: block; text-align: center; padding: .5rem; font-size: 1.05rem; }

@media (max-width: 859px) {
  .shell { position: relative; }
  .topbar { position: absolute; top: .3rem; right: .75rem; padding: 0; z-index: 30; max-width: none; margin: 0; }
}

.callout-danger { border-color: var(--danger); }

/* invoices */
.stats { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; display: flex; flex-direction: column; }
.stat-n { font-size: 1.5rem; font-weight: 700; }
input[readonly] { background: var(--accent-soft); }
.tabs-wrap { flex-wrap: wrap; }
.icon-preview { border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
