/* =========== Workshop palette: Blue Night + Rusty Silver =========== */
:root {
  --c-bg:        #0A1929;
  --c-surface:   #13243B;
  --c-surface-2: #1B324F;
  --c-border:    #243B5A;
  --c-text:      #ECEFF3;
  --c-muted:     #8A9099;
  --c-silver:    #B8C2CC;
  --c-accent:    #E2B33C;
  --c-accent-2:  #C99A2A;
  --c-danger:    #E05A4A;
  --c-success:   #4CB17B;
  --radius:      14px;
  --radius-sm:   10px;
  --shadow:      0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

/* Make sure the HTML5 [hidden] attribute always wins over our display rules. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--c-muted); }
.error { color: var(--c-danger); font-size: 13px; margin-top: 8px; }
.badge {
  background: var(--c-surface-2);
  color: var(--c-silver);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}

/* =========== Buttons =========== */
button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  transition: transform .05s ease, opacity .15s ease, background .15s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--c-accent);
  color: var(--c-bg);
}
.btn-primary:hover:not(:disabled) { background: var(--c-accent-2); }

.btn-ghost {
  background: transparent;
  color: var(--c-silver);
  border: 1px solid var(--c-border);
}
.btn-ghost:hover { background: var(--c-surface); color: #fff; }

.btn-danger {
  background: transparent;
  color: var(--c-danger);
  border: 1px solid var(--c-danger);
}
.btn-danger:hover { background: var(--c-danger); color: #fff; }

.btn-success {
  background: var(--c-success);
  color: #0a1f14;
}

/* =========== Form fields =========== */
label {
  display: block;
  margin-bottom: 14px;
}
label > span {
  display: block;
  font-size: 12px;
  color: var(--c-muted);
  margin-bottom: 6px;
  letter-spacing: .3px;
}
input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"],
input[type="search"] {
  width: 100%;
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s ease;
}
input:focus {
  border-color: var(--c-accent);
}
input[type="search"] {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238A9099' stroke-width='2'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
  padding-left: 38px;
}

.input-suffix {
  position: relative;
}
.input-suffix input { padding-right: 42px; }
.input-suffix span {
  position: absolute;
  right: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--c-muted);
  font-size: 13px;
}

/* =========== Login view =========== */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -100px, rgba(226,179,60,.06), transparent 60%),
    var(--c-bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo {
  width: 96px; height: 96px;
  object-fit: cover;
  border-radius: 50%;
  margin-bottom: 16px;
  border: 2px solid var(--c-border);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.login-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
  font-weight: 700;
  letter-spacing: .3px;
}
.login-card p { margin: 0 0 24px; font-size: 13px; }
#login-form { text-align: left; }
#login-form .btn-primary { width: 100%; margin-top: 8px; }

/* =========== App layout =========== */
.app-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--c-border);
}
.brand h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .3px;
}
.brand .muted { font-size: 11px; }
.topbar-actions { display: flex; gap: 8px; }
.topbar-actions .btn-ghost { padding: 8px 14px; }
#refresh-btn { font-size: 18px; padding: 8px 14px; }

