/* DATEV-Webportal – Mandantenfarben kommen über --brand und --accent. */
:root {
  --brand: #1f4e79;
  --accent: #f28c28;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --grid: rgba(100, 116, 139, 0.15);
  --good: #15803d;
  --bad: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 16px rgba(15, 23, 42, 0.05);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--brand); }
code { font: 0.85em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--bad); }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* Layout */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--brand);
  color: #fff;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar a { color: inherit; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand img { max-height: 44px; max-width: 120px; background: #fff; border-radius: 8px; padding: 4px; object-fit: contain; }
.brand-mark {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; letter-spacing: 0.5px; flex: none;
}
.brand-name { font-size: 1.02rem; }
.switcher { display: grid; gap: 4px; font-size: 0.78rem; opacity: 0.9; }
.switcher select { background: rgba(255, 255, 255, 0.14); color: #fff; border-color: rgba(255, 255, 255, 0.25); }
.switcher option { color: var(--text); }
.nav { display: grid; gap: 2px; }
.nav a { padding: 9px 12px; border-radius: 8px; opacity: 0.85; }
.nav a:hover { background: rgba(255, 255, 255, 0.1); opacity: 1; }
.nav a.active { background: rgba(255, 255, 255, 0.18); opacity: 1; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; display: grid; gap: 6px; font-size: 0.85rem; opacity: 0.85; }
.sidebar-foot .link { color: #fff; }

.main { padding: 28px 32px 48px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; max-width: 820px; }
.toolbar { display: flex; gap: 8px; align-items: center; }

/* Karten */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card.danger { border-color: #fecaca; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.empty { text-align: center; padding: 40px; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; align-items: start; }
.two-col > .card { margin-bottom: 0; }
.stack { display: grid; gap: 16px; }
.stack > .card { margin-bottom: 0; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat-row .card { margin: 0; }
.stat { display: grid; gap: 2px; }
.stat strong { font-size: 1.3rem; }

/* Formulare */
input, select, textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
input[type="color"] { height: 42px; padding: 4px; }
input[type="checkbox"] { width: auto; }
label { display: grid; gap: 4px; font-size: 0.88rem; font-weight: 550; }
label small { font-weight: 400; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form-grid { display: grid; gap: 12px; }
.form-grid .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form select, .inline-form input { width: auto; }
fieldset { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
legend { font-size: 0.85rem; font-weight: 600; padding: 0 4px; }
.effect-row { display: grid; grid-template-columns: 2fr 1fr 1.3fr auto; gap: 8px; }
.formula-result { font-weight: 400; min-height: 1.2em; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 550; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { padding: 4px 10px; font-size: 0.82rem; }
.link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-align: left; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.add-box { margin-top: 12px; }
.add-box[open] > summary { margin-bottom: 12px; }
.popover { position: absolute; right: 0; top: 100%; z-index: 30; width: min(560px, 80vw); margin-top: 6px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18); text-align: left; white-space: normal; }

/* Tabellen */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
.table.compact th, .table.compact td { padding: 6px 8px; }
.table td input, .table td select { padding: 5px 8px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions > * { display: inline-block; vertical-align: top; margin-left: 4px; }
.row-actions details { position: relative; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: 0.8rem; }
.badge.ok { background: #dcfce7; border-color: #bbf7d0; color: var(--good); }
ul.plain { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 4px; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid var(--line); background: var(--surface); }
.flash-ok { border-color: #bbf7d0; background: #f0fdf4; }
.flash-error { border-color: #fecaca; background: #fef2f2; color: var(--bad); }

/* Mandanten-Übersicht */
.tenant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.tenant-card {
  display: grid; gap: 6px; padding: 0 0 16px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; transition: transform 0.15s, box-shadow 0.15s;
}
.tenant-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1); }
.tenant-card > strong, .tenant-card > span { padding: 0 16px; }
.tenant-card-top { height: 86px; background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 65%, var(--accent))); display: flex; align-items: center; padding: 0 16px; margin-bottom: 6px; }
.tenant-card-top img { max-height: 52px; max-width: 150px; background: #fff; padding: 4px; border-radius: 8px; }
.logo-preview { max-height: 80px; max-width: 240px; display: block; margin-bottom: 12px; }

.login-card { max-width: 380px; margin: 10vh auto; }
.login-card form { display: grid; gap: 12px; }

/* Dashboard */
.edit-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; position: sticky; top: 8px; z-index: 20; border-color: var(--accent); }
.edit-bar .inline-form { flex: 1; }
.grid-stack { min-height: 200px; }
.grid-stack-item-content.widget {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; inset: 0;
}
.widget-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px 4px; }
.widget-head h3 { margin: 0; font-size: 0.86rem; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.widget-remove { display: none; border: 0; background: var(--surface-2); border-radius: 6px; cursor: pointer; color: var(--muted); padding: 2px 8px; }
.editing .widget-remove { display: block; }
.editing .widget-head { cursor: move; }
.editing .widget { outline: 2px dashed color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: -2px; }
.widget-body { flex: 1; min-height: 0; padding: 4px 16px 14px; position: relative; }
.widget-body.scroll { overflow-y: auto; }
.chart-box { position: relative; height: 100%; min-height: 120px; }
.chart-box.tall { height: 380px; }
.widget-tile .widget-body { display: flex; flex-direction: column; }
.tile-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: var(--text); }
.tile-delta .delta { font-weight: 600; }
.tile-delta .delta.good { color: var(--good); }
.tile-delta .delta.bad { color: var(--bad); }
.tile-spark { flex: 1; min-height: 24px; position: relative; margin-top: 4px; }

/* Schieberegler */
.driver { padding: 10px 0; border-bottom: 1px solid var(--line); }
.driver:last-of-type { border-bottom: 0; }
.driver-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.driver-head label { font-weight: 600; }
.driver-head output { font-weight: 700; font-variant-numeric: tabular-nums; }
.driver.changed .driver-head output { color: var(--accent); }
.driver-foot { display: grid; gap: 2px; }
.driver.changed .delta { color: var(--accent); font-weight: 600; }
.driver.start { margin-bottom: 8px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px; padding: 0; border: 0; border-radius: 99px; margin: 10px 0 6px;
  background: linear-gradient(to right, var(--accent) 0 var(--fill, 50%), var(--line) var(--fill, 50%) 100%);
}
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); cursor: pointer; }
input[type="range"]:focus { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); }

.forecast-layout { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 16px; align-items: start; }
.forecast-layout .card { margin: 0; }
.forecast-layout .wide { grid-column: 1 / -1; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; gap: 12px; padding: 14px 16px; }
  .nav { display: flex; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; padding: 7px 10px; }
  .nav a.active { box-shadow: inset 0 -3px 0 var(--accent); }
  .sidebar-foot { flex-direction: row; display: flex; flex-wrap: wrap; gap: 4px 14px; }
  .popover { position: static; width: auto; }
  .main { padding: 20px 16px 40px; }
  .forecast-layout { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .popover { min-width: 0; }
  .table { display: block; overflow-x: auto; }
  .effect-row { grid-template-columns: 1fr 1fr; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #111a2e; --surface-2: #0f172a; --text: #e2e8f0; --muted: #94a3b8;
    --line: #1e293b; --grid: rgba(148, 163, 184, 0.12); --good: #4ade80; --bad: #f87171;
    color-scheme: dark;
  }
  a { color: color-mix(in srgb, var(--brand) 40%, #fff); }
  .flash-ok { background: #052e16; border-color: #14532d; }
  .flash-error { background: #450a0a; border-color: #7f1d1d; }
  .badge.ok { background: #052e16; border-color: #14532d; }
  .card.danger { border-color: #7f1d1d; }
}
