/* Colour tokens: every colour in every stylesheet comes from these blocks and nowhere else.
   Light "QuickBooks" (the default): charcoal navigation and a green accent, darkened just enough that white
   button text and green text pass 4.5:1. Dark "Edgewood": near-black surfaces and the gold of the logo. The dark
   tokens apply with html[data-theme="dark"], or with no data-theme when the device prefers dark (static/theme.js
   sets data-theme from the choice in the account menu). They are screen-only, so printing always uses the light
   tokens: dark text on white. */
:root {
  color-scheme: light;
  --bg: #F4F5F8;
  --card: #FFFFFF;
  --card-2: #F4F5F8;
  --ink: #393A3D;
  --muted: #6B6C72;
  --line: #D4D7DC;
  --line-strong: #898C92;
  --accent: #258617;
  --accent-hover: #108000;
  --accent-ink: #FFFFFF;
  --accent-soft: #EBF8E8;
  --link: #006FB8;
  --topbar: #393A3D;
  --topbar-ink: #FFFFFF;
  --topbar-hover: rgba(255, 255, 255, .12);
  --ok: #108000;
  --ok-soft: #EBF8E8;
  --warn: #AD5700;
  --warn-soft: #FFF4E5;
  --bad: #CC291D;
  --bad-soft: #FDECEA;
  --info: #006FB8;
  --info-soft: #E6F2FA;
  --input-bg: #FFFFFF;
  --table-head: #F4F5F8;
  --row-hover: #F0F2F5;
  --shadow: rgba(0, 0, 0, .14);
  --focus: #0077C5;
  /* The same in both themes: the receipt camera, what is drawn over the camera or a photo, and the white paper
     behind uploaded images (a transparent PNG receipt or logo has dark ink). */
  --viewfinder: #000000;
  --on-viewfinder: #FFFFFF;
  --scrim: rgba(0, 0, 0, .6);
  --paper: #FFFFFF;
}
/* The two dark blocks must stay identical (tests/test_theme.py checks it). */
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121417;
    --card: #1C1F24;
    --card-2: #22262C;
    --ink: #E8EAED;
    --muted: #A3A8AE;
    --line: #2E3339;
    --line-strong: #6B737D;
    --accent: #C9A84C;
    --accent-hover: #DDBD63;
    --accent-ink: #15120A;
    --accent-soft: #2E2816;
    --link: #DDBD63;
    --topbar: #0B0C0E;
    --topbar-ink: #F2EBD3;
    --topbar-hover: rgba(255, 255, 255, .08);
    --ok: #7ED67A;
    --ok-soft: #16301C;
    --warn: #F2B45A;
    --warn-soft: #3A2A12;
    --bad: #F28B82;
    --bad-soft: #3B1F1D;
    --info: #8AB4F8;
    --info-soft: #1B2A3B;
    --input-bg: #15181C;
    --table-head: #22262C;
    --row-hover: #272C33;
    --shadow: rgba(0, 0, 0, .5);
    --focus: #8AB4F8;
  }
}
@media screen {
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121417;
    --card: #1C1F24;
    --card-2: #22262C;
    --ink: #E8EAED;
    --muted: #A3A8AE;
    --line: #2E3339;
    --line-strong: #6B737D;
    --accent: #C9A84C;
    --accent-hover: #DDBD63;
    --accent-ink: #15120A;
    --accent-soft: #2E2816;
    --link: #DDBD63;
    --topbar: #0B0C0E;
    --topbar-ink: #F2EBD3;
    --topbar-hover: rgba(255, 255, 255, .08);
    --ok: #7ED67A;
    --ok-soft: #16301C;
    --warn: #F2B45A;
    --warn-soft: #3A2A12;
    --bad: #F28B82;
    --bad-soft: #3B1F1D;
    --info: #8AB4F8;
    --info-soft: #1B2A3B;
    --input-bg: #15181C;
    --table-head: #22262C;
    --row-hover: #272C33;
    --shadow: rgba(0, 0, 0, .5);
    --focus: #8AB4F8;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--link); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
.muted { color: var(--muted); }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .4rem 1rem; background: var(--topbar); color: var(--topbar-ink); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar a { color: var(--topbar-ink); text-decoration: none; }
.brand { font-weight: 700; display: flex; align-items: center; gap: .4rem; }
.brand img { border-radius: 6px; }
.mainnav { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.mainnav > a, .mainnav summary, .account summary { padding: .35rem .6rem; border-radius: 6px; cursor: pointer; }
.mainnav > a:hover, .mainnav summary:hover, .account summary:hover { background: var(--topbar-hover); }
.account { margin-left: auto; display: flex; gap: .5rem; align-items: center; }
.company-name { opacity: .9; }
details.menu { position: relative; }
details.menu summary { list-style: none; }
details.menu summary::-webkit-details-marker { display: none; }
details.menu .dropdown { display: none; }
details.menu[open] .dropdown { display: flex; flex-direction: column; position: absolute; left: 0; top: 100%; min-width: 200px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px var(--shadow); z-index: 20; padding: .3rem 0; }
.account details.menu[open] .dropdown { left: auto; right: 0; }
details.menu .dropdown a, details.menu .dropdown button { color: var(--ink); background: none; padding: .45rem .9rem; border: 0; width: 100%; text-align: left; font: inherit; cursor: pointer; text-decoration: none; }
details.menu .dropdown a:hover, details.menu .dropdown button:hover { background: var(--row-hover); }
/* Theme row in the account menu (System / Light / Dark): app.js handles the buttons, theme.js applies the choice. */
.theme-row { display: flex; align-items: center; gap: .3rem; padding: .45rem .9rem; margin: .2rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.theme-row span { margin-right: auto; padding-right: .4rem; }
.theme-row[hidden] { display: none; }
details.menu .dropdown .theme-row button { width: auto; padding: .2rem .5rem; border: 1px solid var(--line-strong); border-radius: 6px; }
details.menu .dropdown .theme-row button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.page { max-width: 1100px; margin: 1.2rem auto; padding: 0 1rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 0; }

.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--bad-soft); color: var(--bad); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .9rem; text-decoration: none; color: inherit; }
.tile:hover { border-color: var(--accent); }
.tile-label { color: var(--muted); font-size: .85rem; }
.tile-value { font-size: 1.6rem; font-weight: 600; }
.tile-sub { color: var(--muted); font-size: .85rem; }
.quick { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.2rem; }

.btn { display: inline-block; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--card); color: var(--ink); text-decoration: none; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
button.linklike { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.card.narrow { max-width: 480px; margin: 2rem auto; }

form .field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; }
form label { font-size: .85rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  font: inherit; padding: .45rem .6rem; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--input-bg); color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
::placeholder { color: var(--muted); opacity: 1; }
a:focus-visible, button:focus-visible, summary:focus-visible, .btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.topbar :focus-visible { outline-color: var(--topbar-ink); }
.topbar .dropdown :focus-visible { outline-color: var(--focus); }
.logo-preview { background: var(--paper); padding: .4rem; border-radius: 6px; max-height: 80px; max-width: 240px; }
.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row > .field { flex: 1 1 180px; }
.actions { display: flex; gap: .6rem; align-items: center; margin-top: .8rem; }
.error { color: var(--bad); font-size: .9rem; }
.help { color: var(--muted); font-size: .85rem; }

table.grid { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.grid th, table.grid td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.grid th { background: var(--table-head); font-weight: 600; font-size: .85rem; color: var(--muted); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr:hover td { background: var(--row-hover); }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; background: var(--line); color: var(--ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; }
.toolbar input[type=search] { width: auto; min-width: 220px; }
ul.list { list-style: none; padding: 0; }
ul.list li { padding: .5rem 0; border-bottom: 1px solid var(--line); }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .mainnav { order: 3; width: 100%; }
  .page { margin: .8rem auto; }
  table.grid { font-size: .9rem; }
}
