/* ============================================================
   Zentrale — "Ledger Precision"
   Newsreader (display/serif) + Public Sans (UI) + Spline Sans Mono (numbers)
   ============================================================ */

:root {
  --bg: #faf7f2;
  --bg-elevated: #ffffff;
  --bg-sidebar: #f2ede4;
  --ink: #1a1a17;
  --ink-dim: #5c5850;
  --ink-faint: #8a8578;
  --border: #e2dccd;
  --border-strong: #cfc7b2;

  --green: #2d5d46;
  --green-strong: #1f4634;
  --green-tint: #e5efe9;

  --gold: #c08a3e;
  --gold-tint: #f7ecd8;

  --red: #a8402e;
  --red-tint: #f6e7e3;

  --shadow-card: 0 1px 2px rgba(26, 26, 23, 0.04), 0 4px 16px rgba(26, 26, 23, 0.06);
  --shadow-lifted: 0 4px 8px rgba(26, 26, 23, 0.06), 0 12px 32px rgba(26, 26, 23, 0.1);

  --font-display: "Newsreader", Georgia, serif;
  --font-ui: "Public Sans", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, monospace;

  --radius: 10px;
  --radius-sm: 6px;
}

:root[data-theme="dark"] {
  --bg: #16181b;
  --bg-elevated: #1e2124;
  --bg-sidebar: #131517;
  --ink: #ede9e0;
  --ink-dim: #a8a297;
  --ink-faint: #736e63;
  --border: #2c2f33;
  --border-strong: #3a3d41;

  --green: #4f9c7d;
  --green-strong: #6bb897;
  --green-tint: #1c2b25;

  --gold: #d9a75a;
  --gold-tint: #2b2419;

  --red: #d67a68;
  --red-tint: #2e1e1b;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 16px rgba(0, 0, 0, 0.28);
  --shadow-lifted: 0 4px 8px rgba(0, 0, 0, 0.24), 0 16px 40px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

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

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, var(--green-tint), transparent 45%),
    radial-gradient(circle at 85% 80%, var(--gold-tint), transparent 45%),
    var(--bg);
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lifted);
}

.card h1 {
  font-size: 1.6rem;
  margin-bottom: 24px;
}

.card .subtitle {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--ink-faint);
  margin: -18px 0 24px;
}

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  margin: 0 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.92rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-tint);
}

input::placeholder { color: var(--ink-faint); }

button {
  font-family: var(--font-ui);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: filter 0.15s ease, transform 0.1s ease;
}

button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:disabled:active { transform: none; }

.card button[type="submit"] {
  width: 100%;
  background: var(--green);
  color: #fdfbf7;
  padding: 12px;
  margin-top: 4px;
}

.card button[type="submit"]:hover { filter: brightness(1.08); }

.error { color: var(--red); font-size: 0.85rem; min-height: 1.2em; margin: -8px 0 4px; }

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  display: flex;
  align-items: baseline;
  padding: 0 8px;
  margin-bottom: 32px;
}

.sidebar .brand h1 {
  font-size: 1.15rem;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  text-decoration: none;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease, color 0.15s ease;
  box-sizing: border-box;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--ink);
}

.nav-item .num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
  width: 16px;
}

.nav-item[aria-current="true"] {
  background: var(--bg-elevated);
  color: var(--green-strong);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}

.nav-item[aria-current="true"] .num { color: var(--green); }

.nav-item[aria-current="true"]::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--green);
  border-radius: 0 3px 3px 0;
}

.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 100px;
  background: var(--gold);
  color: #fdfbf7;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-badge[hidden] { display: none; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink-dim);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font-ui);
}

.theme-toggle .icon { font-family: var(--font-mono); }

.logout-link {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  text-align: left;
  padding: 6px 10px;
  cursor: pointer;
}

.logout-link:hover { color: var(--red); }

