/* ==========================================================================
   Tesla Dashboard — Redesign: Helles Fleet-UI
   Palette: kühles Off-White, weiße Karten, Tesla-Blau, semantische Farben
   Typo: DM Sans (geometrisch, präzise, B2B-typisch ohne generisch zu sein)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

:root {
  /* Farben */
  --bg:          #F0F2F7;
  --surface:     #FFFFFF;
  --surface-2:   #F8F9FC;
  --border:      #E2E8F0;
  --border-2:    #CBD5E1;

  --text:        #0F172A;
  --text-muted:  #64748B;
  --text-faint:  #94A3B8;

  --blue:        #2D6BFF;
  --blue-light:  #EEF3FF;
  --blue-mid:    #93B5FF;

  --green:       #22C55E;
  --green-light: #DCFCE7;
  --amber:       #F59E0B;
  --amber-light: #FEF3C7;
  --red:         #EF4444;
  --red-light:   #FEE2E2;
  --gray-ring:   #E2E8F0;

  /* Schatten */
  --shadow-card: 0 1px 3px rgba(15,23,42,0.06), 0 4px 16px rgba(15,23,42,0.04);
  --shadow-card-hover: 0 4px 12px rgba(15,23,42,0.10), 0 8px 32px rgba(15,23,42,0.06);

  /* Radien */
  --r-sm:  6px;
  --r-md:  12px;
  --r-lg:  16px;

  /* Typografie */
  --font: 'DM Sans', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ---- App Shell ---- */
.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 28px 72px;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

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

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

.brand-mark svg { display: block; }

.brand-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.last-update {
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: box-shadow .15s, background .15s, border-color .15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
  box-shadow: 0 1px 4px rgba(15,23,42,.08);
}

.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover {
  background: #1A57F5;
  border-color: #1A57F5;
  box-shadow: 0 2px 8px rgba(45,107,255,.28);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface); border-color: var(--border); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
  transition: box-shadow .2s;
}

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

.card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-faint);
  margin: 0 0 14px;
}

/* ---- Main Grid ---- */
.main-grid {
  display: grid;
  grid-template-columns: 280px 1fr 240px;
  gap: 18px;
  margin-bottom: 18px;
}

@media (max-width: 1100px) {
  .main-grid { grid-template-columns: 1fr 1fr; }
  .main-grid .card:last-child { grid-column: span 2; }
}
@media (max-width: 680px) {
  .main-grid { grid-template-columns: 1fr; }
  .main-grid .card:last-child { grid-column: span 1; }
}

/* ---- Donut Chart ---- */
.donut-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.donut-container {
  position: relative;
  width: 160px; height: 160px;
  margin: 8px 0 16px;
}

.donut-container canvas { display: block; }

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

.donut-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.donut-unit {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 3px;
}

.donut-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 6px;
}

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

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

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

.legend-count {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---- Stat-Info Zeilen unter Donut ---- */
.stat-rows {
  width: 100%;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.stat-row:last-child { border-bottom: none; }

.stat-row-label { color: var(--text-muted); }
.stat-row-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ---- Charging pill ---- */
.charging-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #EEF9F2;
  border: 1px solid #BBF7D0;
  color: #16A34A;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
}

.charging-badge .pulse {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #22C55E;
  animation: blink 1.6s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

@media (prefers-reduced-motion: reduce) {
  .charging-badge .pulse { animation: none; }
}

/* ---- Trend Chart Card ---- */
.trend-card { padding: 22px 24px 16px; }

.trend-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.tab-group {
  display: flex;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 3px;
}

.tab {
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: var(--font);
  transition: all .15s;
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15,23,42,.08);
  font-weight: 600;
}

/* ---- Cost Section ---- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 28px 0 14px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-meta { font-size: 12px; color: var(--text-muted); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

@media (max-width: 800px) { .summary-grid { grid-template-columns: repeat(2, 1fr); } }

.summary-card .big-num {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}

.summary-card.neutral .big-num { color: var(--text); }

.big-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 2px;
}

/* ---- Session Table ---- */
.table-card { padding: 0; overflow: hidden; }

.table-card .card-title { padding: 20px 24px 0; }

.session-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.session-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.session-table th:first-child { padding-left: 24px; }
.session-table th:last-child  { padding-right: 24px; text-align: right; }

.session-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.session-table td:first-child { padding-left: 24px; }
.session-table td:last-child  { padding-right: 24px; text-align: right; }

.session-table tbody tr:last-child td { border-bottom: none; }

.session-table tbody tr:hover { background: var(--surface-2); }

.cost-cell { font-weight: 600; color: var(--blue); }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-live { background: var(--green-light); color: #16A34A; }
.badge-done { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* ---- Battery delta ---- */
.delta-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.delta-track {
  width: 64px; height: 5px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  flex-shrink: 0;
}

.delta-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--blue);
}

/* ---- Empty / connect state ---- */
.empty-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  text-align: center;
}

.empty-icon {
  width: 52px; height: 52px;
  color: var(--text-faint);
  margin-bottom: 20px;
}

.empty-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}

.empty-text {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 380px;
  line-height: 1.65;
  margin-bottom: 24px;
}

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: 36px 32px;
}

.login-logo {
  width: 40px; height: 40px;
  background: var(--blue);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 4px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 28px;
}

.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.form-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  transition: border-color .15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45,107,255,.12);
}

.form-error {
  background: var(--red-light);
  border: 1px solid #FECACA;
  color: #DC2626;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  margin-bottom: 14px;
}

.btn-block { width: 100%; justify-content: center; margin-top: 6px; padding: 11px; }

/* ---- Settings Dialog ---- */
dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 40px rgba(15,23,42,.14);
  color: var(--text);
  padding: 28px;
  width: 320px;
  max-width: 92vw;
}

dialog::backdrop { background: rgba(15,23,42,.35); }

.settings-field { margin-bottom: 16px; }
.settings-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.settings-field input { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 9px 12px; font-family: var(--font); font-size: 14px; color: var(--text); }
.settings-field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(45,107,255,.12); }
.settings-field .hint { font-size: 11px; color: var(--text-faint); margin-top: 5px; line-height: 1.5; }
.dialog-actions { display: flex; gap: 8px; margin-top: 20px; }
.dialog-actions .btn { flex: 1; justify-content: center; }

/* ---- Footer ---- */
.footer { text-align: center; margin-top: 56px; font-size: 12px; color: var(--text-faint); }
