:root {
  --bg-primary: #0b1120;
  --bg-surface: #1e293b;
  --bg-surface-elevated: #334155;
  --bg-input: #0f172a;
  --border-color: #334155;
  --border-light: #475569;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --accent-orange: #f97316;
  --accent-red: #ef4444;
  --accent-teal: #14b8a6;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-light: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.logo-icon-svg {
  width: 24px;
  height: 24px;
  color: var(--accent-primary);
}

.theme-icon-svg {
  width: 18px;
  height: 18px;
}

.btn-icon-svg {
  width: 16px;
  height: 16px;
}

.tip-icon-svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--accent-teal);
}

.trip-icon-svg {
  width: 14px;
  height: 14px;
  display: inline-block;
  vertical-align: -2px;
  margin-right: 4px;
}

.logo-text {
  font-size: 16px;
  color: var(--text-primary);
}

.badge-beta {
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.header-divider {
  width: 1px;
  height: 24px;
  background: var(--border-color);
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gateway-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface-elevated);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  border: 1px solid var(--border-color);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
}

.status-dot.pulsing {
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Control Bar (Filters) */
.control-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 16px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.form-select, .form-input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}

.form-select:focus, .form-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.form-select {
  min-width: 260px;
  cursor: pointer;
}

.preset-buttons {
  display: flex;
  gap: 4px;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.btn-preset {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-preset:hover {
  color: var(--text-primary);
}

.btn-preset.active {
  background: var(--accent-primary);
  color: #ffffff;
}

.date-range-group {
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}

.date-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.submit-group {
  margin-left: auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-icon {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--border-color);
}

/* Dashboard Layout */
.dashboard-main {
  flex: 1;
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

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

.card-subtitle {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

/* Hero Grid */
.hero-grid {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1fr;
  gap: 20px;
}

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

/* Score Gauge */
.card-hero-score {
  display: flex;
  flex-direction: column;
}

.gauge-container {
  position: relative;
  width: 240px;
  margin: 0 auto 12px;
}

.score-gauge {
  width: 100%;
  overflow: visible;
}

.gauge-bg {
  stroke: var(--bg-surface-elevated);
}

.gauge-val {
  stroke: var(--accent-primary);
  stroke-dasharray: 251.2;
  stroke-dashoffset: 40;
  transition: stroke-dashoffset 1s ease-out, stroke 0.5s ease;
}

.gauge-center-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
}

.score-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.score-num {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text-primary);
}

.score-grade {
  font-size: 24px;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 8px;
  color: #ffffff;
}

.grade-a { background: var(--accent-green); color: #ffffff; }
.grade-b { background: var(--accent-primary); color: #ffffff; }
.grade-c { background: var(--accent-yellow); color: #000000; }
.grade-d { background: var(--accent-red); color: #ffffff; }

.score-target {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.badge-delta {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
}

.badge-delta.positive {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
}

.badge-delta.negative {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

.score-legend {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* Savings Card */
.card-savings {
  display: flex;
  flex-direction: column;
}

.savings-badge {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

.savings-amount-box {
  margin: 10px 0 20px;
}

.amount-rub {
  font-size: 38px;
  font-weight: 800;
  color: var(--accent-green);
  letter-spacing: -0.03em;
}

.amount-liters {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.savings-tips {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}

.tip-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg-surface-elevated);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 12px;
}

.tip-icon {
  font-size: 18px;
}

.tip-content {
  color: var(--text-secondary);
}

.tip-content b {
  color: var(--text-primary);
}

/* Operational Metrics */
.op-metrics-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.op-metric-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-md);
}

.op-metric-info {
  display: flex;
  flex-direction: column;
}

.op-title {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.op-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.op-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--border-color);
  color: var(--text-secondary);
}

.op-tag.tag-success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
}

.op-tag.tag-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-yellow);
}

/* Components Section */
.section-components {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.section-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

.components-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.component-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.component-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.component-card.highlight-card {
  border-color: rgba(245, 158, 11, 0.4);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.05) 0%, var(--bg-surface) 100%);
}

.comp-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.comp-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.comp-score {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent-primary);
}

.comp-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--bg-surface-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.comp-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
}

.fill-acc { background: var(--accent-teal); }
.fill-brake { background: var(--accent-primary); }
.fill-speed { background: var(--accent-yellow); }
.fill-turn { background: #8b5cf6; }
.fill-idle { background: var(--accent-orange); }
.fill-cruise { background: #06b6d4; }
.fill-coasting { background: var(--accent-green); }

.comp-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.comp-status {
  color: var(--text-secondary);
}

.comp-incidents {
  color: var(--text-muted);
  font-weight: 500;
}

/* Charts Section */
.section-charts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

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

.chart-card {
  min-height: 240px;
}

.chart-container {
  height: 180px;
  position: relative;
}

.violations-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
}

.viol-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 8px 12px;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-sm);
}

.viol-row b {
  color: var(--accent-orange);
}

/* Leaderboard Table */
.section-leaderboard {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.table-header-flex {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.table-search-box {
  width: 300px;
}

.table-card {
  padding: 0;
  overflow: hidden;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.leaderboard-table th {
  background: var(--bg-surface-elevated);
  padding: 12px 16px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.leaderboard-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  white-space: nowrap;
}

.leaderboard-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.th-center, .td-center { text-align: center; }
.th-pos { width: 60px; text-align: center; }
.th-action { width: 100px; text-align: right; }

.badge-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 12px;
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
}

.badge-rank.rank-1 { background: #eab308; color: #000000; }
.badge-rank.rank-2 { background: #94a3b8; color: #000000; }
.badge-rank.rank-3 { background: #b45309; color: #ffffff; }

.badge-table-score {
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.btn-table-action {
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-table-action:hover {
  background: var(--accent-primary-hover);
}

.td-empty {
  text-align: center;
  padding: 40px !important;
  color: var(--text-muted);
}

/* Login Screen */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 36px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.login-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 8px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 14px;
  margin-top: 8px;
}

.login-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.btn-logout {
  color: var(--text-muted);
}

.btn-logout:hover {
  color: var(--accent-red);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.active {
  display: flex !important;
}

.modal-window {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 800px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.trip-item {
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trip-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
}

.trip-route {
  font-size: 12px;
  color: var(--text-secondary);
}

.trip-stats {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Footer */
.app-footer {
  border-top: 1px solid var(--border-color);
  padding: 16px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-surface);
  margin-top: auto;
}
