/* Büro. Same palette as Dienst: dark header, quiet surfaces, colour only
   where it carries meaning. */

:root {
  color-scheme: light;
  --bg: #dde1e6;
  --surface: #ffffff;
  --ink: #1b2128;
  --muted: #5f6a75;
  --line: #e1e5e9;
  --row-line: #eef0f3;
  --band: #f0f2f5;
  --accent: #2f5f8f;
  --accent-soft: #e9f0f8;
  --warn: #a85200;
  --warn-soft: #fff4e8;
  --good: #1a6e41;
  --good-soft: #e7f5ed;
  --bad: #b3261e;
  --bad-soft: #fdecea;
  --fz: #7a4bb0;
  --fz-soft: #efe7f8;
  --on-accent: #ffffff;
  --backdrop: rgba(10, 16, 22, 0.35);
  --hdr: #1b2128;
  --hdr-raised: #2a323b;
  --hdr-ink: #ffffff;
  --hdr-muted: #aab4bf;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0d10;
    --surface: #1d232a;
    --ink: #e6ebf0;
    --muted: #9aa6b2;
    --line: #323b45;
    --row-line: #272f38;
    --band: #262e37;
    --accent: #8db6e0;
    --accent-soft: #1c2d40;
    --warn: #f0a04b;
    --warn-soft: #33240f;
    --good: #6fd39c;
    --good-soft: #15291e;
    --bad: #f28b80;
    --bad-soft: #3a1a17;
    --fz: #c4a3ec;
    --fz-soft: #2a2038;
    --on-accent: #10161c;
    --backdrop: rgba(0, 0, 0, 0.55);
    --hdr: #212932;
    --hdr-raised: #303945;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d10; --surface: #1d232a; --ink: #e6ebf0; --muted: #9aa6b2; --line: #323b45;
  --row-line: #272f38; --band: #262e37; --accent: #8db6e0; --accent-soft: #1c2d40;
  --warn: #f0a04b; --warn-soft: #33240f; --good: #6fd39c; --good-soft: #15291e;
  --bad: #f28b80; --bad-soft: #3a1a17; --fz: #c4a3ec; --fz-soft: #2a2038;
  --on-accent: #10161c; --backdrop: rgba(0, 0, 0, 0.55); --hdr: #212932; --hdr-raised: #303945;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.4 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Header */
.hdr {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  background: var(--hdr); color: var(--hdr-ink);
  padding: 0 16px; height: 52px;
}
.brand { color: var(--hdr-ink); font-weight: 700; font-size: 18px; text-decoration: none; }
.hdr nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.hdr nav a {
  color: var(--hdr-muted); text-decoration: none; padding: 7px 12px; border-radius: 8px; white-space: nowrap;
}
.hdr nav a:hover { color: var(--hdr-ink); background: var(--hdr-raised); }
.hdr nav a.active { color: var(--hdr-ink); background: var(--hdr-raised); }
.logout button { background: none; border: 0; color: var(--hdr-muted); padding: 7px 0; }
.logout button:hover { color: var(--hdr-ink); }

main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 80px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; text-decoration: none; white-space: nowrap;
  min-height: 38px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

.btn.icon { padding: 6px 0; width: 38px; justify-content: center; font-size: 18px; }
.btn.small.icon { width: 30px; font-size: 14px; }

/* Month header */
.month-head { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; margin-bottom: 12px; }
.month-title { display: flex; align-items: center; gap: 6px; }
.month-title h1 { margin: 0 4px; font-size: 24px; min-width: 190px; text-align: center; }
.month-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }

/* Export menu */
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "▾"; font-size: 12px; color: var(--muted); }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 25; min-width: 210px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); display: flex; flex-direction: column;
}
.menu-pop a, .menu-pop button {
  display: block; text-align: left; padding: 8px 10px; border-radius: 6px; border: 0; background: none;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--band); }

