/* =========================================================================
   Rechnung — UI 2.0
   Professionelles, ruhiges Dark-Theme mit zentraler Sidebar-Navigation,
   klar strukturierten Karten und tabellarischen Ansichten.
   ========================================================================= */

:root {
  --bg:        #0b0d12;
  --bg-2:      #0f1218;
  --panel:     #151922;
  --panel-2:   #1b2030;
  --panel-3:   #232a3c;
  --border:    #262d3d;
  --border-2:  #323a4f;
  --text:      #e8ebf2;
  --text-dim:  #b6bccd;
  --muted:     #828aa0;
  --accent:    #5b8cff;
  --accent-2:  #7c5bff;
  --accent-soft: rgba(91, 140, 255, 0.12);
  --pos:       #34c47e;
  --neg:       #ff6f6f;
  --warn:      #f0b14a;
  --warn-soft: rgba(240, 177, 74, 0.10);
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 0 rgba(255,255,255,0.02), 0 8px 24px rgba(0,0,0,0.25);
  --mono:      ui-monospace, "SFMono-Regular", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --sans:      "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14.5px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 24px 0 12px; letter-spacing: -0.01em; color: var(--text); }
p  { margin: 0 0 12px; color: var(--text-dim); }

code {
  font-family: var(--mono);
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
}

/* ----- Layout ----------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
  padding: 6px 10px 22px;
}
.sidebar .brand .logo {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  color: white; font-weight: 700; font-size: 14px;
}

.sidebar .nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); padding: 14px 10px 6px;
}

.sidebar a.nav-link, .sidebar button.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 14px;
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.sidebar a.nav-link:hover, .sidebar button.nav-link:hover {
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}
.sidebar a.nav-link.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(91,140,255,0.20);
}
.sidebar .nav-icon {
  width: 18px; height: 18px; flex: 0 0 18px;
  color: currentColor; opacity: .85;
}
.sidebar .nav-spacer { flex: 1; }
.sidebar .user-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px; border-top: 1px solid var(--border); margin-top: 10px;
  font-size: 13px; color: var(--muted);
}

.main {
  min-width: 0;
  padding: 28px 36px 56px;
  max-width: 1280px;
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-head .subtitle { color: var(--muted); font-size: 13px; }

/* ----- Flash messages --------------------------------------------------- */

.flash {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid var(--border);
}
.flash.error { background: #3a1c20; color: #ffc3c3; border-color: #5b2024; }
.flash.warn  { background: var(--warn-soft); color: #f5d28b; border-color: rgba(240,177,74,0.30); }
.flash.info  { background: var(--accent-soft); color: var(--text); border-color: rgba(91,140,255,0.25); }
.flash a { color: inherit; text-decoration: underline; }

/* ----- Login ------------------------------------------------------------ */

.login-shell {
  min-height: 100vh;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(91,140,255,0.10), transparent),
              var(--bg);
}
.login-card {
  width: 360px; max-width: 92vw;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card .brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 700; margin-bottom: 18px;
}
.login-card .brand .logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: white; font-weight: 700;
}
.login-card label { display: block; margin: 12px 0; font-size: 12px; color: var(--muted); }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  margin-top: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.login-card button {
  width: 100%; margin-top: 18px; padding: 11px;
  border: 0; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; font-weight: 600; cursor: pointer;
}
.login-card button:disabled { opacity: .55; cursor: not-allowed; }

/* ----- Cards & filter bar ---------------------------------------------- */

.toolbar {
  display: flex; gap: 10px; align-items: end; flex-wrap: wrap;
  background: var(--panel);
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 18px;
}
.toolbar .field { display: flex; flex-direction: column; gap: 4px; }
.toolbar label  { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.toolbar input, .toolbar select {
  padding: 8px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  min-width: 150px;
}
.toolbar input:focus, .toolbar select:focus {
  outline: 2px solid var(--accent); outline-offset: 0;
}
.toolbar .spacer { flex: 1; }
.toolbar .checkbox {
  flex-direction: row; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-dim); text-transform: none; letter-spacing: 0;
  padding-bottom: 6px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card.row {
  display: flex; gap: 12px; align-items: end; flex-wrap: wrap;
}
.card .hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; width: 100%; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.card input, .card select {
  padding: 9px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

/* ----- Buttons --------------------------------------------------------- */

.btn, .btn-primary, .btn-secondary, .btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn, .btn-primary {
  background: var(--accent); color: white;
}
.btn:hover, .btn-primary:hover { background: #6f9bff; }
.btn-secondary {
  background: var(--panel-2); color: var(--text); border-color: var(--border);
}
.btn-secondary:hover { background: var(--panel-3); border-color: var(--border-2); }
.btn-ghost {
  background: transparent; color: var(--text-dim); border-color: transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--panel-2); }

.btn-tiny {
  padding: 4px 10px; font-size: 12px; border-radius: 6px;
  background: var(--accent); color: white; border: 0; cursor: pointer;
  font-weight: 500;
}
.btn-tiny:hover { background: #6f9bff; }
.btn-tiny.danger { background: var(--neg); }
.btn-tiny.danger:hover { background: #ff8484; }
.btn-tiny.biz { background: var(--accent-2); }
.btn-tiny.ghost {
  background: transparent; color: var(--text-dim); border: 1px solid var(--border);
}
.btn-tiny.ghost:hover { background: var(--panel-2); color: var(--text); }

/* ----- KPIs ----------------------------------------------------------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi .label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .1em;
}
.kpi .value {
  font-size: 22px; font-weight: 600; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.kpi .sub {
  font-size: 12px; color: var(--muted); margin-top: 2px;
}
.kpi .value.pos { color: var(--pos); }
.kpi .value.neg { color: var(--neg); }

/* ----- Table ---------------------------------------------------------- */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  background: var(--panel-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  position: sticky; top: 0;
}
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: rgba(255,255,255,0.015); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .pos { color: var(--pos); }
.table .neg { color: var(--neg); }
.table tr.uncat { background: rgba(240, 180, 74, 0.05); }
.table tr.uncat:hover td { background: rgba(240, 180, 74, 0.08); }

.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- Inline forms in table ----------------------------------------- */

.inline-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form select, .inline-form input[type=text] {
  padding: 5px 7px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
}
.tiny {
  font-size: 11px; color: var(--muted);
  display: inline-flex; gap: 4px; align-items: center;
}

/* ----- Badges --------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: var(--panel-2);
}
.badge.biz   { color: #c8b8ff; background: rgba(124,91,255,0.10); border-color: rgba(124,91,255,0.30); }
.badge.priv  { color: var(--text-dim); }
.badge.warn  { color: #f5d28b; background: var(--warn-soft); border-color: rgba(240,177,74,0.30); }

/* ----- Chart ---------------------------------------------------------- */

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
#catchart { width: 100%; display: block; }

/* ----- Bulk action bar ------------------------------------------------ */

.bulk-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .bulk-count { font-size: 13px; color: var(--text-dim); }
.bulk-bar select {
  padding: 7px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ----- Mobile --------------------------------------------------------- */

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap;
    padding: 12px;
  }
  .sidebar .brand { padding: 4px 8px; }
  .sidebar .nav-group-label { display: none; }
  .sidebar a.nav-link, .sidebar button.nav-link {
    padding: 8px 10px; font-size: 13px;
  }
  .sidebar .nav-spacer, .sidebar .user-row { display: none; }
  .main { padding: 18px; }
  .truncate { max-width: 180px; }
}

/* ----- Utility -------------------------------------------------------- */

.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.right { text-align: right; }
.hidden { display: none; }
