:root {
  color-scheme: dark;
  --bg: #090a0b;
  --surface: #111416;
  --surface-raised: #171b1e;
  --surface-soft: #1d2225;
  --surface-muted: #242a2e;
  --line: #2c3337;
  --line-strong: #3b454b;
  --text: #f2f5f3;
  --text-strong: #ffffff;
  --muted: #9aa6a0;
  --muted-strong: #c4ccc7;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-weak: rgba(45, 212, 191, 0.14);
  --blue: #7bb3ff;
  --blue-weak: rgba(123, 179, 255, 0.16);
  --amber: #f4c95d;
  --amber-weak: rgba(244, 201, 93, 0.17);
  --red: #fb7185;
  --red-weak: rgba(251, 113, 133, 0.15);
  --green: #48d597;
  --green-weak: rgba(72, 213, 151, 0.16);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
}

::selection {
  background: rgba(45, 212, 191, 0.28);
  color: var(--text-strong);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.35;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button,
input,
select,
textarea,
summary {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 64px;
  padding: 10px clamp(14px, 2vw, 24px);
  background: rgba(9, 10, 11, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 230px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 1px solid rgba(94, 234, 212, 0.4);
  border-radius: 8px;
  background: #0f766e;
  color: #ecfffb;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 10px 26px rgba(45, 212, 191, 0.18);
  font-weight: 800;
  font-size: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--text-strong);
  font-size: 18px;
  line-height: 1.12;
}

h2 {
  color: var(--text-strong);
  font-size: 15px;
  line-height: 1.25;
}

.brand p,
.section-head span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.top-actions,
.button-row,
.filters,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary,
.ghost,
.icon-button {
  min-height: 36px;
  border-radius: 7px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.primary {
  background: #0d9488;
  color: #f7fffd;
  box-shadow: 0 10px 24px rgba(13, 148, 136, 0.24);
}

.primary:hover {
  background: #14b8a6;
}

.ghost {
  background: var(--surface-soft);
  color: var(--muted-strong);
  border: 1px solid var(--line-strong);
}

.ghost:hover,
.icon-button:hover,
.card-actions button:hover,
.row-actions button:hover {
  background: #283036;
  border-color: #53606a;
  color: var(--text-strong);
}

.icon-button {
  width: 36px;
  padding: 0;
  background: var(--surface-soft);
  color: var(--muted-strong);
  border: 1px solid var(--line-strong);
  font-size: 22px;
  line-height: 1;
}

.token-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

body.authorized .token-box {
  border-color: rgba(45, 212, 191, 0.54);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.08);
}

.token-box input {
  width: 168px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.layout {
  display: grid;
  gap: 12px;
  max-width: 1520px;
  margin: 0 auto;
  padding: 12px clamp(12px, 2vw, 24px) 32px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(118px, 1fr));
  gap: 10px;
}

.kpi {
  position: relative;
  min-height: 82px;
  overflow: hidden;
  padding: 12px 13px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--kpi-accent, var(--accent));
  opacity: 0.9;
}

.kpi:nth-child(2) {
  --kpi-accent: var(--blue);
}

.kpi:nth-child(4) {
  --kpi-accent: var(--amber);
}

.kpi:nth-child(5) {
  --kpi-accent: var(--red);
}

.kpi small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.kpi strong {
  display: block;
  margin-top: 7px;
  color: var(--text-strong);
  font-size: 24px;
  line-height: 1;
}

.kpi em {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(340px, 0.72fr) minmax(0, 1.28fr);
  gap: 12px;
  align-items: start;
}

