/* ── Design Tokens ──────────────────────────────────────────────────────── */
:root {
  --accent:        #f97316;
  --accent-dark:   #ea6c00;
  --accent-subtle: #fff7ed;
  --danger:        #ef4444;

  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;

  --text-1:  #0f172a;
  --text-2:  #475569;
  --text-3:  #94a3b8;

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 14px;

  --shadow-s: 0 1px 3px 0 rgb(0 0 0 / .07), 0 1px 2px -1px rgb(0 0 0 / .07);
  --shadow-m: 0 4px 12px -2px rgb(0 0 0 / .09), 0 2px 4px -2px rgb(0 0 0 / .06);

  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --sidebar-w: 220px;
  --header-h:  3.5rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent:        #fb923c;
    --accent-dark:   #f97316;
    --accent-subtle: #1c1007;
    --danger:        #f87171;

    --bg:            #0f172a;
    --surface:       #1e293b;
    --surface-2:     #273549;
    --border:        #334155;
    --border-strong: #475569;

    --text-1: #f1f5f9;
    --text-2: #94a3b8;
    --text-3: #64748b;

    --shadow-s: 0 1px 3px 0 rgb(0 0 0 / .3);
    --shadow-m: 0 4px 12px -2px rgb(0 0 0 / .4);
  }
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell (CSS Grid) ────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-areas:
    "sidebar header"
    "sidebar content";
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

/* ── App Header ──────────────────────────────────────────────────────────── */
.app-header {
  grid-area: header;
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-h);
}

.app-header h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header h1::before {
  content: "🔥 ";
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  height: 2.75rem;
  padding: 0 0.875rem;
  border: none;
  border-radius: var(--radius-m);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
  white-space: nowrap;
  box-shadow: none;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text-1);
  box-shadow: none;
}

.nav-item:active { transform: none; }

.nav-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
}

.nav-icon {
  font-size: 1.125rem;
  flex-shrink: 0;
}

.nav-label { flex: 1; }

/* ── Content Area ────────────────────────────────────────────────────────── */
.content-area {
  grid-area: content;
  padding: 1.5rem;
  overflow-y: auto;
  min-width: 0;
}

/* ── Tab Panels ──────────────────────────────────────────────────────────── */
.tab-panel {
  display: grid;
  gap: 1rem;
  align-content: start;
}

/* ── Panel Header ────────────────────────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0.25rem;
}

.panel-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-1);
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.panel-header-actions select {
  height: 2.25rem;
  padding: 0 2rem 0 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  color: var(--text-1);
  font-family: var(--font);
  font-size: 0.875rem;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  width: auto;
}

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1.5rem;
  text-align: center;
  color: var(--text-3);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.875rem;
  opacity: 0.6;
}

.empty-state p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.7;
}

/* ── Base Card ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-s);
}

h3 {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-1);
}

.section-hint {
  margin: -0.5rem 0 1rem;
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ── Collapsible Card (details) ──────────────────────────────────────────── */
details.card.collapsible {
  padding: 0;
}

details.card.collapsible > summary.card-header {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  cursor: pointer;
  user-select: none;
  border-radius: calc(var(--radius-l) - 1px);
  transition: background 0.15s;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-2);
}

details.card.collapsible > summary.card-header::-webkit-details-marker { display: none; }
details.card.collapsible > summary.card-header::marker { display: none; }

details.card.collapsible > summary.card-header::after {
  content: "▾";
  font-size: 0.8rem;
  color: var(--text-3);
  flex-shrink: 0;
  transition: transform 0.2s;
  display: inline-block;
  margin-left: auto;
}

details.card.collapsible[open] > summary.card-header::after {
  transform: rotate(-180deg);
}

details.card.collapsible[open] > summary.card-header {
  border-bottom: 1px solid var(--border);
  border-radius: calc(var(--radius-l) - 1px) calc(var(--radius-l) - 1px) 0 0;
}

details.card.collapsible > summary.card-header:hover {
  background: var(--surface-2);
}

details.card.collapsible > .card-body {
  padding: 1.125rem 1.25rem 1.25rem;
}

.summary-inline {
  flex: 1;
  font-size: 0.775rem;
  font-weight: 400;
  color: var(--text-3);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

details.result-details > summary.card-header > span {
  white-space: nowrap;
}

/* ── Form Layout ─────────────────────────────────────────────────────────── */
.row {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.grid-2,
.grid-3,
.grid-4,
.grid-5 {
  display: grid;
  gap: 0.75rem;
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid-5 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

/* Button im gleichen Grid wie Labels → am Input ausrichten */
form[class*="grid-"] > button {
  align-self: end;
}

/* ── Labels & Inputs ─────────────────────────────────────────────────────── */
label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-2);
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

input:hover, select:hover { border-color: var(--accent); }

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(249 115 22 / .15);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.25rem;
  padding: 0 1rem;
  border: none;
  border-radius: var(--radius-s);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgb(249 115 22 / .35);
}

button:hover {
  background: var(--accent-dark);
  box-shadow: 0 3px 8px rgb(249 115 22 / .35);
}

button:active { transform: scale(0.97); }

/* Danger — delete buttons in tables */
td button {
  height: 1.625rem;
  padding: 0 0.5rem;
  font-size: 0.725rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid currentColor;
  box-shadow: none;
}

td button:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: none;
}

