/*
 * Doulez Lumiere — app styles.
 * Colours and type follow the design system "One Lamp On" (Paper file
 * "Doulez Lumiere", tokens --lum-*): calm white, walnut ink carries the page,
 * one dark "lamp box" per page holding the headline figure in gold, gold only
 * as a tiny marker, seal red only for problems.
 * Two separate layouts: .is-desktop (sidebar) and .is-mobile (top bar + tab bar).
 */
:root {
  --lum-bg: #F7F7F7;
  --lum-card: #FFFFFF;
  --lum-ink: #221C15;
  --lum-ink-2: #5E554B;
  --lum-muted: #8A8178;
  --lum-line: #E7E3DD;
  --lum-bar: #DAD4CB;
  --lum-gold: #E3B505;
  --lum-red: #C8483A;
  --lum-radius: 14px;
  --lum-font: "Geist", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --lum-mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --tap: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color: var(--lum-ink);
  background: var(--lum-bg);
  font-family: var(--lum-font);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; }
a { color: inherit; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
p { margin: 0; }
.muted { color: var(--lum-muted); }
.small { font-size: .85rem; }
.is-bad { color: var(--lum-red); }
.num, .figure, .value, .headline, .amount, .bar-value { font-variant-numeric: tabular-nums; }
.notice { background: #F1EFEA; border: 1px solid var(--lum-line); padding: .6rem .8rem; border-radius: 10px; margin-bottom: 1rem; }
.error, .errorlist { color: var(--lum-red); }
.helptext { color: var(--lum-muted); font-size: .85rem; }

/* ---------- shared components ---------- */
.lampbox { background: var(--lum-ink); color: #F3EEE7; border-radius: var(--lum-radius); padding: 1.1rem 1.25rem; text-decoration: none; display: block; }
.lampbox .label { color: #B9AFA3; font-size: .85rem; }
.lampbox .figure { color: var(--lum-gold); font-size: 2rem; font-weight: 600; letter-spacing: -0.02em; margin-top: .25rem; }
.lampbox .sub { color: #B9AFA3; font-size: .85rem; margin-top: .35rem; }
.unit { font-size: .55em; font-weight: 500; opacity: .8; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpis > .lampbox { grid-column: span 2; }
.kpi, .panel, .card, .m-card, .m-stat, .m-section { background: var(--lum-card); border: 1px solid var(--lum-line); border-radius: var(--lum-radius); }
.kpi { padding: 1rem; }
.kpi .label, .m-stat .label { color: var(--lum-muted); font-size: .82rem; }
.kpi .value { font-size: 1.3rem; font-weight: 600; margin-top: .3rem; }
.kpi .sub { color: var(--lum-muted); font-size: .8rem; margin-top: .2rem; }
.panel { padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--lum-muted); font-weight: 500; font-size: .8rem; padding: .4rem .5rem; border-bottom: 1px solid var(--lum-line); }
.table td { padding: .55rem .5rem; border-bottom: 1px solid #F1EEE9; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table .wide { width: 30%; }

.meter { display: block; height: 6px; background: #F0ECE6; border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; width: var(--w); background: var(--lum-bar); border-radius: inherit; }
.meter.is-stock > span { background: var(--lum-red); opacity: .55; }

.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: .5rem; align-items: end; height: 190px; }
.bar { display: grid; grid-template-rows: auto 1fr auto; height: 100%; text-align: center; gap: .3rem; }
.bar-fill { align-self: end; height: var(--h); min-height: 2px; background: var(--lum-bar); border-radius: 6px 6px 2px 2px; }
.bar.is-current .bar-fill { background: var(--lum-ink); box-shadow: inset 0 3px 0 var(--lum-gold); }
.bar-value { font-size: .7rem; color: var(--lum-muted); }
.bar-label { font-size: .75rem; color: var(--lum-muted); }

.aging { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: #F0ECE6; margin: .25rem 0 1rem; }
.aging-seg { width: var(--w); }
.aging-1 { background: var(--lum-bar); }
.aging-2 { background: #B8AC9C; }
.aging-3 { background: #8E7F6C; }
.aging-4 { background: #5E554B; }
.aging-5 { background: var(--lum-red); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .5rem; vertical-align: -1px; }

.placeholder { margin-top: 1rem; padding: 3rem 1rem; text-align: center; border: 1px dashed var(--lum-bar); border-radius: var(--lum-radius); color: var(--lum-muted); background: var(--lum-card); }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; text-decoration: none; letter-spacing: -0.01em; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--lum-gold); box-shadow: 0 0 0 3px rgba(227, 181, 5, .18); }
button.link { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; }

/* ---------- computer layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100dvh; background: var(--lum-card); border-right: 1px solid var(--lum-line); padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: 1.25rem; }
.sidebar nav { display: flex; flex-direction: column; gap: .15rem; }
.sidebar nav a { text-decoration: none; padding: .55rem .7rem; border-radius: 10px; color: var(--lum-ink-2); }
.sidebar nav a:hover { background: var(--lum-bg); }
.sidebar nav a[aria-current="page"] { background: var(--lum-ink); color: #fff; }
.sync-status { margin-top: auto; font-size: .8rem; color: var(--lum-muted); }
.account { display: flex; flex-direction: column; gap: .4rem; font-size: .88rem; color: var(--lum-ink-2); }
.account .who { font-weight: 600; color: var(--lum-ink); }
.account form { margin: 0; }
.content { padding: 2rem 2.25rem 3rem; max-width: 1240px; width: 100%; outline: none; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.card { padding: 1.1rem 1.2rem; text-decoration: none; display: grid; gap: .3rem; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--lum-bar); transform: translateY(-1px); }
.headline { font-size: 1.6rem; font-weight: 600; letter-spacing: -0.02em; }
.sub { color: var(--lum-muted); font-size: .85rem; }

/* ---------- phone layout ---------- */
.is-mobile { background: var(--lum-bg); }
.m-topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .75rem; padding: calc(.6rem + var(--safe-top)) 1rem .6rem; background: var(--lum-ink); color: #F3EEE7; }
.m-topbar .brand { color: #fff; min-height: var(--tap); }
.m-sync { margin-left: auto; font-size: .75rem; color: #B9AFA3; }
.m-account { position: relative; }
.m-account summary { list-style: none; width: var(--tap); height: var(--tap); display: grid; place-items: center; cursor: pointer; }
.m-account summary::-webkit-details-marker { display: none; }
.m-account summary::before { content: ""; position: absolute; width: 32px; height: 32px; border-radius: 50%; background: #3A3128; z-index: -1; }
.m-account summary { position: relative; z-index: 0; font-weight: 600; }
.m-account-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--lum-card); color: var(--lum-ink); border: 1px solid var(--lum-line); border-radius: 12px; box-shadow: 0 12px 32px rgba(34, 28, 21, .18); min-width: 190px; padding: .4rem; display: grid; }
.m-account-menu > * { min-height: var(--tap); display: flex; align-items: center; padding: 0 .75rem; text-decoration: none; border-radius: 8px; }
.m-account-menu .who { color: var(--lum-muted); font-size: .85rem; }
.m-account-menu form { padding: 0; margin: 0; }
.m-account-menu button.menu-danger[type="submit"] { all: unset; box-sizing: border-box; display: flex; align-items: center; width: 100%; min-height: var(--tap); padding: 0 .75rem; color: var(--lum-red); cursor: pointer; border-radius: 8px; }
.m-content { padding: 1rem 1rem calc(84px + var(--safe-bottom)); outline: none; display: grid; gap: .75rem; align-content: start; }
.m-title { font-size: 1.3rem; margin: .25rem 0 0; }
.m-hero .figure { font-size: 2.1rem; }
.m-card { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1rem 1.1rem; text-decoration: none; min-height: 84px; }
.m-card h2 { font-size: .85rem; color: var(--lum-muted); font-weight: 500; margin: 0 0 .2rem; }
.m-card .headline { font-size: 1.4rem; }
.chev { font-size: 1.6rem; color: var(--lum-bar); }
.m-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.m-stat { padding: .9rem 1rem; }
.m-stat .value { font-size: 1.25rem; font-weight: 600; margin-top: .2rem; }
.m-section { padding: 1rem; }
.m-section h2 { font-size: .95rem; }
.m-list { list-style: none; margin: 0; padding: 0; }
.m-list li { display: flex; align-items: center; gap: .75rem; padding: .65rem 0; border-bottom: 1px solid #F1EEE9; min-height: var(--tap); }
.m-list li:last-child { border-bottom: 0; }
.m-list .grow { flex: 1; min-width: 0; display: grid; gap: .25rem; }
.m-list .right { display: grid; justify-items: end; }
.m-list .rank { width: 1.5rem; color: var(--lum-muted); font-variant-numeric: tabular-nums; }
.m-list .amount { font-weight: 600; }
.m-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; }
.m-legend li { display: flex; align-items: center; min-height: 36px; font-size: .92rem; }
.m-legend .amount { margin-left: auto; font-weight: 600; }
.bars.is-compact { height: 140px; gap: .3rem; }
.bars.is-compact .bar-label { font-size: .65rem; }
.m-content .placeholder, .m-content .notice { margin: 0; }

.m-tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: rgba(255, 255, 255, .96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--lum-line); padding-bottom: var(--safe-bottom); }
.m-tabbar a { flex: 1; min-height: 58px; display: grid; justify-items: center; align-content: center; gap: 2px; text-decoration: none; color: var(--lum-muted); font-size: .7rem; position: relative; }
.m-tabbar a[aria-current="page"] { color: var(--lum-ink); font-weight: 600; }
.m-tabbar a[aria-current="page"]::before { content: ""; position: absolute; top: 6px; width: 5px; height: 5px; border-radius: 50%; background: var(--lum-gold); transform: translateY(-4px); }
.icon { display: block; }

/* touch: everything tappable gives instant feedback */
.is-mobile a, .is-mobile button, .is-mobile summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.m-card:active, .m-tabbar a:active, .m-account-menu > *:active, .lampbox:active { transform: scale(.98); background-color: #EFEBE5; transition: transform .08s; }
.lampbox:active { background-color: #2E261D; }
.m-tabbar a:active { background: transparent; }

/* ---------- loading: grey placeholder boxes instead of a blank page ---------- */
#content.is-loading > * { visibility: hidden; }
#content.is-loading { position: relative; }
#content.is-loading::before, #content.is-loading::after { content: ""; position: absolute; left: inherit; right: 0; border-radius: var(--lum-radius); background: linear-gradient(90deg, #ECE8E2 25%, #F4F1EC 50%, #ECE8E2 75%); background-size: 200% 100%; animation: lum-shimmer 1.1s infinite linear; }
#content.is-loading::before { top: 1rem; height: 120px; width: auto; inset-inline: 1rem; }
#content.is-loading::after { top: calc(1rem + 136px); height: 260px; inset-inline: 1rem; }
.is-desktop #content.is-loading::before { inset-inline: 2.25rem; top: 2rem; }
.is-desktop #content.is-loading::after { inset-inline: 2.25rem; top: calc(2rem + 136px); }
@keyframes lum-shimmer { to { background-position: -200% 0; } }

/* ---------- page switch transition (only the content moves) ---------- */
#content { view-transition-name: lum-content; }
::view-transition-old(lum-content) { animation: lum-out .14s ease-in both; }
::view-transition-new(lum-content) { animation: lum-in .22s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes lum-out { to { opacity: 0; transform: translateY(-4px); } }
@keyframes lum-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(lum-content), ::view-transition-new(lum-content) { animation: none; }
  #content.is-loading::before, #content.is-loading::after { animation: none; }
}

/* ---------- offline ---------- */
.offline-banner { display: none; position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(70px + var(--safe-bottom)); z-index: 20; background: var(--lum-ink); color: #F3EEE7; font-size: .8rem; padding: .5rem .9rem; border-radius: 99px; white-space: nowrap; }
.is-desktop .offline-banner { bottom: 1.25rem; }
.is-offline .offline-banner { display: block; }

/* ---------- login / standalone pages ---------- */
.auth { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.auth-card { background: var(--lum-card); border: 1px solid var(--lum-line); border-radius: var(--lum-radius); padding: 2rem; width: min(380px, 100%); display: grid; gap: .5rem; }
.auth-card h1 { margin: 0; }
.auth-card form, .form { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.narrow { max-width: 420px; }
input { font: inherit; font-size: max(16px, 1rem); padding: .65rem .75rem; min-height: var(--tap); border: 1px solid var(--lum-line); border-radius: 10px; width: 100%; background: #fff; }
input:focus { outline: 2px solid var(--lum-ink); outline-offset: 1px; }
button[type="submit"]:not(.link) { font: inherit; margin-top: .5rem; min-height: var(--tap); padding: .6rem; border: 0; border-radius: 10px; background: var(--lum-ink); color: #fff; cursor: pointer; }
.is-mobile .form { margin: 0; }

/* computer layout on a narrow window (someone chose it on a phone): stay usable */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--lum-line); }
  .two-col { grid-template-columns: 1fr; }
  .content { padding: 1.25rem; }
}
.reconcile { margin: -.25rem 0 1rem; }

/* ---------- two-factor login pages ---------- */
.twofa { width: min(440px, 100%); }
.steps { margin: .5rem 0 0; padding-left: 1.2rem; display: grid; gap: .6rem; color: var(--lum-ink-2); }
.qr { margin: .75rem 0 .5rem; width: 196px; padding: 6px; background: #fff; border: 1px solid var(--lum-line); border-radius: 12px; }
.qr svg { display: block; width: 100%; height: auto; }
.secret { display: inline-block; margin-top: .4rem; font-family: var(--lum-mono); letter-spacing: .06em; word-break: break-all; color: var(--lum-ink); }
.twofa input[name="code"] { font-family: var(--lum-mono); font-size: 1.4rem; letter-spacing: .3em; text-align: center; }
.check { display: flex; align-items: center; gap: .5rem; min-height: var(--tap); color: var(--lum-ink-2); font-size: .92rem; }
.check input { width: 20px; height: 20px; min-height: 0; }
.backup-codes { list-style: none; padding: 0; margin: .5rem 0 1rem; display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.backup-codes code { display: block; text-align: center; padding: .55rem; border: 1px dashed var(--lum-bar); border-radius: 8px; font-family: var(--lum-mono); font-size: 1.05rem; letter-spacing: .08em; }
a.button { display: flex; align-items: center; justify-content: center; min-height: var(--tap); border-radius: 10px; background: var(--lum-ink); color: #fff; text-decoration: none; }
.twofa form[data-logout] { margin: 0; }
