:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #dde3ea;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --accent: #14b8a6;
  --warn: #f59e0b;
  --radius: 8px;
  --shadow: 0 16px 40px rgba(15, 23, 42, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --panel: #182233;
    --text: #edf2f7;
    --muted: #a8b3c5;
    --line: #2d3a4e;
    --shadow: 0 16px 40px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

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

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel,
.panel,
.empty {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(460px, 100%);
  padding: 32px;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
}

h1 { font-size: clamp(1.65rem, 3vw, 2.35rem); }
h2 { font-size: 1rem; }
p { color: var(--muted); line-height: 1.55; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  max-width: 100%;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
}

.sidebar nav {
  display: grid;
  gap: 6px;
  margin: 24px 0;
}

.sidebar nav a {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 650;
}

.sidebar nav a.active,
.sidebar nav a:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.content {
  width: min(1180px, 100%);
  min-width: 0;
  padding: 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 750;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 700;
}

input,
select,
textarea {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

textarea { resize: vertical; }

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

button,
.primary,
.secondary,
.ghost,
.danger {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.primary {
  color: #fff;
  background: var(--primary);
}

.primary:hover { background: var(--primary-strong); }
.compact { min-height: 40px; }

.secondary {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.ghost,
.text-button {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}

.danger {
  color: #fff;
  background: #dc2626;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.delete-form {
  margin-top: -4px;
}

.ghost:disabled {
  cursor: not-allowed;
  opacity: .6;
}

.text-button {
  width: 100%;
}

.wide-button {
  width: 100%;
}

.mfa-form {
  margin-top: 14px;
}

.flash {
  padding: 12px 14px;
  border-radius: 7px;
  margin-bottom: 18px;
  font-weight: 750;
}

.flash.success { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.flash.error { background: color-mix(in srgb, #ef4444 18%, transparent); }

.periods {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.periods.muted { margin-top: -4px; }

.chip {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel);
  font-weight: 750;
}

.chip.active {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.kpi strong {
  display: block;
  font-size: 1.24rem;
}

.grid {
  display: grid;
  gap: 18px;
  margin-bottom: 18px;
  min-width: 0;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
  max-width: 100%;
}

.provider-manager {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.provider-create,
.tariff-focus {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.provider-create h3 {
  margin: 0;
  font-size: .95rem;
}

.empty-state {
  align-self: stretch;
}

.fixed-form {
  align-self: start;
}

.list-panel {
  min-width: 0;
}

.panel {
  padding: 20px;
  min-width: 0;
}

.panel.wide {
  margin-bottom: 18px;
}

.empty {
  padding: 36px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.subtle {
  color: var(--muted);
}

.table-wrap {
  overflow-x: hidden;
  max-width: 100%;
}

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
}

.session-edit-row td {
  padding: 0 10px 16px;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
}

.session-editor {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.session-edit-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.session-edit-grid label:has(textarea),
.session-edit-grid button {
  grid-column: 1 / -1;
}

canvas {
  width: 100%;
  height: 320px;
  max-height: 320px;
}

.edit-list {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  max-height: min(72vh, 760px);
  overflow-y: auto;
  padding-right: 4px;
}

.tariff-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  padding-left: 12px;
  border-left: 3px solid color-mix(in srgb, var(--primary) 22%, transparent);
}

.tariff-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.tariff-item h3 {
  margin: 0;
  font-size: .95rem;
}

.edit-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}

.edit-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.edit-heading strong,
.edit-heading span {
  overflow-wrap: anywhere;
}

.car-thumb {
  width: 58px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 7px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--panel);
}

.car-thumb.placeholder::before {
  content: "";
  display: block;
  width: 26px;
  height: 12px;
  margin: 15px auto;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 28%, transparent);
}

.qr {
  width: 260px;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

.secret {
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar nav {
    display: flex;
    flex-wrap: wrap;
    overflow-x: hidden;
    margin: 10px 0;
  }
  .sidebar nav a {
    white-space: normal;
    flex: 1 1 140px;
  }
  .content {
    padding: 20px 16px 32px;
  }
  .topbar {
    align-items: flex-start;
  }
  .kpis,
  .grid.two,
  .settings-layout,
  .provider-manager,
  .session-edit-grid {
    grid-template-columns: 1fr;
  }
  .auth-panel {
    padding: 24px;
  }
}

@media (max-width: 640px) {
  .topbar {
    display: grid;
  }
  .topbar .primary {
    width: 100%;
  }
  .panel,
  .empty {
    padding: 16px;
  }
  .responsive-table,
  .responsive-table thead,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table th,
  .responsive-table td {
    display: block;
    width: 100%;
  }
  .responsive-table thead {
    display: none;
  }
  .responsive-table tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
    margin-bottom: 10px;
    background: color-mix(in srgb, var(--bg) 70%, transparent);
  }
  .responsive-table td {
    border: 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    overflow-wrap: anywhere;
  }
  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 800;
    flex: 0 0 42%;
  }
  .session-edit-row td {
    display: block;
    padding: 0;
  }
  .session-edit-row td::before {
    display: none;
  }
}
