:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --ink: #1B2420;
  --ink-muted: #5B6B64;
  --ink-faint: #8B978F;
  --line: #E3E1D9;
  --line-strong: #CBC8BD;
  --brand: #1F5C4F;
  --brand-dark: #163F37;
  --brand-tint: #E7F0EC;
  --amber: #C97A3D;
  --status-green: #3F8F5E;
  --status-green-bg: #E7F3EB;
  --status-yellow: #B58A1F;
  --status-yellow-bg: #FBF3DE;
  --status-orange: #C06A29;
  --status-orange-bg: #FBEBDD;
  --status-red: #B54F3F;
  --status-red-bg: #FBEAE6;
  --sidebar-w: 248px;
  --radius-tile: 14px;
  --radius-chip: 100px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
}

a { color: inherit; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 28px;
}

.brand-mark { width: 30px; height: 30px; flex-shrink: 0; }
.brand-mark svg, .brand-mark img, .brand-mark canvas { display: block; }

.brand-name {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}

nav.primary-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  font-size: 12px;
  color: var(--ink-faint);
  padding: 14px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.nav-item:hover { background: var(--brand-tint); color: var(--ink); }
.nav-item.active { background: var(--brand-tint); color: var(--brand-dark); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-item.stub { opacity: 0.55; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.office-card { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; }
.office-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--amber); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 600; flex-shrink: 0;
}
.office-meta { min-width: 0; }
.office-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.office-plan { font-size: 12px; color: var(--ink-faint); }

/* ---------- Main ---------- */
main { flex: 1; min-width: 0; padding: 36px 44px 60px; }

.main-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 20px; margin-bottom: 34px; flex-wrap: wrap;
}
.main-header h1 { font-size: 27px; font-weight: 600; }
.main-header p { margin: 6px 0 0; color: var(--ink-muted); font-size: 14.5px; }

.btn-primary, main button[type="submit"], main a > button {
  background: var(--brand);
  color: white;
  border: 1px solid var(--brand);
  padding: 10px 18px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-primary:hover, main button[type="submit"]:hover, main a > button:hover { background: var(--brand-dark); }

main button.danger, main button[type="submit"].danger {
  background: var(--status-red-bg);
  border-color: var(--status-red);
  color: var(--status-red);
}
main button.danger:hover, main button[type="submit"].danger:hover {
  background: var(--status-red-bg); filter: brightness(0.95);
}

/* ---------- Stat row ---------- */
.stat-row {
  display: flex; flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius-tile);
  background: var(--surface);
  margin-bottom: 40px;
  overflow: hidden;
}
.stat { flex: 1; min-width: 160px; padding: 22px 26px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: none; }
.stat-value { font-family: 'Space Grotesk', sans-serif; font-size: 30px; font-weight: 600; line-height: 1; }
.stat-label { margin-top: 8px; font-size: 13.5px; color: var(--ink-muted); }

/* ---------- Tool grid ---------- */
.section-heading { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--ink); }

.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 44px; }

.tool-tile {
  border: 1px solid var(--line);
  border-radius: var(--radius-tile);
  padding: 20px 20px 22px;
  background: var(--surface);
  display: flex; flex-direction: column; gap: 14px;
  transition: border-color 0.15s ease, transform 0.15s ease;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.tool-tile:hover { border-color: var(--brand); transform: translateY(-2px); }
.tool-tile.stub { cursor: default; }
.tool-tile.stub:hover { border-color: var(--line); transform: none; }

.tool-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--brand-tint); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
}
.tool-tile.stub .tool-icon { background: var(--bg); color: var(--ink-faint); }

.tool-tile h3 { font-size: 15.5px; font-weight: 600; }
.tool-tile p { margin: 0; font-size: 13.5px; color: var(--ink-muted); line-height: 1.5; flex: 1; }

.tool-meta { font-size: 12.5px; color: var(--ink-faint); border-top: 1px solid var(--line); padding-top: 12px; }
.tool-meta.stub { color: var(--amber); font-weight: 600; }

/* ---------- Tables / case list ---------- */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-tile);
  background: var(--surface);
  overflow: hidden;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left; font-size: 12.5px; font-weight: 600; color: var(--ink-faint);
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 15px 20px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg); }

