:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #6b7385;
  --border: #dde2ea;
  --primary: #2457c5;
  --primary-hover: #1c47a3;
  --danger: #c0392b;
  --success-bg: #e5f5ea; --success-fg: #1e6b39;
  --error-bg: #fdecea; --error-fg: #9b2c22;
  --info-bg: #e8f0fd; --info-fg: #1f4aa0;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 1px 6px rgba(20, 30, 50, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --surface: #1d2129; --text: #e4e7ee; --muted: #9aa2b4; --border: #313745;
    --primary: #5a8bf0; --primary-hover: #7aa2f5; --danger: #e5675a;
    --success-bg: #173826; --success-fg: #8fe0ae;
    --error-bg: #42201d; --error-fg: #f3aaa2;
    --info-bg: #1c2b4a; --info-fg: #a9c3f7;
  }
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); font-weight: normal; }
.pre { white-space: pre-wrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: .6rem 1.5rem;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); font-size: 1.1rem; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { padding: .4rem .7rem; border-radius: 6px; color: var(--text); }
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: var(--primary); color: #fff; }
.logout { display: flex; align-items: center; gap: .5rem; }
.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1rem; overflow-x: auto;
}
.card.warn { border-left: 4px solid var(--danger); }
.card.narrow { max-width: 420px; margin: 3rem auto; }
.card p:last-child { margin-bottom: 0; }
.grid-2, .grid-3 { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.grid-2, .grid-3 { margin-bottom: 1rem; }
.login h1 { margin-bottom: 1.25rem; text-align: center; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; display: flex; flex-direction: column; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

/* Buttons */
.btn {
  display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .45rem .9rem; border-radius: 6px; font: inherit; cursor: pointer; line-height: 1.2; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
.btn.wide { width: 100%; margin-top: .5rem; }
form.inline { display: inline; }

/* Forms */
fieldset { border: none; padding: 0; margin: 0 0 1.25rem; }
legend { font-weight: 600; margin-bottom: .6rem; font-size: 1.02rem; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; min-width: 160px; }
.field.grow { flex: 1; }
.field.small { max-width: 130px; min-width: 90px; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
label { font-size: .88rem; font-weight: 500; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search],
input[type=date], input[type=datetime-local], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 500; padding-top: 1.6rem; }
.field > .check:first-child { padding-top: 0; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.error { color: var(--danger); font-size: .85rem; }
.form-actions { display: flex; gap: .5rem; }
.filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 240px; }
.filters select { width: auto; }
.upload { display: flex; gap: .5rem; align-items: center; margin-top: .75rem; flex-wrap: wrap; }
.add-item { margin-top: 1rem; align-items: flex-end; }
.copy-row { display: flex; gap: .5rem; margin-bottom: .5rem; }
.narrow-form { max-width: 400px; }
.hidden { display: none !important; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: var(--bg); }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tfoot td { border-bottom: none; }
.table tfoot tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 .75rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }

/* Flash */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash-success { background: var(--success-bg); color: var(--success-fg); }
.flash-error { background: var(--error-bg); color: var(--error-fg); }
.flash-info, .flash-message { background: var(--info-bg); color: var(--info-fg); }

/* Badges */
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; vertical-align: middle; white-space: nowrap; }
.status-angefragt { background: #fff3cd; color: #7a5a00; }
.status-bestaetigt { background: #d9f2e1; color: #1e6b39; }
.status-abgeschlossen { background: #e3e7ee; color: #3d4556; }
.status-storniert { background: #f8dcd9; color: #8e2a20; text-decoration: line-through; }
.inv-entwurf { background: #e3e7ee; color: #3d4556; }
.inv-verschickt { background: #dce8fb; color: #1f4aa0; }
.inv-bezahlt { background: #d9f2e1; color: #1e6b39; }
.inv-storniert { background: #f8dcd9; color: #8e2a20; }
.badge.overdue { background: var(--danger); color: #fff; }

/* Calendar */
.calendar {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--border); gap: 1px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.cal-head { background: var(--surface); padding: .5rem; font-weight: 600; text-align: center; color: var(--muted); font-size: .85rem; }
.cal-day { background: var(--surface); min-height: 110px; padding: .3rem .25rem; display: flex; flex-direction: column; gap: 2px; }
.cal-day.weekend { background: color-mix(in srgb, var(--surface) 92%, var(--border)); }
.cal-day.other { opacity: .45; }
.cal-day.today .cal-date span { background: var(--primary); color: #fff; border-radius: 999px; padding: 0 .45rem; }
.cal-date { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; padding: 0 .2rem; }
.cal-add { visibility: hidden; color: var(--muted); }
.cal-day:hover .cal-add { visibility: visible; }
.cal-event {
  display: block; font-size: .78rem; padding: .1rem .35rem; border-radius: 3px; color: inherit;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-event:hover { text-decoration: none; filter: brightness(.95); }
.cal-setup { font-weight: 700; }
.legend { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }

@media (max-width: 700px) {
  .container { padding: 1rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .cal-day { min-height: 70px; }
  .cal-event { font-size: .7rem; }
}

@media print {
  .topbar, .actions, .filters, .upload, .add-item, form.inline { display: none !important; }
  .card { box-shadow: none; border: none; }
}
