/* ==========================================================================
   LongWayDrivers UCP. Loads after site.css and uses its tokens.
   ========================================================================== */

/* ---------- View states (set by ucp.js) ---------- */

body.ucp-booting .login-screen,
body.ucp-booting .dashboard { visibility: hidden; }
body.ucp-authenticated .login-screen { display: none; }
body.ucp-anonymous .dashboard,
body.ucp-booting .dashboard { display: none; }

[hidden] { display: none !important; }

.btn-block { width: 100%; }
.btn-icon { width: 38px; padding: 0; }
.btn-discord { background: #5865f2; color: #fff; }
.btn-discord:hover { background: #6c77f4; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.active { background: rgba(255, 102, 0, 0.14); color: var(--bar); border-color: var(--bar); }

/* ---------- Login ---------- */

.login-screen { max-width: 480px; margin: 12px auto; }
.login-side { padding: 24px; }
.login-card { display: grid; gap: 14px; }
.login-card h1 {
  font-family: var(--display);
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 0.95;
  text-transform: uppercase;
}
.login-sub { margin: -6px 0 4px; color: var(--muted); }

.field { display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.field input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:hover { border-color: var(--faint); }
.field input:focus { outline: none; border-color: var(--bar); box-shadow: 0 0 0 3px rgba(255, 102, 0, 0.18); }
.field input:disabled { opacity: 0.55; }
#totpCode { font-family: var(--mono); letter-spacing: 0.3em; font-size: 1.1rem; }

.captcha-field { min-height: 65px; }
.turnstile-widget { min-height: 65px; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.auth-divider::before,
.auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.form-status { min-height: 1.4em; color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.form-status:empty { min-height: 0; }
.form-status.error { color: #d33; }

.login-help { color: var(--faint); font-size: 0.86rem; }
.login-help a { color: var(--bar); }

/* ---------- Dashboard layout ---------- */

.dash-layout { padding: 0; }

.dash-main { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.dash-main > * { scroll-margin-top: 88px; }

.dash-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px 24px;
  padding-bottom: 8px;
}
.dash-head h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.6rem, 5vw, 3.6rem);
  font-weight: 800;
  text-transform: uppercase;
  line-height: 0.92;
  overflow-wrap: anywhere;
}
.account-state { display: flex; flex-wrap: wrap; gap: 8px; }

.dash-title-row 
@media (max-width: 960px) { .dash-layout { padding-top: 20px; } }

/* ---------- Alerts ---------- */

.page-error {
  padding: 14px 18px;
  border-radius: 12px;
  background: rgba(237, 43, 43, 0.12);
  box-shadow: inset 0 0 0 1px rgba(237, 43, 43, 0.4);
  color: #ffb3a6;
  font-weight: 700;
}
.security-warning {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px 14px 18px;
  border-radius: 12px;
  background: rgba(218, 176, 56, 0.1);
  box-shadow: inset 0 0 0 1px rgba(218, 176, 56, 0.4);
}
.security-warning > .icon { color: #dab038; width: 22px; height: 22px; }
.security-warning div { flex: 1; display: grid; gap: 2px; }
.security-warning span { color: var(--muted); font-size: 0.9rem; }

/* ---------- Pills and status ---------- */

.pill,
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}
.pill .icon { width: 14px; height: 14px; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.pill.good { background: rgba(57, 181, 74, 0.14); color: var(--way-hi); }
.pill.good .dot { background: var(--way); }
.pill.warn { background: rgba(218, 160, 20, 0.16); color: #a8740a; }
.pill.vip { background: rgba(255, 102, 0, 0.14); color: #d45400; }

.status { text-transform: capitalize; }
.status.active,
.status.completed,
.status.delivered,
.status.claimed,
.status.open { background: rgba(57, 181, 74, 0.14); color: var(--way-hi); }
.status.failed,
.status.cancelled,
.status.canceled,
.status.expired,
.status.abandoned { background: rgba(220, 40, 40, 0.12); color: #c62828; }
.status.paused,
.status.pending,
.status.in_progress,
.status.in-progress { background: rgba(218, 160, 20, 0.16); color: #a8740a; }

/* ---------- Metrics ---------- */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--line);
  box-shadow: 0 0 0 1px var(--line);
}
.metric {
  display: grid;
  gap: 6px;
  padding: 22px;
  background: var(--surface);
}
.metric > span {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}
.metric > span .icon { width: 16px; height: 16px; color: var(--long); }
.metric strong {
  font-family: var(--display);
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.metric small { color: var(--faint); font-size: 0.84rem; font-weight: 600; }

@media (max-width: 1100px) { .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .metric { padding: 16px; }
  .metric strong { font-size: 1.9rem; }
}
@media (max-width: 340px) { .metric-grid { grid-template-columns: 1fr; } }

/* ---------- Panels ---------- */

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  padding: 6px 8px 6px 12px;
  background: var(--bar);
  color: var(--bar-ink);
}
.panel-head h2,
.panel-head h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.panel-head h2::before,
.panel-head h3::before { content: "\25B6"; font-size: 9px; }
.panel-head .count { background: rgba(0, 0, 0, 0.14); color: var(--bar-ink); }
.panel-head .panel-hint,
.panel-head .settings-state { color: var(--bar-ink); opacity: 0.75; font-size: 11px; font-weight: 700; }
.count {
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
}

.empty-state {
  padding: 28px 20px;
  color: var(--faint);
  font-size: 0.92rem;
  text-align: center;
}


@media (max-width: 1100px) {
  .char-grid, .split-grid, }

/* characters */
.character-list { display: grid; gap: 2px; padding: 8px; }
.character-button {
  width: 100%;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.character-button:hover { background: var(--surface-2); }
.character-button.active { background: rgba(57, 181, 74, 0.1); box-shadow: inset 0 0 0 1px rgba(57, 181, 74, 0.35); }
.character-text { min-width: 0; display: grid; gap: 2px; }
.character-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.character-text small { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.status.offline { background: transparent; color: var(--faint); }

.character-skin,
.character-avatar {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--surface-2);
  object-fit: cover;
  object-position: 50% 15%;
}
.character-avatar { display: block; }

/* driver file */
.detail-body { padding: 20px; }
.detail-body > .empty-state { padding: 8px 0; }
.driver-preview {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
}
.detail-skin {
  width: 96px;
  height: 120px;
  border-radius: 12px;
  background:
    radial-gradient(70% 60% at 50% 90%, rgba(241, 90, 36, 0.28), transparent 70%),
    var(--surface-2);
  object-fit: contain;
  object-position: 50% 100%;
}
.driver-preview strong {
  display: block;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  line-height: 1;
  overflow-wrap: anywhere;
}
.driver-preview small { display: block; margin-top: 4px; color: var(--muted); font-size: 0.86rem; }
.driver-money { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px 24px; }
.driver-money span { display: grid; font-family: var(--mono); font-weight: 600; font-size: 1.05rem; }
.driver-money em {
  font-style: normal;
  font-family: var(--body);
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.detail-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--line);
  box-shadow: 0 0 0 1px var(--line);
}
.detail-item { display: grid; gap: 2px; padding: 12px 14px; background: var(--bg-2); }
.detail-item span { color: var(--faint); font-size: 0.76rem; font-weight: 800; }
.detail-item strong { font-size: 1rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.detail-sub {
  margin: 20px 0 10px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.license-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.license {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--faint);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 0.82rem;
  font-weight: 700;
}
.license .icon { width: 14px; height: 14px; }
.license.active { background: rgba(57, 181, 74, 0.12); color: var(--way-hi); box-shadow: none; }

@media (max-width: 560px) {
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .driver-preview { grid-template-columns: 72px minmax(0, 1fr); }
  .detail-skin { width: 72px; height: 92px; }
}

/* loads */
.load-list { display: grid; }
.load-row {
  display: grid;
  gap: 6px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}
.load-row:first-child { border-top: 0; }
.load-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.load-top small { color: var(--muted); font-weight: 700; }
.load-pay { font-family: var(--mono); font-weight: 600; color: var(--way-hi); }
.load-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; color: var(--muted); font-size: 0.88rem; }
.load-meta .icon { width: 14px; height: 14px; color: var(--long); }
.load-row footer { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

/* compact lists */
.compact-list { display: grid; }
.compact-row { display: grid; gap: 2px; padding: 14px 20px; border-top: 1px solid var(--line); }
.compact-row:first-child { border-top: 0; }
.compact-row small { color: var(--muted); font-size: 0.84rem; overflow-wrap: anywhere; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table-wrap th {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.table-wrap td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table-wrap tbody tr:last-child td { border-bottom: 0; }
.table-wrap td strong { display: block; }
.table-wrap td small { display: flex; align-items: center; gap: 4px; margin-top: 2px; color: var(--muted); font-size: 0.82rem; }
.table-wrap td small .icon { width: 13px; height: 13px; color: var(--long); }
.table-wrap .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap td.money { font-family: var(--mono); font-weight: 600; color: var(--way-hi); }
.table-wrap td.muted { color: var(--muted); white-space: nowrap; }
.table-wrap td.empty-cell { padding: 32px 18px; color: var(--faint); text-align: center; }

.vehicle-row { cursor: pointer; transition: background-color 0.15s; }
.vehicle-row:hover,
.vehicle-row:focus-visible { background: var(--surface-2); outline: none; }
.vehicle-row:focus-visible td:first-child { box-shadow: inset 2px 0 0 var(--way); }
.vehicle-model-cell { display: flex; align-items: center; gap: 12px; }
.vehicle-model-cell > span:last-child { display: grid; }
.vehicle-model-badge {
  flex: none;
  min-width: 46px;
  padding: 4px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 600;
  text-align: center;
}
.plate {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 5px;
  background: #f1efe8;
  color: #1a1d1e;
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

/* ---------- Settings ---------- */

.settings-state {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}
.settings-form { display: grid; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  padding: 18px 20px;
  border-top: 1px solid var(--line);
}
.setting-row:first-child { border-top: 0; }
.setting-row > span { display: grid; gap: 2px; }
.setting-row small { color: var(--muted); font-size: 0.86rem; }
.setting-row .segmented { margin: 0; }
.setting-row .segmented button.active { background: var(--surface-2); color: var(--ink); }
.setting-toggle { cursor: pointer; }

.setting-toggle input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 13px;
  background: #3a3f41;
  cursor: pointer;
  transition: background-color 0.18s;
}
.setting-toggle input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #c8cdca;
  transition: transform 0.18s, background-color 0.18s;
}
.setting-toggle input:checked { background: var(--way); }
.setting-toggle input:checked::before { transform: translateX(18px); background: #fff; }
.setting-toggle input:disabled { opacity: 0.4; cursor: not-allowed; }
.setting-toggle input:focus-visible { outline: 2px solid var(--way-hi); outline-offset: 3px; }

@media (max-width: 560px) {
  .setting-row:not(.setting-toggle) { flex-direction: column; align-items: flex-start; }
}

/* ---------- Vehicle preview ---------- */

.preview-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 7, 8, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.vehicle-preview {
  width: min(1000px, 100%);
  max-height: min(780px, calc(100svh - 32px));
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--line-2);
}
.vehicle-preview-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.vehicle-preview-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  line-height: 1;
}
.vehicle-preview-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.vehicle-preview-stage {
  position: relative;
  min-height: 300px;
  overflow: hidden;
  isolation: isolate;
  --turntable-bottom: clamp(94px, 13vw, 142px);
  --turntable-width: min(58%, 540px);
  --turntable-height: clamp(70px, 9vw, 108px);
  --turntable-center-x: 50%;
  --turntable-rotation: 0rad;
  --engine-room-glow: transparent;
  --turntable-drive-glow: rgba(241, 90, 36, 0.2);
  background:
    radial-gradient(circle at 50% 58%, var(--engine-room-glow), transparent 30%),
    radial-gradient(circle at 50% 10%, rgba(238, 246, 246, 0.1), transparent 26%),
    linear-gradient(180deg, #171c1e 0%, #121617 50%, #0b0e0f 50%, #0d1011 100%);
}
.vehicle-preview-stage.engine-on { --engine-room-glow: rgba(245, 245, 238, 0.08); }
.vehicle-preview-stage.accelerating {
  --engine-room-glow: rgba(241, 90, 36, 0.12);
  --turntable-drive-glow: rgba(241, 90, 36, 0.45);
}
.vehicle-preview-stage::before {
  content: "";
  position: absolute;
  left: -18%;
  right: -18%;
  bottom: -24%;
  height: 78%;
  z-index: 0;
  transform: perspective(620px) rotateX(62deg);
  transform-origin: 50% 100%;
  background:
    repeating-linear-gradient(90deg, transparent 0 46px, rgba(241, 90, 36, 0.08) 46px 48px),
    linear-gradient(180deg, rgba(20, 26, 27, 0.3), rgba(7, 9, 10, 0.98));
  opacity: 0.7;
}
.vehicle-preview-stage::after {
  content: "";
  position: absolute;
  left: var(--turntable-center-x);
  bottom: var(--turntable-bottom);
  z-index: 1;
  width: var(--turntable-width);
  height: var(--turntable-height);
  transform: translateX(-50%) perspective(460px) rotateX(3deg);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(238, 246, 246, 0.22), rgba(238, 246, 246, 0.06) 34%, transparent 67%),
    conic-gradient(from var(--turntable-rotation), rgba(238, 246, 246, 0.24) 0deg 3deg, transparent 3deg 52deg, var(--turntable-drive-glow) 52deg 56deg, transparent 56deg 180deg, rgba(238, 246, 246, 0.12) 180deg 183deg, transparent 183deg 360deg),
    repeating-radial-gradient(ellipse at 50% 52%, transparent 0 16px, rgba(238, 246, 246, 0.045) 17px 18px),
    linear-gradient(180deg, #2e3537 0%, #171c1d 52%, #08090a 100%);
  border: 1px solid rgba(238, 246, 246, 0.16);
  box-shadow:
    0 30px 56px rgba(0, 0, 0, 0.56),
    0 7px 0 rgba(6, 9, 9, 0.94),
    inset 0 4px 10px rgba(255, 255, 255, 0.1),
    inset 0 -16px 24px rgba(0, 0, 0, 0.42);
  opacity: 0.9;
}
.vehicle-preview-stage canvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: min(54svh, 520px);
  cursor: grab;
  touch-action: none;
}
.vehicle-preview-stage canvas:active { cursor: grabbing; }
.vehicle-preview-status {
  position: absolute;
  z-index: 3;
  left: 20px;
  bottom: 14px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}
.vehicle-preview-status.error { color: #ff9a8a; }
.vehicle-preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

@media (max-width: 640px) {
  .vehicle-preview-stage canvas { height: 46svh; }
  .vehicle-preview-head h2 { font-size: 1.6rem; }
}

@media (max-width: 820px) {
  .topbar-actions .ucp-logout:not([hidden]) { display: inline-flex; }
}


/* ---------- Bento dashboard ---------- */

.ucp-bento {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}
.ucp-bento > * { min-width: 0; scroll-margin-top: 88px; }
.b-metrics { grid-column: span 12; }
.b-chars { grid-column: span 4; }
.b-driver { grid-column: span 8; }
.b-vehicles { grid-column: span 8; }
.b-settings { grid-column: span 4; }
.b-missions { grid-column: span 12; }
.b-half { grid-column: span 6; }
.b-third { grid-column: span 4; }
.panel-hint { color: var(--faint); font-size: 0.82rem; font-weight: 600; }

@media (max-width: 1100px) {
  .b-chars, .b-settings { grid-column: span 5; }
  .b-driver, .b-vehicles { grid-column: span 7; }
  .b-third { grid-column: span 6; }
  .b-third:last-child { grid-column: span 12; }
}
@media (max-width: 860px) {
  .ucp-bento > * { grid-column: 1 / -1 !important; }
}

/* ---------- Dark theme tweaks ---------- */
:root[data-theme="dark"] .pill.warn,
:root[data-theme="dark"] .status.in-progress { color: #e8c45c; }
:root[data-theme="dark"] .pill.vip { color: #ffb08f; }
:root[data-theme="dark"] .status.abandoned { color: #ff9a8a; }
