/* ──────────────────────────────────────
   DESIGN TOKENS – Apple System
────────────────────────────────────── */
:root {
  --blue:   #007AFF;
  --red:    #FF3B30;
  --orange: #FF9500;
  --green:  #34C759;
  --purple: #AF52DE;
  --teal:   #32ADE6;

  --bg:        #F2F2F7;
  --surface:   #FFFFFF;
  --surface-2: #F2F2F7;
  --surface-3: #E5E5EA;

  --text:   #1C1C1E;
  --text-2: #3C3C43;
  --text-3: rgba(60,60,67,0.55);
  --text-4: rgba(60,60,67,0.28);

  --sep: rgba(60,60,67,0.13);

  --sidebar-bg: #FFFFFF;
  --sidebar-w:  220px;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 0 0 0.5px rgba(0,0,0,0.05);
  --shadow-md:   0 4px 16px rgba(0,0,0,0.10);

  --radius: 12px;
  --radius-sm: 8px;

  --c-red-bg:    rgba(255,59,48,0.1);
  --c-orange-bg: rgba(255,149,0,0.1);
  --c-green-bg:  rgba(52,199,89,0.1);
  --c-blue-bg:   rgba(0,122,255,0.1);
  --c-purple-bg: rgba(175,82,222,0.1);
  --c-teal-bg:   rgba(50,173,230,0.1);

  /* Legacy compat */
  --primary: var(--blue);
  --primary-light: #3d8eff;
  --accent: var(--orange);
  --white: var(--surface);
  --text-muted: var(--text-3);
  --border: var(--sep);
  --success: var(--green);
  --success-bg: var(--c-green-bg);
  --warning: var(--orange);
  --warning-bg: var(--c-orange-bg);
  --danger: var(--red);
  --danger-bg: var(--c-red-bg);
  --info: var(--blue);
  --info-bg: var(--c-blue-bg);
  --shadow: var(--shadow-card);
}

/* ──────────────────────────────────────
   RESET
────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

/* ──────────────────────────────────────
   SIDEBAR
────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 0.5px solid var(--sep);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  z-index: 100;
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
}

.sidebar-header {
  padding: 22px 16px 14px;
  border-bottom: 0.5px solid var(--sep);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: var(--blue);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo-icon svg {
  width: 16px; height: 16px;
  fill: none; stroke: white;
  stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

.sidebar-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.sidebar-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-4);
  padding: 10px 7px 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 1px;
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-item svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
  color: var(--text-3);
}

.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--c-blue-bg); color: var(--blue); }
.nav-item.active svg { color: var(--blue); }

.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  line-height: 16px;
}

.sidebar-footer {
  padding: 10px 10px 18px;
  border-top: 0.5px solid var(--sep);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* ──────────────────────────────────────
   MAIN LAYOUT
────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: var(--sidebar-bg);
  border-bottom: 0.5px solid var(--sep);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-brand { font-size: 14px; font-weight: 600; color: var(--text); }

.hamburger {
  width: 32px; height: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4.5px;
  padding: 8px;
  cursor: pointer;
  border: none;
  background: none;
  border-radius: 6px;
}

.hamburger span {
  display: block;
  height: 1.5px;
  background: var(--text-2);
  border-radius: 2px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.25s;
}

/* ──────────────────────────────────────
   PAGE
────────────────────────────────────── */
.page {
  padding: 32px;
  flex: 1;
  max-width: 1280px;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 3px;
}

/* ──────────────────────────────────────
   CARDS
────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px 13px;
  border-bottom: 0.5px solid var(--sep);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.card-meta { font-size: 12px; color: var(--text-3); }
.card-body { padding: 20px; }

/* ──────────────────────────────────────
   CHARTS GRID (index.html)
────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 3fr 2fr 1.5fr;
  gap: 12px;
  margin-bottom: 24px;
  align-items: stretch;
}

.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
}

.chart-card-area .chart-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.chart-metric-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  margin-bottom: 4px;
}

.chart-metric-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
}

.chart-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
}

.chart-trend.up   { color: var(--green); }
.chart-trend.down { color: var(--red); }

.period-seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 7px;
  padding: 2px;
  flex-shrink: 0;
}

.period-btn {
  padding: 4px 10px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}

.period-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.chart-canvas-wrap {
  position: relative;
  height: 145px;
  width: 100%;
}

.chart-card-donut {
  align-items: center;
}

.chart-card-donut .chart-metric-label {
  margin-bottom: 12px;
  align-self: flex-start;
  width: 100%;
}

.donut-wrap {
  position: relative;
  width: 140px;
  height: 140px;
  flex-shrink: 0;
  margin: 0 auto 16px;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.donut-center-num {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
}

.donut-center-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}

.donut-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
}

.legend-left {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
}

.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-count {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.chart-card-metrics {
  justify-content: space-between;
}

.metric-row {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 14px 0;
}

.metric-row + .metric-row {
  border-top: 0.5px solid var(--sep);
}

.metric-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-3);
  margin-bottom: 5px;
}

.metric-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.metric-sub {
  font-size: 11.5px;
  color: var(--text-4);
  margin-top: 3px;
}

/* ──────────────────────────────────────
   STATS GRID (simple number cards)
────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-sub { font-size: 12px; color: var(--text-4); }

/* ──────────────────────────────────────
   FILTER BAR
────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-4);
}

.filter-segment {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 3px;
  gap: 1px;
}

.filter-btn {
  padding: 5px 11px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
  white-space: nowrap;
}

.filter-btn:hover { color: var(--text-2); }

.filter-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 0 0 0.5px rgba(0,0,0,0.05);
}

.filter-sep {
  width: 0.5px; height: 18px;
  background: var(--sep);
  align-self: center;
}

/* ──────────────────────────────────────
   TABLE
────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

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

th {
  padding: 9px 16px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  border-bottom: 0.5px solid var(--sep);
  white-space: nowrap;
  text-align: left;
  letter-spacing: 0.01em;
}

td {
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--sep);
  vertical-align: middle;
  font-size: 13.5px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* Notfall row */
