/* ===== CMertes ERP – Theme & Layout ===== */
:root {
  --gold: #c8a24a;
  --gold-soft: rgba(200, 162, 74, 0.14);
  --radius: 10px;
  --sidebar-w: 240px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Light theme (default) */
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f7f7f5;
  --border: #e4e3dd;
  --text: #16150f;
  --text-muted: #6b6a64;
  --sidebar-bg: #1b1c22;
  --sidebar-text: #c9c8c0;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: rgba(255,255,255,0.06);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --logo-light: block;
  --logo-dark: none;

  /* status */
  --st-good: #0ca30c;
  --st-good-bg: rgba(12,163,12,0.12);
  --st-warn: #d98a00;
  --st-warn-bg: rgba(217,138,0,0.14);
  --st-crit: #d03b3b;
  --st-crit-bg: rgba(208,59,59,0.12);
  --st-info: #2a78d6;
  --st-info-bg: rgba(42,120,214,0.12);
  --st-neutral-bg: rgba(120,120,120,0.14);

  /* charts */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --chart-grid: #e1e0d9;
  --chart-axis: #898781;
}

:root[data-theme="dark"] {
  --bg: #0e0f13;
  --surface: #191b21;
  --surface-2: #15171c;
  --border: #2a2d35;
  --text: #f2f1ea;
  --text-muted: #9b9a90;
  --sidebar-bg: #131418;
  --sidebar-text: #b7b6ad;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: rgba(255,255,255,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --logo-light: none;
  --logo-dark: block;

  --st-good: #23b95a; --st-good-bg: rgba(35,185,90,0.16);
  --st-warn: #e0a52a; --st-warn-bg: rgba(224,165,42,0.16);
  --st-crit: #e66767; --st-crit-bg: rgba(230,103,103,0.16);
  --st-info: #3987e5; --st-info-bg: rgba(57,135,229,0.16);
  --st-neutral-bg: rgba(255,255,255,0.09);

  --series-1: #3987e5;
  --series-2: #d95926;
  --chart-grid: #2c2c2a;
  --chart-axis: #898781;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 20;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

.brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex; align-items: center; justify-content: center;
}
.brand img { max-width: 100%; height: 34px; object-fit: contain; }
.brand .logo-l { display: var(--logo-light); }
.brand .logo-d { display: var(--logo-dark); }

.nav { padding: 8px 0 20px; flex: 1; }
.nav-group-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: rgba(255,255,255,0.32); padding: 14px 18px 5px; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 18px; color: var(--sidebar-text);
  font-size: 13.5px; cursor: pointer; border: none; background: none;
  width: 100%; text-align: left; transition: background .12s, color .12s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.nav-item.active {
  background: var(--sidebar-hover); color: var(--sidebar-text-active);
  border-left-color: var(--gold);
}
.nav-item .ico { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.nav-item.active .ico { opacity: 1; }

/* ===== Main ===== */
.main {
  margin-left: var(--sidebar-w);
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}
.topbar {
  height: 58px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 17px; font-weight: 650; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); display: grid; place-items: center;
  transition: background .12s;
}
.icon-btn:hover { background: var(--surface-2); }
.user-chip {
  display: flex; align-items: center; gap: 9px; padding: 5px 12px 5px 5px;
  border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--gold);
  color: #1b1c22; display: grid; place-items: center; font-weight: 700; font-size: 12px;
}

.content { padding: 24px; flex: 1; }

