/* Souel's look. Colours are set once here, as variables: change them to restyle everything. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2329;
  --muted: #5f6b76;
  --line: #dde2e7;
  --accent: #5b7d99;
  --accent-text: #ffffff;
  --accent-soft: #e6eef5;
  --error: #c62828;
  --error-soft: #fdecea;
  --good: #2e7d32;
  --radius: 10px;
  --shadow: 0 1px 3px rgb(0 0 0 / 8%), 0 4px 16px rgb(0 0 0 / 6%);
  color-scheme: light dark;
}

/* Dark: by the system's setting, unless the person chose light; or chosen with the toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15191d;
    --surface: #1e2328;
    --text: #e6e9ec;
    --muted: #9aa5af;
    --line: #333b43;
    --accent: #8fb3d1;
    --accent-text: #10161b;
    --accent-soft: #263441;
    --error: #ef9a9a;
    --error-soft: #3b2224;
    --good: #81c784;
  }
}
:root[data-theme="dark"] {
  --bg: #15191d;
  --surface: #1e2328;
  --text: #e6e9ec;
  --muted: #9aa5af;
  --line: #333b43;
  --accent: #8fb3d1;
  --accent-text: #10161b;
  --accent-soft: #263441;
  --error: #ef9a9a;
  --error-soft: #3b2224;
  --good: #81c784;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
}
main { padding: 20px 24px 64px; max-width: 1600px; margin: 0 auto; }
h1 { font-size: 1.6rem; margin: 0; font-weight: 600; }
h2 { font-size: 1.25rem; margin: 0 0 12px; font-weight: 600; }
a { color: var(--accent); }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 0.87rem; }
.error { color: var(--error); }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- the menu on the left ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px; padding: 18px 14px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px; padding: 0 8px;
  font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none;
}
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.tabs { display: flex; flex-direction: column; gap: 2px; }
.tabs .group { margin: 12px 10px 4px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.tabs a {
  padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted);
  font-weight: 500;
}
.tabs a:hover { background: var(--accent-soft); color: var(--text); }
.tabs a.active { background: var(--accent); color: var(--accent-text); }
.account { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.account .who { padding: 0 4px; font-size: 0.85rem; }
.account .version { padding: 0 4px; font-size: 0.75rem; text-align: center; }
.account form { margin: 0; }
.account button, .account .button { width: 100%; justify-content: center; }
.content { min-width: 0; }

/* ---------- the dashboard ---------- */
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.dash { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; margin-top: 16px; }
.dash h2 { font-size: 1.05rem; margin: 0 0 10px; }
.dash .card { padding: 16px 18px; }
.dash ul { list-style: none; margin: 0; padding: 0; }
.dash li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.dash li:last-child { border-bottom: 0; }
.dash li .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash li .amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dash .warn { color: var(--error); }
.dash .all-good { color: var(--good); }
.month { color: var(--muted); font-size: 0.95rem; margin: 18px 0 6px; }
/* the light/dark switch */
.switch {
  flex-direction: row; align-items: center; gap: 10px; padding: 6px 4px;
  cursor: pointer; color: var(--text); font-size: 0.9rem; user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative; flex: none; width: 40px; height: 22px; border-radius: 999px;
  background: var(--line); transition: background 0.2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
  transition: transform 0.2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons and fields ---------- */
button, .button {
  font: inherit; cursor: pointer; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px; line-height: 1.2;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.6; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.quiet, button.quiet { border-color: transparent; color: var(--accent); }
button.icon { padding: 4px 8px; border-color: transparent; background: transparent; }
button.icon:hover { background: var(--accent-soft); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled, select:disabled, input[readonly] { background: var(--bg); color: var(--muted); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); font-size: 1rem; }

/* ---------- table pages ---------- */
.title-row {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 14px;
}
.title-row .total { color: var(--muted); font-size: 1.05rem; margin-left: 12px; }
.search-row { display: flex; gap: 8px; align-items: center; }
.search-row input { max-width: 420px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 12px;
  border-radius: 999px; background: var(--accent-soft); font-size: 0.9rem;
}
.chip button { padding: 0 6px; border: 0; background: transparent; }
.add-filter summary { cursor: pointer; color: var(--accent); padding: 4px 6px; list-style: none; }
.add-filter summary::before { content: "＋ "; }
.add-filter[open] { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.add-filter select, .add-filter input { width: auto; min-width: 150px; }
.note { color: var(--muted); margin: 6px 0; font-size: 0.9rem; }
.scroll {
  overflow-x: auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--accent-soft); }
th { font-weight: 600; font-size: 0.88rem; color: var(--muted); white-space: nowrap; }
th button.sort { border: 0; background: transparent; padding: 4px 0; font-weight: 600; color: inherit; }
td.code { font-weight: 600; white-space: nowrap; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
td.notes { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.long { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.money, th.money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.loss { color: var(--error); }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; }
.lock { font-size: 0.8rem; }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 22px; background: var(--surface); color: var(--text);
  box-shadow: 0 10px 40px rgb(0 0 0 / 30%); width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgb(0 0 0 / 40%); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form small.error { margin-top: -6px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trio { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.material-row { display: grid; grid-template-columns: 1fr 110px 44px 36px; gap: 8px; align-items: end; }
.material-row .unit { color: var(--muted); padding-bottom: 8px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { color: var(--muted); padding: 0 6px; }
.preview { max-width: 120px; max-height: 120px; border-radius: 8px; object-fit: cover; }
dialog.picture { width: auto; max-width: calc(100vw - 40px); }
dialog.picture img { max-width: min(720px, calc(100vw - 80px)); max-height: calc(100vh - 160px); display: block; }
dialog.picture figure { margin: 0; }
dialog.picture figcaption { color: var(--muted); margin-top: 8px; }

/* ---------- messages ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); }
.toast.error { background: var(--error-soft); color: var(--error); border: 1px solid var(--error); }

/* ---------- sign-in and plain cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); }
.narrow { max-width: 520px; margin: 40px auto; }
.signin { max-width: 380px; margin: 8vh auto; display: flex; flex-direction: column; gap: 14px; align-items: stretch; text-align: center; }
.signin img { align-self: center; border-radius: 16px; }

/* ---------- analytics ---------- */
.figures { display: flex; flex-wrap: wrap; gap: 14px; margin: 6px 0 4px; }
.figure { min-width: 220px; flex: 0 1 260px; }
.figure .value { font-size: 1.9rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.figure .value.good { color: var(--good); }
.figure .value.bad { color: var(--error); }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 16px 0; }
.controls label { width: auto; }
.controls select, .controls input { width: auto; min-width: 140px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 12px; }
.chart .line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 6px 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }

@media (max-width: 860px) {
  /* on a phone the menu goes across the top, and the account's buttons wrap under it */
  .shell { display: block; }
  .side { position: static; height: auto; flex-direction: column; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; gap: 8px; }
  .tabs { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 2px; }
  .tabs a { white-space: nowrap; }
  .tabs .group { display: none; }
  .account { margin-top: 0; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .account button, .account .button { width: auto; }
}

@media (max-width: 720px) {
  main { padding: 14px 12px 64px; }
  .pair, .trio { grid-template-columns: 1fr; }
  .material-row { grid-template-columns: 1fr 80px 36px 32px; }
}