/* ---------- Main content ---------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 40px 48px 64px;
  max-width: 1040px;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}

.topbar .eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.section { display: none; }
.section.active { display: block; }

.section h2 {
  font-size: 1.9rem;
  margin-bottom: 4px;
}

.section .lede {
  font-size: 0.88rem;
  color: var(--ink-faint);
  margin: 0 0 28px;
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
}

.panel-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 16px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0 16px;
}

.field-grid label { margin-top: 2px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.btn-primary {
  background: var(--green);
  color: #fdfbf7;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: var(--bg-sidebar);
  color: var(--ink);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--border); }

/* ---------- Dashboard ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
}

.stat-tile .stat-label {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 10px;
}

.stat-tile .stat-value {
  font-family: var(--font-mono);
  font-size: 1.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.stat-tile.accent .stat-value { color: var(--green-strong); }
.stat-tile.warn .stat-value { color: var(--gold); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.mini-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mini-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
}

.mini-list li:last-child { border-bottom: none; }

.mini-list .mini-title { color: var(--ink); }

.mini-list .mini-meta {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ---------- Search ---------- */

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.panel-title-row .panel-title { margin-bottom: 0; }

.search-input {
  width: 220px;
  margin: 0;
  padding: 7px 12px;
  font-size: 0.82rem;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 14, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 64px 20px;
  z-index: 100;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  padding: 28px;
  box-shadow: var(--shadow-lifted);
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.modal-header h2 { font-size: 1.4rem; }

.modal-close {
  width: auto;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 4px 8px;
}

.modal-close:hover { color: var(--red); }

.customer-meta {
  color: var(--ink-dim);
  font-size: 0.85rem;
  line-height: 1.7;
  margin: 4px 0 24px;
}

#customers-table tbody tr, #anfragen-table tbody tr[data-id] { cursor: pointer; }

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
  border-bottom: 1px solid var(--border-strong);
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: var(--bg-sidebar); }
tbody tr:last-child td { border-bottom: none; }

.num-cell, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.num-cell { text-align: right; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-ui);
}

.badge-neu { background: var(--gold-tint); color: var(--gold); }
.badge-bearbeitet { background: var(--green-tint); color: var(--green-strong); }
.badge-erledigt { background: var(--border); color: var(--ink-dim); }
.badge-yes { background: var(--green-tint); color: var(--green-strong); }
.badge-no { background: var(--red-tint); color: var(--red); }
.badge-storno { background: var(--border); color: var(--ink-dim); }
.badge-new { background: var(--gold-tint); color: var(--gold); }

td select.anfrage-status {
  width: auto;
  margin: 0;
  padding: 5px 8px;
  font-size: 0.8rem;
}

.btn-icon, .send-btn, .anfrage-to-customer, #add-item-btn {
  display: inline-block;
  width: auto;
  padding: 7px 12px;
  font-size: 0.8rem;
  background: var(--bg-sidebar);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  margin: 0;
  text-decoration: none;
  vertical-align: middle;
}
.btn-icon:hover, .send-btn:hover, .anfrage-to-customer:hover, #add-item-btn:hover {
  background: var(--border);
}

.btn-danger {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-tint);
}
.btn-danger:hover { filter: brightness(0.95); background: var(--red-tint); }

.empty-state {
  padding: 32px 12px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.88rem;
}

/* ---------- Invoice item rows ---------- */

#invoice-items { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }

#invoice-items > div {
  display: grid;
  grid-template-columns: 1.3fr 1.6fr 0.7fr 0.9fr;
  gap: 12px;
  align-items: start;
}

#invoice-items input, #invoice-items select { margin: 0; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: column;
    padding: 12px 16px 0;
    gap: 10px;
  }
  .sidebar .brand {
    margin-bottom: 0;
    width: 100%;
  }
  .nav-list {
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
    padding-bottom: 10px;
    -webkit-overflow-scrolling: touch;
  }
  .nav-item {
    flex-shrink: 0;
    white-space: nowrap;
  }
  .nav-item[aria-current="true"]::before { display: none; }
  .sidebar-footer {
    flex-direction: row;
    margin-top: 0;
    padding: 10px 0;
    justify-content: space-between;
  }
  .theme-toggle { flex: 1; }
  .main { padding: 24px 20px 48px; }
  #invoice-items > div { grid-template-columns: 1fr; }
}