.cust-name { font-weight: 600; }
.cust-sub { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: var(--radius-chip);
  font-size: 12.5px; font-weight: 600;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.chip.green { background: var(--status-green-bg); color: var(--status-green); }
.chip.green::before { background: var(--status-green); }
.chip.yellow { background: var(--status-yellow-bg); color: var(--status-yellow); }
.chip.yellow::before { background: var(--status-yellow); }
.chip.orange { background: var(--status-orange-bg); color: var(--status-orange); }
.chip.orange::before { background: var(--status-orange); }
.chip.red { background: var(--status-red-bg); color: var(--status-red); }
.chip.red::before { background: var(--status-red); }
.chip.grey { background: var(--line); color: var(--ink-muted); }
.chip.grey::before { background: var(--ink-faint); }

.row-action { color: var(--brand-dark); font-weight: 600; font-size: 13px; background: none; border: none; cursor: pointer; padding: 0; text-decoration: none; }
.row-action:hover { text-decoration: underline; }

/* ---------- Auth page (no sidebar) ---------- */
.auth-page {
  max-width: 360px;
  margin: 10vh auto;
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius-tile);
  border: 1px solid var(--line);
}
.auth-page form label { display: block; margin-bottom: 1rem; }
.auth-page input {
  width: 100%; padding: 0.5rem; margin-top: 0.25rem; box-sizing: border-box;
  border: 1px solid var(--line-strong); border-radius: 8px;
}

.error { color: var(--status-red); }
.notice { background: var(--status-yellow-bg); color: var(--status-yellow); padding: 0.75rem 1rem; border-radius: 8px; }

/* ---------- Generic forms (Kunde-Anlage, Admin etc.) ---------- */
.form-page { max-width: 480px; }
.form-page form label, main form label { display: block; margin-bottom: 1rem; }
.form-page input, .form-page select, main form input, main form select {
  width: 100%; max-width: 320px; padding: 0.4rem; margin-top: 0.25rem; box-sizing: border-box;
  border: 1px solid var(--line-strong); border-radius: 6px;
}

.row-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.row-actions form { display: inline; }

.search-bar { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.search-bar input[type="search"] {
  flex: 1 1 280px; max-width: 360px; padding: 10px 14px; box-sizing: border-box;
  border: 1px solid var(--line-strong); border-radius: 8px; font-size: 14px;
  background: var(--surface); color: var(--ink);
}
.search-bar input[type="search"]:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.search-bar .search-hint { color: var(--ink-muted); font-size: 13px; }
.search-bar .search-clear { color: var(--ink-muted); font-size: 13px; text-decoration: underline; }

.dropzone {
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-tile);
  padding: 2rem; max-width: 320px; min-height: 100px;
  text-align: center; cursor: pointer;
  background: var(--surface);
  margin-bottom: 1rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.dropzone.dragover { border-color: var(--brand); background: var(--brand-tint); }
.logo-preview { max-width: 100%; max-height: 150px; }

fieldset {
  max-width: 700px;
  margin-bottom: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-tile);
  padding: 1rem 1.5rem;
  background: var(--surface);
}
fieldset legend { font-weight: 600; padding: 0 0.5rem; font-family: 'Space Grotesk', sans-serif; }
fieldset label { display: block; margin-bottom: 0.75rem; }
fieldset label input[type="checkbox"] { width: auto; margin-right: 0.4rem; }
fieldset input[type="text"], fieldset input[type="email"], fieldset select, fieldset textarea {
  width: 100%; max-width: 400px; padding: 0.4rem; margin-top: 0.25rem; box-sizing: border-box;
  border: 1px solid var(--line-strong); border-radius: 6px;
}
fieldset label input[type="text"] + input[type="text"] { margin-top: 0.4rem; }
#de-minimis-tabelle input { width: 100%; box-sizing: border-box; }

/* ---------- Read-only Detailanzeige (Kunde etc.) ---------- */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 24px; }
.kv-row span { display: block; }
.kv-row .kv-label { font-size: 12px; color: var(--ink-faint); margin-bottom: 3px; }
.kv-row .kv-value { font-size: 14px; }

/* ---------- Mobile ---------- */
.menu-toggle {
  display: none; background: none; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; cursor: pointer;
}

@media (max-width: 880px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: relative; width: 100%; height: auto;
    border-right: none; border-bottom: 1px solid var(--line);
    flex-direction: row; align-items: center; padding: 14px 18px;
  }
  .brand { padding: 0; flex: 1; }
  nav.primary-nav, .sidebar-footer { display: none; }
  .menu-toggle { display: flex; }
  main { padding: 26px 20px 50px; }
  .tool-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-row { flex-wrap: wrap; }
  .stat { flex: 1 1 50%; border-bottom: 1px solid var(--line); }
}

@media (max-width: 560px) {
  .tool-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