/* Month summary: Anfangsbestand + Einnahmen − Ausgaben = Endbestand */
.summary {
  display: flex; align-items: stretch; flex-wrap: wrap; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.sum { display: flex; flex-direction: column; justify-content: center; padding: 8px 16px; position: relative; min-width: 0; }
.sum span { font-size: 12px; color: var(--muted); }
.sum b { font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum b.in { color: var(--good); }
.sum + .sum::before {
  position: absolute; left: -6px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 15px; width: 12px; text-align: center;
}
.sum:nth-child(2)::before { content: "+"; }
.sum:nth-child(3)::before { content: "−"; }
.sum:nth-child(4)::before { content: "="; }
.sum.total { background: var(--band); }
.sum.total.bad b { color: var(--bad); }
.sum.start input {
  border: 0; border-bottom: 1px dashed var(--line); padding: 0; background: none; font: inherit;
  font-size: 17px; font-weight: 700; width: 110px; font-variant-numeric: tabular-nums; color: var(--ink);
}
.sum.start input::placeholder { font-weight: 400; color: var(--accent); }
.sum.start input:focus { outline: none; border-bottom-color: var(--accent); }
.sum-meta { margin-left: auto; display: flex; align-items: center; gap: 10px; padding: 8px 14px; color: var(--muted); font-size: 14px; }
.pill { border: 1px solid transparent; border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.pill.warn:hover { filter: brightness(1.05); }

@media (max-width: 760px) {
  .month-title { width: 100%; justify-content: space-between; }
  .month-title h1 { min-width: 0; font-size: 21px; }
  .month-actions { width: 100%; margin-left: 0; }
  .month-actions > .btn.primary { flex: 1; justify-content: center; }
  .summary { display: grid; grid-template-columns: 1fr 1fr; }
  .sum { padding: 8px 12px; border-top: 1px solid var(--row-line); }
  .sum:nth-child(-n+2) { border-top: 0; }
  .sum + .sum::before { content: none !important; }
  .sum-meta { grid-column: 1 / -1; margin-left: 0; border-top: 1px solid var(--row-line); justify-content: space-between; }
}

/* Drop zone */
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface);
  padding: 34px 16px; text-align: center; color: var(--muted); margin-bottom: 12px;
}
.drop b { color: var(--ink); display: block; font-size: 17px; margin-bottom: 4px; }
body.dragging .drop, .drop.over { border-color: var(--accent); background: var(--accent-soft); }

/* List */
.list {
  background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden;
  container-type: inline-size;
}
.row {
  display: grid;
  grid-template-columns: 44px 52px 92px minmax(0, 1fr) 150px 54px 110px;
  align-items: center; gap: 10px;
  padding: 8px 12px; border-top: 1px solid var(--row-line);
  cursor: pointer; background: var(--surface);
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--band); }
.row.selected { background: var(--accent-soft); }
.nr { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.thumb {
  width: 44px; height: 44px; border-radius: 6px; background: var(--band); object-fit: cover; display: block;
  border: 1px solid var(--line);
}
.thumb.none { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }
.what { min-width: 0; }
.what .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.what .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.what .sub.warn { color: var(--warn); }
.what .sub.bad { color: var(--bad); }
.konto { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.konto b { color: var(--ink); font-weight: 500; }
.badge {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  background: var(--band); color: var(--muted);
}
.badge.fz { background: var(--fz-soft); color: var(--fz); }
.amount { font-weight: 600; }
.amount.in { color: var(--good); }
.amount small, .date small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.amount .saldo.bad { color: var(--bad); font-weight: 600; }
.row.reading .what .title { color: var(--muted); }
.spinner {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
  vertical-align: -1px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* Narrow list: on phones, and beside the open booking on desktop. */
@container (max-width: 680px) {
  .row { grid-template-columns: 44px minmax(0, 1fr) auto; grid-template-areas: "t w a" "t k a"; row-gap: 2px; }
  .row .nr, .row .date, .row .kst { display: none; }
  .row .thumbcell { grid-area: t; grid-row: 1 / 3; }
  .row .what { grid-area: w; }
  .row .konto { grid-area: k; }
  .row .amount { grid-area: a; grid-row: 1 / 3; }
}

/* Workspace: the list, and the open booking docked beside it on wide
   screens (full screen on smaller ones). */
main:has(.workspace > .panel) { max-width: 1680px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
  container-type: inline-size;
}
@media (min-width: 1100px) {
  /* App shell while a booking is open: the list scrolls in its column, the
     booking fills the rest of the window. */
  main:has(.workspace > .panel) {
    height: calc(100dvh - 52px); padding-bottom: 14px; display: flex; flex-direction: column;
  }
  main:has(.workspace > .panel) > :not(.workspace) { flex: none; }
  .workspace:has(> .panel) {
    flex: 1 1 0; min-height: 0;
    grid-template-columns: minmax(380px, 480px) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  }
  .workspace:has(> .panel) > .listcol { height: 100%; overflow-y: auto; border-radius: var(--radius); }
  .workspace > .panel { height: 100%; }
}
@media (max-width: 1099px) {
  .panel { position: fixed; inset: 0; z-index: 31; border: 0; border-radius: 0; }
  body:has(.panel) { overflow: hidden; }
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel.photo-off [data-act="toggle-photo"] { color: var(--muted); text-decoration: line-through; }
.panel-body { display: grid; min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(140px, 38%) minmax(0, 1fr); }
.panel.photo-off .panel-body { grid-template-rows: minmax(0, 1fr); }
.panel.photo-off .photo { display: none; }
@container (min-width: 760px) {
  .panel-body { grid-template-rows: none; grid-template-columns: minmax(0, 1fr) 380px; }
  .panel.photo-off .panel-body { grid-template-columns: minmax(0, 1fr); }
  .panel.photo-off .form { max-width: 560px; }
}

.photo { background: #14181c; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; min-height: 0; }
.photo img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; display: block; }
.photo .nophoto { color: #aaa; text-align: center; padding: 20px; }
.photo iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.photo-tools {
  position: absolute; right: 10px; bottom: 10px; display: flex; gap: 2px; padding: 3px;
  background: rgba(20, 24, 28, .78); border-radius: 10px; backdrop-filter: blur(4px);
}
.photo-tools button {
  width: 36px; height: 36px; border: 0; border-radius: 8px; background: none; color: #fff; font-size: 19px; line-height: 1;
}
.photo-tools button:hover { background: rgba(255, 255, 255, .16); }
.busy img { opacity: .45; transition: opacity .15s; }
.busy .photo-tools button { pointer-events: none; opacity: .5; }

/* Full-screen photo */
.viewer { position: fixed; inset: 0; z-index: 40; background: rgba(8, 10, 12, .94); }
.viewer-scroll { position: absolute; inset: 0; overflow: auto; display: flex; padding: 16px; }
.viewer-scroll img { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; }
.viewer.zoom .viewer-scroll img { max-width: none; max-height: none; cursor: zoom-out; }
.viewer .photo-tools { right: 50%; transform: translateX(50%); bottom: 18px; }

.form { overflow-y: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.form > * { flex-shrink: 0; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form input, .form select, .form textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface);
  font-size: 15px; color: var(--ink); width: 100%;
}
.form textarea { min-height: 70px; resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.form .pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--surface); padding: 8px 6px; font-size: 14px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--on-accent); font-weight: 500; }
.seg button.on.fz { background: var(--fz); }
.hint {
  border-radius: 8px; padding: 9px 12px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start;
  background: var(--warn-soft); color: var(--warn);
}
.hint.bad { background: var(--bad-soft); color: var(--bad); }
.hint p { margin: 0; flex: 1; }
.form .actions { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; }
.saved { font-size: 13px; color: var(--muted); min-width: 80px; text-align: right; }
.saved.ok { color: var(--good); }
.saved.err { color: var(--bad); }

/* Pages */
.page { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 22px; }
.page h1 { margin-top: 0; font-size: 22px; }
.page ol li { margin-bottom: 8px; }
.bookmarklet {
  display: inline-block; padding: 10px 16px; border-radius: 8px; background: var(--accent); color: var(--on-accent);
  font-weight: 600; text-decoration: none; cursor: grab;
}
code, .mono { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 13px; }
pre { background: var(--band); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--hdr); color: var(--hdr-ink); padding: 10px 16px; border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }

/* Login */
body.login { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  background: var(--surface); border-radius: 14px; padding: 28px; width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 14px; border: 1px solid var(--line);
}
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 16px; background: var(--surface); color: var(--ink); }
.login-error { color: var(--bad) !important; }
