@font-face {
  font-family: "Open Sans";
  src: url("/static/fonts/OpenSans.ttf") format("truetype");
  font-weight: 300 800;
  font-display: swap;
}

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --border: #e3e0d8;
  --text: #1f2421;
  --muted: #6b716c;
  --accent: #2f6f5e;
  --accent-hover: #255a4c;
  --accent-soft: #e3efea;
  --danger: #b2412e;
  --danger-soft: #f8e6e2;
  --warn: #a5650b;
  --warn-soft: #fbf0dc;
  --ok: #2f6f5e;
  --ok-soft: #e3efea;
  --neutral-soft: #ecebe6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 4px 16px rgba(20, 30, 25, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1d211f;
    --surface-2: #252a27;
    --border: #323935;
    --text: #e8ebe9;
    --muted: #9aa39e;
    --accent: #5fb39a;
    --accent-hover: #74c4ab;
    --accent-soft: #1f3a32;
    --danger: #e0806e;
    --danger-soft: #3c2420;
    --warn: #e0a85a;
    --warn-soft: #3a2e1b;
    --ok: #5fb39a;
    --ok-soft: #1f3a32;
    --neutral-soft: #2b302d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Open Sans", system-ui, -apple-system, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 700; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---------- top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 0 16px; height: 60px; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 10px; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 6px 6px 5px; border-top: 2px solid #fff; border-bottom: 2px solid #fff; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); }

.page { max-width: 1180px; margin: 0 auto; padding: 28px 16px 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: progress; }
.inline { display: inline; margin: 0; }

/* ---------- cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; gap: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.grid-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 960px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-side { grid-template-columns: minmax(0, 1fr); }
}

.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; hyphens: manual; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.kpi.danger .value { color: var(--danger); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.list td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--surface-2); }
table.list th.num, table.list td.num { text-align: right; }
table.list tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

/* ---------- badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-entwurf { background: var(--neutral-soft); color: var(--muted); }
.badge-offen { background: var(--warn-soft); color: var(--warn); }
.badge-ueberfaellig { background: var(--danger-soft); color: var(--danger); }
.badge-bezahlt { background: var(--ok-soft); color: var(--ok); }
.badge-storniert { background: var(--neutral-soft); color: var(--muted); text-decoration: line-through; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; margin-left: 6px; vertical-align: 1px; }

/* ---------- forms */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
.field { margin-bottom: 14px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
fieldset { border: 0; padding: 0; margin: 0; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select, .filters input { width: auto; min-width: 140px; }
.filters input[type=search] { flex: 1; min-width: 180px; }

/* ---------- invoice editor */
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left; padding: 0 4px 6px; font-weight: 700; }
.items td { padding: 3px 4px; vertical-align: top; }
.items input { padding: 7px 8px; font-size: 14px; }
.items .c-date { width: 150px; } .items .c-qty { width: 80px; } .items .c-unit { width: 80px; }
.items .c-price { width: 110px; } .items .c-sum { width: 110px; padding-top: 10px; } .items .c-del { width: 36px; }
.items input.num { text-align: right; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1; padding: 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--danger); background: var(--danger-soft); }
.total-line { display: flex; justify-content: flex-end; gap: 24px; font-size: 18px; font-weight: 700; padding: 14px 4px 0; border-top: 2px solid var(--border); margin-top: 10px; }

@media (max-width: 760px) {
  .items thead { display: none; }
  .items, .items tbody, .items tr, .items td { display: block; width: 100% !important; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .items td.c-desc { grid-column: 1 / -1; }
  .items td.c-date { grid-column: 1 / -1; }
  .items td.c-sum { grid-column: 1 / 3; text-align: left; }
  .items td.c-del { text-align: right; }
}

.pdf-frame { width: 100%; height: 78vh; min-height: 560px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.side-section { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 16px; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack .btn { width: 100%; }

/* ---------- flash */
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; font-size: 14px; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.callout { background: var(--warn-soft); color: var(--warn); padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; }
.callout a { color: inherit; text-decoration: underline; }

/* ---------- year chart */
.years { display: flex; align-items: flex-end; gap: 14px; height: 170px; padding-top: 10px; }
.years .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.years .col .v { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.years .col .b { width: 100%; max-width: 64px; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 3px; }
.years .col.current .b { background: var(--accent-hover); }
.years .col .y { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.login h1 { font-size: 22px; margin-bottom: 18px; display: flex; align-items: center; gap: 10px; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; max-width: 560px; width: calc(100% - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(15, 20, 18, .45); }
dialog h2 { font-size: 18px; }

@media (max-width: 640px) {
  .topbar-inner { gap: 4px 12px; height: auto; flex-wrap: wrap; padding-top: 10px; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -8px; padding-bottom: 6px; }
  .brand { font-size: 16px !important; gap: 10px !important; }
  .btn-new { padding: 7px 10px; font-size: 13px; }
  h1 { font-size: 22px; }
  .page { padding-top: 20px; }
  .kpi .value { font-size: 21px; }
  .hide-sm { display: none; }
}