/* Tab nav between Clients and Map views */
.topbar-tabs {
  display: flex;
  gap: 4px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  padding: 4px;
}
.tab-btn {
  background: transparent;
  color: var(--c-muted);
  border: 0;
  padding: 6px 18px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.tab-btn:hover { color: var(--c-silver); }
.tab-btn.active {
  background: var(--c-accent);
  color: var(--c-bg);
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-tabs { order: 3; width: 100%; justify-content: center; }
}

/* Map view */
.map-tab {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  overflow: hidden;
}
@media (max-width: 880px) {
  .map-tab { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
}
.map-sidebar {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.map-sidebar-section {
  border-top: 1px solid var(--c-border);
  padding: 16px;
  margin-top: auto;
}
.map-sidebar-section h4 {
  margin: 0 0 4px;
  font-size: 13px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--c-muted);
}
.map-sidebar-section .small { font-size: 11px; margin: 0 0 12px; }
.map-sidebar-section .btn-primary,
.map-sidebar-section .btn-ghost { width: 100%; margin-top: 8px; }
.map-canvas {
  background: #0d1a2c;
  min-height: 400px;
}
.leaflet-container {
  background: #0d1a2c !important;
  font-family: inherit;
}
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; }
.leaflet-popup-content strong { color: #fff; }
.car-marker {
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
  background: var(--c-accent);
  color: var(--c-bg);
  border-radius: 50%;
  font-size: 18px;
  font-weight: 700;
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
.car-marker.stale {
  background: var(--c-rusty-silver, #8A9099);
  color: #fff;
}
.clients-list li.no-loc {
  opacity: 0.5;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr;
  overflow: hidden;
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
}

/* =========== Clients panel =========== */
.clients-panel {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 8px;
}
.panel-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--c-muted);
}
.clients-panel #search-input {
  margin: 0 16px 12px;
  width: calc(100% - 32px);
}
.clients-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px 16px;
  overflow-y: auto;
  flex: 1;
}
.clients-list li {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.clients-list li:hover { background: var(--c-surface-2); }
.clients-list li.active {
  background: var(--c-surface-2);
  box-shadow: inset 3px 0 0 var(--c-accent);
}
.clients-list .plate {
  font-weight: 600;
  color: #fff;
  letter-spacing: .8px;
  font-size: 14px;
}
.clients-list .phone {
  font-size: 12px;
  color: var(--c-muted);
  margin-top: 2px;
}
.clients-list .km {
  color: var(--c-accent);
  font-weight: 600;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.clients-list .empty {
  color: var(--c-muted);
  cursor: default;
  text-align: center;
  padding: 24px;
}

/* =========== Detail panel =========== */
.detail-panel {
  overflow-y: auto;
  padding: 24px;
}
.placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--c-muted);
  text-align: center;
}
.placeholder-icon { font-size: 56px; margin-bottom: 12px; }

.detail-header {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.detail-header .plate-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--c-silver);
  font-size: 13px;
  margin-bottom: 4px;
}
.detail-header .plate-row strong {
  color: #fff;
  font-size: 16px;
  letter-spacing: 1px;
}
.detail-header .phone-row {
  color: var(--c-muted);
  font-size: 13px;
  margin-bottom: 16px;
}
.detail-header .mileage-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.detail-header .mileage {
  font-size: 44px;
  font-weight: 700;
  color: var(--c-accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}
.detail-header .mileage-unit {
  color: var(--c-muted);
  font-size: 16px;
  margin-left: 4px;
}
.detail-header .last-synced {
  color: var(--c-muted);
  font-size: 12px;
  margin-top: 4px;
}

.section-title {
  margin: 24px 4px 8px;
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--c-muted);
  font-weight: 700;
}

/* =========== Maintenance cards =========== */
.maint-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
}
.maint-card.overdue {
  border-color: var(--c-danger);
  box-shadow: inset 0 0 0 1px rgba(224,90,74,.15);
}
.maint-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.maint-head h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}
.progress {
  height: 8px;
  background: var(--c-surface-2);
  border-radius: 6px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-bar {
  height: 100%;
  background: var(--c-success);
  transition: width .3s ease;
}
.progress-bar.warning { background: var(--c-accent); }
.progress-bar.danger  { background: var(--c-danger); }
.maint-foot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--c-muted);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.maint-foot .remaining { color: var(--c-text); font-weight: 600; }
.maint-foot .remaining.overdue { color: var(--c-danger); }

/* =========== Toast =========== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-accent);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 1000;
  animation: slideUp .25s ease;
}
.toast.success { border-left-color: var(--c-success); }
.toast.error   { border-left-color: var(--c-danger); }
@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* =========== Modal =========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: grid;
  place-items: center;
  z-index: 900;
  padding: 16px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}
.modal-card p { margin: 0 0 18px; font-size: 13px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* =========== Spinner =========== */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