/* ===== Cards / tiles ===== */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 16px; margin-bottom: 22px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.tile .label { font-size: 12px; color: var(--text-muted); font-weight: 600; display:flex; align-items:center; gap:7px; }
.tile .value { font-size: 25px; font-weight: 700; margin-top: 7px; letter-spacing: -0.01em; }
.tile .sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.tile .dot { width:8px;height:8px;border-radius:50%; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-head { padding: 15px 18px; border-bottom: 1px solid var(--border); display:flex; align-items:center; gap:12px; }
.card-head h2 { font-size: 15px; font-weight: 650; }
.card-head .spacer { flex:1; }
.card-body { padding: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1000px){ .grid-2 { grid-template-columns: 1fr; } }

/* ===== Toolbar (list) ===== */
.toolbar { display:flex; align-items:center; gap:12px; margin-bottom:16px; flex-wrap: wrap; }
.search {
  display:flex; align-items:center; gap:8px; background: var(--surface);
  border:1px solid var(--border); border-radius: 8px; padding: 0 12px; height:38px; min-width: 280px; flex:1; max-width: 460px;
}
.search input { border:none; background:none; outline:none; color: var(--text); font-size:14px; width:100%; }
.search svg { color: var(--text-muted); flex-shrink:0; }
.select {
  height:38px; border:1px solid var(--border); border-radius:8px; background: var(--surface);
  color: var(--text); padding: 0 10px; font-size: 13.5px;
}
.count-badge { font-size: 13px; color: var(--text-muted); }

/* ===== Table ===== */
.table-wrap { background: var(--surface); border:1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 700; padding: 11px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap; cursor: pointer; user-select: none;
}
thead th.no-sort { cursor: default; }
thead th .arrow { opacity:.5; font-size:10px; margin-left:3px; }
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr.clickable:hover { background: var(--surface-2); cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.strong { font-weight: 650; }

/* pagination */
.pager { display:flex; align-items:center; justify-content:flex-end; gap:6px; padding: 12px 16px; }
.pager button { min-width: 34px; height: 32px; border:1px solid var(--border); background: var(--surface); border-radius:7px; color: var(--text); font-size:13px; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager button.active { background: var(--gold); border-color: var(--gold); color:#1b1c22; font-weight:700; }

/* ===== Status pills ===== */
.pill { display:inline-flex; align-items:center; gap:6px; font-size:12px; font-weight:650; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.pill svg { width: 12px; height: 12px; }
.pill.good { color: var(--st-good); background: var(--st-good-bg); }
.pill.warn { color: var(--st-warn); background: var(--st-warn-bg); }
.pill.crit { color: var(--st-crit); background: var(--st-crit-bg); }
.pill.info { color: var(--st-info); background: var(--st-info-bg); }
.pill.neutral { color: var(--text-muted); background: var(--st-neutral-bg); }

/* ===== Detail view ===== */
.detail-head { display:flex; align-items:flex-start; gap:16px; margin-bottom: 20px; flex-wrap: wrap; }
.detail-head .back { }
.detail-title { font-size: 22px; font-weight: 700; }
.detail-sub { color: var(--text-muted); margin-top: 2px; }
.kv { display:grid; grid-template-columns: 150px 1fr; gap: 9px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-muted); }
.kv dd { font-weight: 550; }
.doc-items th, .doc-items td { font-size: 13px; }

.empty { text-align:center; color: var(--text-muted); padding: 48px 20px; }
.empty svg { opacity:.4; margin-bottom: 10px; }

/* chart */
.legend { display:flex; gap:16px; flex-wrap:wrap; margin-top: 12px; font-size: 12.5px; color: var(--text-muted); }
.legend span { display:inline-flex; align-items:center; gap:6px; }
.legend i { width:11px; height:11px; border-radius:3px; display:inline-block; }
.bar-tip, .arc-tip { fill: var(--text); }

.spinner { display:inline-block; width:20px;height:20px;border:2.5px solid var(--border); border-top-color: var(--gold); border-radius:50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-wrap { display:grid; place-items:center; padding: 60px; }

.section-links { display:flex; gap:8px; flex-wrap:wrap; margin-top: 4px; }
.chip-link { font-size: 12.5px; padding: 4px 10px; border:1px solid var(--border); border-radius: 20px; color: var(--text-muted); background:none; }
.chip-link:hover { border-color: var(--gold); color: var(--text); }

/* ===== Buttons ===== */
.btn { display:inline-flex; align-items:center; gap:7px; height:36px; padding:0 15px; border-radius:8px;
  font-size:13.5px; font-weight:600; border:1px solid var(--border); background:var(--surface); color:var(--text); transition:all .12s; }
.btn:hover { background:var(--surface-2); }
.btn.primary { background:var(--gold); border-color:var(--gold); color:#1b1c22; }
.btn.primary:hover { filter:brightness(1.07); }
.btn.danger { color:var(--st-crit); border-color:var(--st-crit); background:transparent; }
.btn.danger:hover { background:var(--st-crit-bg); }
.btn.small { height:30px; padding:0 11px; font-size:12.5px; }
.btn:disabled { opacity:.5; cursor:default; }

/* ===== Modal ===== */
.modal-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.55); z-index:100; display:grid; place-items:center; padding:20px; }
.modal { background:var(--surface); border:1px solid var(--border); border-radius:14px; box-shadow:0 18px 50px rgba(0,0,0,.4);
  width:100%; max-width:680px; max-height:92vh; display:flex; flex-direction:column; }
.modal.wide { max-width:860px; }
.modal-head { padding:16px 20px; border-bottom:1px solid var(--border); display:flex; align-items:center; }
.modal-head h2 { font-size:16px; font-weight:700; flex:1; }
.modal-body { padding:20px; overflow-y:auto; }
.modal-foot { padding:14px 20px; border-top:1px solid var(--border); display:flex; gap:10px; justify-content:flex-end; }

/* ===== Forms ===== */
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px 16px; }
.form-grid .full { grid-column:1 / -1; }
.field label { display:block; font-size:12px; font-weight:650; color:var(--text-muted); margin-bottom:5px; }
.field input, .field select, .field textarea {
  width:100%; height:38px; border:1px solid var(--border); border-radius:8px; background:var(--surface-2);
  color:var(--text); padding:0 11px; font-size:13.5px; font-family:inherit; outline:none;
}
.field textarea { height:auto; min-height:72px; padding:9px 11px; resize:vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color:var(--gold); }
.field input[type=checkbox] { width:17px; height:17px; accent-color:var(--gold); }
.field.checkbox { display:flex; align-items:center; gap:9px; }
.field.checkbox label { margin:0; }
.field input[type=date] { color-scheme: dark; }
:root[data-theme="light"] .field input[type=date] { color-scheme: light; }

/* ===== Toast ===== */
.toast-wrap { position:fixed; bottom:22px; right:22px; z-index:200; display:flex; flex-direction:column; gap:8px; }
.toast { background:var(--surface); border:1px solid var(--border); border-left:4px solid var(--st-good);
  border-radius:9px; padding:11px 16px; box-shadow:var(--shadow); font-size:13.5px; min-width:230px; animation:slidein .18s ease-out; }
.toast.error { border-left-color:var(--st-crit); }
@keyframes slidein { from { transform:translateX(30px); opacity:0; } to { transform:none; opacity:1; } }

/* ===== Positionseditor ===== */
.items-editor table { width:100%; }
.items-editor td { padding:6px 6px; vertical-align:top; border-bottom:1px solid var(--border); }
.items-editor input, .items-editor textarea { width:100%; border:1px solid var(--border); border-radius:7px;
  background:var(--surface-2); color:var(--text); padding:7px 9px; font-size:13px; font-family:inherit; outline:none; }
.items-editor textarea { min-height:34px; resize:vertical; }
.items-editor input:focus, .items-editor textarea:focus { border-color:var(--gold); }
.items-editor .line-total { text-align:right; font-variant-numeric:tabular-nums; font-weight:650; padding-top:14px; white-space:nowrap; }
.items-editor .rm { color:var(--st-crit); background:none; border:none; font-size:17px; padding:10px 4px 0; }

/* ===== Übersicht (klickbare Kacheln) ===== */
.tile.clickable { cursor:pointer; transition:border-color .12s, transform .08s; }
.tile.clickable:hover { border-color:var(--gold); }
.tile.clickable.active { border-color:var(--gold); box-shadow:0 0 0 1px var(--gold); }
.tile .value.neg { color:var(--st-crit); }
.tile .value.pos { color:var(--st-good); }

/* ===== Dropdown ===== */
.dropdown { position:relative; }
.dropdown-menu { position:absolute; top:calc(100% + 6px); left:0; z-index:50; background:var(--surface);
  border:1px solid var(--border); border-radius:10px; box-shadow:0 10px 30px rgba(0,0,0,.3); min-width:230px; padding:6px; }
.dropdown-menu button.item { display:flex; width:100%; text-align:left; padding:9px 12px; border:none; background:none;
  color:var(--text); font-size:13.5px; border-radius:7px; align-items:center; gap:8px; }
.dropdown-menu button.item:hover { background:var(--surface-2); }
.dropdown-menu button.item.selected { font-weight:700; }
.dropdown-menu .custom-range { padding:10px 12px; border-top:1px solid var(--border); margin-top:6px; display:grid; gap:8px; }
.range-label { font-size:13px; color:var(--text-muted); }
.range-label strong { color:var(--text); }

/* Kontakt-/Bankkarten */
.subcard { border:1px solid var(--border); border-radius:9px; padding:12px 14px; margin-bottom:10px; display:flex; gap:12px; align-items:flex-start; }
.subcard .grow { flex:1; min-width:0; }
.subcard .title { font-weight:650; font-size:13.5px; }
.subcard .sub { font-size:12.5px; color:var(--text-muted); margin-top:2px; }
.subcard .actions { display:flex; gap:6px; flex-shrink:0; }

/* v0.7 – Tabellen-Summen, kleine Auswahl, negative Werte in Tabellen */
tfoot td { border-top: 2px solid var(--border); font-weight: 600; }
td.num.neg { color: var(--st-crit); }
.select.small { padding: 3px 6px; font-size: 12px; height: auto; }