tr.row-notfall td { background: rgba(255,59,48,0.04); }
tr.row-notfall td:first-child {
  border-left: 2.5px solid var(--red);
  padding-left: 13.5px;
}
tr.row-notfall:hover td { background: rgba(255,59,48,0.07); }

.table-link {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  display: block;
}
.table-link:hover { color: var(--blue); }

/* ──────────────────────────────────────
   BADGES
────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-neu          { background: var(--c-blue-bg);   color: var(--blue); }
.badge-in_bearbeitung { background: var(--c-purple-bg); color: var(--purple); }
.badge-angenommen   { background: var(--c-green-bg);  color: var(--green); }
.badge-abgelehnt    { background: var(--c-red-bg);    color: var(--red); }
.badge-abgeschlossen { background: var(--surface-2);  color: var(--text-3); }
.badge-termin_geplant { background: var(--c-teal-bg); color: var(--teal); }
.badge-voice_eingang  { background: var(--c-purple-bg); color: var(--purple); }

.badge-notfall    { background: var(--c-red-bg);    color: var(--red); }
.badge-dringend   { background: var(--c-orange-bg); color: var(--orange); }
.badge-geplant    { background: var(--c-green-bg);  color: var(--green); }

.badge-hoch       { background: var(--c-red-bg);    color: var(--red); }
.badge-mittel     { background: var(--c-orange-bg); color: var(--orange); }
.badge-niedrig    { background: var(--c-green-bg);  color: var(--green); }

/* ──────────────────────────────────────
   BUTTONS
────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary  { background: var(--blue);  color: white; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-success  { background: var(--green); color: white; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger   { background: var(--red);   color: white; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-outline  {
  background: var(--surface-2);
  color: var(--text-2);
  border: none;
}
.btn-outline:hover { background: var(--surface-3); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-icon {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--surface-2);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  text-decoration: none;
}
.btn-icon:hover { background: var(--surface-3); color: var(--text-2); }

/* ──────────────────────────────────────
   DETAIL PAGE
────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.detail-field { margin-bottom: 16px; }
.detail-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  margin-bottom: 4px;
}
.detail-value { font-size: 14px; color: var(--text); }

.ki-box {
  background: var(--c-blue-bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
}

.ki-box-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--blue);
  margin-bottom: 8px;
}

.ki-summary { font-size: 14px; line-height: 1.6; color: var(--text); }

.ki-meta {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.ki-meta-item { display: flex; flex-direction: column; gap: 2px; }
.ki-meta-label { font-size: 10px; text-transform: uppercase; font-weight: 600; color: var(--text-3); }
.ki-meta-value { font-size: 13px; font-weight: 600; }

/* ──────────────────────────────────────
   STATS PAGE – BAR CHARTS
────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}

.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 100px; font-size: 13px; color: var(--text); text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; background: var(--surface-2); border-radius: 4px; height: 24px; overflow: hidden; }
.bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 4px;
  transition: width 0.5s ease;
  display: flex;
  align-items: center;
  padding-left: 8px;
  min-width: 30px;
}
.bar-fill span { color: white; font-size: 11px; font-weight: 700; }
.bar-count { width: 30px; font-size: 13px; font-weight: 600; color: var(--text-3); }

/* ──────────────────────────────────────
   FORM / TEXTAREA
────────────────────────────────────── */
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 0.5px solid var(--sep);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  color: var(--text);
  background: var(--surface);
}

textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}

/* ──────────────────────────────────────
   EMPTY STATE / LOADING
────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-3);
}

.empty-state-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; font-weight: 600; color: var(--text); }
.empty-state-sub { font-size: 13px; margin-top: 4px; }

.loading { text-align: center; padding: 32px; color: var(--text-3); }

/* ──────────────────────────────────────
   TOAST
────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
}

.toast.show  { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

/* ──────────────────────────────────────
   RESPONSIVE
────────────────────────────────────── */
@media (max-width: 1100px) {
  .charts-grid {
    grid-template-columns: 1fr 1fr;
  }
  .chart-card:first-child {
    grid-column: span 2;
  }
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .chart-grid  { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 0 0 40px rgba(0,0,0,0.12);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; }
  .sidebar-overlay.open { opacity: 1; pointer-events: all; }
  .main { margin-left: 0; }
  .topbar { display: flex; }
  .page { padding: 16px; }
  .page-header { flex-wrap: wrap; }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card:first-child { grid-column: span 1; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-title { font-size: 20px; }
  .col-ort, .col-aufwand, .col-prioritaet { display: none; }
  th, td { padding: 12px; }
}

@media (max-width: 420px) {
  .col-kategorie { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