/* Secondary */
.btn-secondary {
  background: transparent !important;
  color: var(--text-2) !important;
  border: 1px solid var(--border-strong) !important;
  box-shadow: none !important;
  flex-shrink: 0;
}

.btn-secondary:hover {
  background: var(--surface-2) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-s);
  margin-top: 0.875rem;
}

.table-wrap table { margin-top: 0; min-width: 480px; }

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

thead { border-bottom: 2px solid var(--border-strong); }

th {
  padding: 0.45rem 0.625rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  white-space: nowrap;
}

td {
  padding: 0.425rem 0.625rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-1);
  vertical-align: middle;
}

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

/* ── Stat Boxes ──────────────────────────────────────────────────────────── */
.yearly-estimate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.875rem;
}

.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-m);
  padding: 1rem;
  text-align: center;
  transition: box-shadow 0.15s;
}

.stat-box:hover { box-shadow: var(--shadow-m); }

.stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  margin-bottom: 0.375rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-1);
  line-height: 1.1;
}

.stat-unit {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-top: 0.2rem;
}

.yearly-details {
  margin: 0.875rem 0 0;
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ── Chart ───────────────────────────────────────────────────────────────── */
.chart-wrap { position: relative; width: 100%; }

.chart-legend-hint {
  font-size: 0.75rem;
  color: var(--text-3);
  margin: -0.5rem 0 1rem;
}

/* ── Status Bar ──────────────────────────────────────────────────────────── */
.status {
  min-height: 1.5rem;
  margin: 0;
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-s);
  font-size: 0.8rem;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}

.status:empty {
  padding: 0;
  border-color: transparent;
  background: transparent;
}

/* ── Data Management ─────────────────────────────────────────────────────── */
.data-mgmt-grid {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.data-mgmt-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.75rem 0.875rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  transition: border-color 0.15s;
}

.data-mgmt-item:hover { border-color: var(--border-strong); }

.data-mgmt-icon {
  font-size: 1.375rem;
  flex-shrink: 0;
  width: 2rem;
  text-align: center;
}

.data-mgmt-info { flex: 1; min-width: 0; }

.data-mgmt-info strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 0.125rem;
}

.data-mgmt-info span {
  font-size: 0.775rem;
  color: var(--text-3);
  line-height: 1.4;
}

/* ── Login Overlay ───────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-m);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-logo { font-size: 2.5rem; margin-bottom: 0.5rem; }

.login-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 1.75rem;
  letter-spacing: -0.02em;
}

.login-title::before { display: none; }

.login-label {
  display: block;
  text-align: left;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 0.35rem;
}

.login-input {
  width: 100%;
  height: 2.5rem;
  padding: 0 0.875rem;
  font-size: 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text-1);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  margin-bottom: 0.75rem;
}

.login-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(249 115 22 / .18);
}

.login-error {
  font-size: 0.8125rem;
  color: var(--danger);
  margin: -0.25rem 0 0.625rem;
  text-align: left;
}

.login-btn { width: 100%; height: 2.5rem; font-size: 0.9375rem; }

.hash-helper {
  margin-top: 1.25rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  text-align: left;
}

.hash-helper summary {
  font-size: 0.8rem;
  color: var(--text-3);
  cursor: pointer;
  user-select: none;
}

.hash-helper-body {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hash-helper-body input {
  height: 2.25rem;
  font-size: 0.875rem;
  padding: 0 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text-1);
  outline: none;
}

.hash-helper-body input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(249 115 22 / .18);
}

.hash-helper-body button { height: 2.25rem; font-size: 0.875rem; }

.hash-helper-hint { font-size: 0.775rem; color: var(--text-3); margin: 0; }

#hashGenOutput {
  display: block;
  font-size: 0.7rem;
  word-break: break-all;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 0.5rem;
  color: var(--accent);
  min-height: 2rem;
  cursor: pointer;
}

#hashGenOutput:not(:empty)::after {
  content: " (klicken zum Kopieren)";
  color: var(--text-3);
  font-style: italic;
}

/* ── Responsive: Mobile bottom-nav ───────────────────────────────────────── */
@media (max-width: 768px) {
  body {
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
  }

  .app-shell {
    grid-template-areas:
      "header"
      "content"
      "sidebar";
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr auto;
  }

  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: auto;
    width: 100%;
    flex-direction: row;
    padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 40;
    gap: 0.25rem;
    overflow-y: visible;
    overflow-x: auto;
  }

  .nav-item {
    flex-direction: column;
    height: auto;
    padding: 0.5rem 0.375rem;
    gap: 0.2rem;
    flex: 1;
    min-width: 0;
    border-radius: var(--radius-s);
  }

  .nav-icon { font-size: 1.25rem; }

  .nav-label {
    font-size: 0.65rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    text-align: center;
  }

  .content-area { padding: 1rem; }

  .panel-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .panel-header-actions { width: 100%; }
  .panel-header-actions select { flex: 1; }
  .panel-header-actions button { flex: 1; }

  .card { padding: 1rem; border-radius: var(--radius-m); }

  .grid-5 { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }

  .yearly-estimate-grid { grid-template-columns: 1fr 1fr; }

  .data-mgmt-item { flex-wrap: wrap; }
  .data-mgmt-item .btn-secondary { width: 100%; margin-top: 0.25rem; }

  .status { max-width: 100%; font-size: 0.75rem; }

  .app-header h1 { font-size: 1rem; }
}
