:root {
  --bg: #f5f5f2;
  --card-bg: #ffffff;
  --border: #e0e0dc;
  --text: #1a1a1a;
  --text-muted: #888;
  --text-secondary: #666;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --input-bg: #ffffff;
  --input-border: #ccc;
  --status-under-bg: #e9f6ec;
  --status-under-text: #1e6b34;
  --status-over-bg: #fdeaea;
  --status-over-text: #a12626;
  --status-warning-bg: #fdf3e0;
  --status-warning-text: #92610f;
  --hint-color: #b45309;
}

[data-theme="dark"] {
  --bg: #17181c;
  --card-bg: #212226;
  --border: #34363c;
  --text: #eaeaea;
  --text-muted: #9a9a9a;
  --text-secondary: #b0b0b0;
  --accent: #5b8def;
  --accent-text: #10131a;
  --input-bg: #2a2b30;
  --input-border: #40424a;
  --status-under-bg: #16301f;
  --status-under-text: #7fd99a;
  --status-over-bg: #3a1c1c;
  --status-over-text: #ef9a9a;
  --status-warning-bg: #3a2e12;
  --status-warning-text: #e0a94f;
  --hint-color: #e0a94f;
}

* { box-sizing: border-box; }

html, body {
  max-width: 100%;
  overflow-x: clip;
  background: var(--bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding-bottom: 10px;
  transition: background 0.15s ease, color 0.15s ease;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.meter-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
}

.user-menu {
  position: relative;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 170px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  z-index: 40;
}

.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text);
}

.dropdown-item[hidden] {
  display: none;
}

.dropdown-item:hover {
  background: var(--bg);
}

.dropdown-item-danger {
  color: var(--status-over-text);
}

.dropdown-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.icon-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 16px 20px 0;
  max-width: 520px;
  margin: 0 auto;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#dashboard {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#dashboard[hidden] {
  display: none;
}

.card {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
}

.card h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 16px;
}

.hero-card {
  background: color-mix(in srgb, var(--accent) 8%, var(--card-bg));
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
}

.hero-title {
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 8px;
}

.hero-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0 0 16px;
}

.hero-benefits {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hero-benefits li {
  position: relative;
  padding-left: 26px;
  font-size: 14px;
  color: var(--text);
}

.hero-benefits li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent);
  font-weight: 700;
}

.muted {
  font-size: 13px;
  color: var(--text-muted);
  margin: -8px 0 16px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.field {
  margin-bottom: 16px;
  min-width: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-width: 0;
}

input[type="number"],
input[type="date"],
input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 16px;
  background: var(--input-bg);
  color: var(--text);
}

input[type="date"] {
  -webkit-min-logical-width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Browser-Autofill (Chrome/Safari) übersteuert sonst die Hintergrundfarbe
   von Feldern wie E-Mail/Passwort mit einem hellen Standardton. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
  transition: background-color 9999s ease-in-out 0s;
}

.results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 24px;
}

#year-results,
#tariff-results,
#g-tariff-results {
  grid-template-columns: repeat(2, 1fr);
}

.metric {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 10px;
  text-align: center;
}

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.metric-value {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  word-break: break-word;
}

.hint {
  font-size: 13px;
  color: var(--hint-color);
  margin-top: 16px;
  min-height: 0;
}

.hint:empty { margin-top: 0; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.status-box {
  margin-top: 12px;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.4;
}

.status-under { background: var(--status-under-bg); color: var(--status-under-text); }
.status-over { background: var(--status-over-bg); color: var(--status-over-text); }
.status-warning { background: var(--status-warning-bg); color: var(--status-warning-text); margin-top: 0; margin-bottom: 16px; }

button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  height: 42px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 600;
}

.btn-secondary {
  width: 100%;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
}

.btn-inline {
  width: auto;
  padding: 0 14px;
}

.btn-danger {
  color: var(--status-over-text);
  border-color: var(--status-over-text);
}

.admin-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.admin-view-header h2 {
  margin: 0;
}

.auth-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.auth-switch-btn {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
}

.auth-switch-btn.active {
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  border-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.row-actions button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.row-actions button.danger {
  color: var(--status-over-text);
  border-color: var(--status-over-text);
}

#logout-btn {
  margin-top: 4px;
}

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

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

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
}

.modal h2 {
  font-size: 16px;
  margin: 0 0 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.modal-actions button { flex: 1; }

@media (max-width: 420px) {
  .topbar {
    padding: 14px 16px;
  }
  .tabs {
    padding: 14px 16px 0;
  }
  .container {
    padding: 16px;
  }
  .field-row {
    grid-template-columns: 1fr;
  }
  .results {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .metric-value {
    font-size: 15px;
  }
}

.version-tag {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
  margin: 8px 0 24px;
}

@media (min-width: 700px) {
  .container,
  .tabs {
    max-width: 640px;
  }
}

@media (min-width: 1000px) {
  .container,
  .tabs {
    max-width: 960px;
  }
}