.intake-panel,
.queue-panel,
.members-panel {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.pill,
.status,
.paid {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.pill {
  background: var(--surface-muted);
  color: var(--muted-strong);
}

.pill.ok,
.status.active,
.status.launched,
.status.full,
.paid.paid {
  background: var(--green-weak);
  border-color: rgba(72, 213, 151, 0.28);
  color: var(--green);
}

.status.pending,
.status.due,
.paid.partial {
  background: var(--amber-weak);
  border-color: rgba(244, 201, 93, 0.28);
  color: var(--amber);
}

.status.expired,
.status.left,
.status.closed,
.paid.unpaid,
.paid.refunded {
  background: var(--red-weak);
  border-color: rgba(251, 113, 133, 0.3);
  color: var(--red);
}

.status.paused,
.status.waiting,
.status.idle {
  background: var(--blue-weak);
  border-color: rgba(123, 179, 255, 0.28);
  color: var(--blue);
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  outline: 0;
}

textarea::placeholder,
input::placeholder {
  color: #75807b;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(45, 212, 191, 0.85);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px var(--surface) inset;
}

textarea {
  resize: vertical;
  height: 82px;
  min-height: 76px;
  padding: 10px 11px;
  line-height: 1.45;
}

input,
select {
  min-height: 36px;
  padding: 0 10px;
}

select option {
  background: #111416;
  color: var(--text);
}

.button-row {
  margin-top: 9px;
}

.parse-result {
  margin-top: 9px;
  min-height: 50px;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  padding: 9px;
  background: #0f1214;
  color: var(--text);
}

.parse-result.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.preview-item {
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.preview-item small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.preview-item strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 2px;
  color: var(--text-strong);
  font-size: 13px;
}

.fleet-grid {
  display: grid;
  gap: 8px;
}

.fleet-card {
  display: grid;
  grid-template-columns: minmax(210px, 1.1fr) 128px minmax(390px, 2.1fr) auto;
  align-items: center;
  gap: 11px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px 11px;
}

.fleet-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  min-width: 0;
}

.fleet-title {
  min-width: 0;
}

.fleet-title strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text-strong);
  font-size: 15px;
}

.fleet-title .muted {
  display: block;
  margin-top: 4px;
}

.progress {
  height: 8px;
  margin: 0;
  overflow: hidden;
  border-radius: 999px;
  background: #242a2e;
}

.progress span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  border-radius: inherit;
  background: var(--accent);
  box-shadow: 0 0 18px rgba(45, 212, 191, 0.28);
}

.fleet-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin-top: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--line);
}

.fleet-metrics div {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 7px 8px;
  background: #131719;
}

.fleet-metrics small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.fleet-metrics strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text-strong);
  font-size: 13px;
  line-height: 1.15;
}

.card-actions {
  display: flex;
  justify-self: end;
  gap: 6px;
  margin-top: 0;
}

.card-actions button,
.row-actions button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 750;
}

.card-actions button[data-action="launch-fleet"] {
  background: rgba(45, 212, 191, 0.12);
  border-color: rgba(45, 212, 191, 0.36);
  color: var(--accent-strong);
}

.card-actions button[data-action="delete-fleet"],
.row-actions button[data-action="delete-rider"] {
  color: #ff9cac;
}

.table-head {
  align-items: center;
}

.filters input {
  width: min(300px, 50vw);
}

.filters select {
  width: 132px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.table-wrap::-webkit-scrollbar {
  height: 10px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #343d43;
  border-radius: 999px;
}

table {
  width: 100%;
  min-width: 790px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #171b1e;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 800;
}

tbody tr:hover {
  background: #151a1c;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.member-main strong,
.member-main span {
  display: block;
  max-width: 220px;
  overflow-wrap: anywhere;
}

.member-main strong {
  color: var(--text-strong);
}

.member-main span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.row-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

dialog {
  width: min(720px, calc(100vw - 24px));
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0;
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.dialog-form {
  padding: 16px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

.dialog-form label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 5px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  min-height: 44px;
  padding: 12px 14px;
  border: 1px solid rgba(45, 212, 191, 0.28);
  border-radius: 8px;
  background: #0f1516;
  color: var(--text-strong);
  box-shadow: var(--shadow);
  transform: translateY(90px);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.empty-state {
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1120px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .workbench {
    grid-template-columns: 1fr;
  }

  .fleet-card {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .fleet-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .card-actions {
    justify-self: start;
  }
}

@media (max-width: 720px) {
  .layout {
    padding-inline: 10px;
  }

  .topbar {
    padding-inline: 10px;
  }

  .top-actions,
  .button-row,
  .filters {
    width: 100%;
  }

  .top-actions > button,
  .button-row > button,
  .filters input,
  .filters select,
  .token-box {
    flex: 1 1 140px;
  }

  .token-box input {
    width: 100%;
  }

  .kpi-grid,
  .preview-grid,
  .form-grid,
  .fleet-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .members-panel,
  .intake-panel,
  .queue-panel {
    padding: 11px;
  }

  .section-head.table-head {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 460px) {
  h1 {
    font-size: 17px;
  }

  .brand {
    min-width: 0;
  }

  .kpi-grid,
  .preview-grid,
  .form-grid,
  .fleet-metrics,
  .fleet-grid {
    grid-template-columns: 1fr;
  }

  .primary,
  .ghost {
    padding-inline: 10px;
  }
}
