/* ================================================
   TRACKSIDE CONTROL — Global Stylesheet
   Aston Martin Performance Technologies branding
   Dark, high-contrast, glove-friendly UI
   Mobile-first design for phones and tablets
   ================================================ */

/* ---- Design tokens ---- */
:root {
  /* Status colours */
  --red:          #FF2020;
  --orange:       #FF9000;
  --green:        #00DD44;

  /* Dimmed / inactive versions */
  --red-dim:      #3A0808;
  --orange-dim:   #3A2000;
  --green-dim:    #003A14;

  /* Glow colours (rgba for box-shadow) */
  --red-glow:     rgba(255, 32, 32, 0.55);
  --orange-glow:  rgba(255, 144, 0, 0.55);
  --green-glow:   rgba(0, 221, 68, 0.55);

  /* Brand accent */
  --accent:       #00574B;
  --accent-dim:   #00352F;

  /* Surface palette */
  --bg:           #0A0A0A;
  --surface:      #161616;
  --surface-2:    #202020;
  --border:       #2C2C2C;
  --border-light: #424242;

  /* Text */
  --text:         #FFFFFF;
  --text-sub:     #999999;
  --text-dim:     #555555;

  /* Sizing */
  --touch-min:    64px;   /* minimum tap target height */
  --radius:       10px;
  --radius-lg:    18px;
}

/* ---- Reset ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* ---- Typography ---- */
h1 { font-size: clamp(1.6rem, 5vw, 2.2rem); font-weight: 900; letter-spacing: -0.5px; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
p  { font-size: 1rem; }

/* ---- Utility ---- */
.hidden       { display: none !important; }
.text-center  { text-align: center; }
.text-sub     { color: var(--text-sub); }
.text-sm      { font-size: 0.85rem; }
.fw-bold      { font-weight: 700; }
.mt-8         { margin-top: 8px; }
.mt-12        { margin-top: 12px; }
.mt-16        { margin-top: 16px; }
.mt-24        { margin-top: 24px; }
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.gap-16       { gap: 16px; }
.w-full       { width: 100%; }
.divider      { border: none; border-top: 2px solid var(--border); margin: 20px 0; }

/* ---- Layout container ---- */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

/* ---- Logo bar ---- */
.logo-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.page-logo {
  display: block;
  max-height: 52px;
  width: auto;
  background: #ffffff;
  mix-blend-mode: multiply;
  border-radius: 4px;
  padding: 4px 10px;
}

/* ---- Site footer ---- */
.site-footer {
  text-align: center;
  padding: 18px 16px;
  font-size: 0.72rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  letter-spacing: 0.5px;
}

/* ---- Sticky header ---- */
.header {
  background: var(--surface);
  border-bottom: 2px solid var(--accent-dim);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 58px;
}
.header-left { flex: 1; min-width: 0; }
.header-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-sub {
  font-size: 0.75rem;
  color: var(--text-sub);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---- Buttons ---- */
button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch-min);
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  transition: opacity 0.15s ease, transform 0.1s ease;
  -webkit-user-select: none;
  user-select: none;
  line-height: 1;
}
button:active:not(:disabled) { transform: scale(0.96); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: #00574B;
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: #007A5E;
  color: #0A0A0A;
}
.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--border);
}
.btn-ghost:hover { border-color: var(--border-light); }

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 2px solid var(--red);
}
.btn-sm {
  min-height: 48px;
  font-size: 0.82rem;
  padding: 8px 14px;
  width: auto;
  letter-spacing: 1px;
}
.btn-icon {
  min-height: 44px;
  min-width: 44px;
  width: 44px;
  padding: 0;
  font-size: 1.1rem;
  border-radius: 8px;
}

/* ---- Status buttons (RED / ORANGE / GREEN) ---- */
.status-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.status-btn {
  flex-direction: column;
  gap: 10px;
  min-height: 100px;
  border-radius: var(--radius-lg);
  border: 3px solid transparent;
  font-size: 0.75rem;
  letter-spacing: 2px;
  opacity: 0.45;
  transition: opacity 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.status-btn .dot {
  width: 38px;
  height: 38px;
  border-radius: 50%;
}

/* Inactive tint */
.status-btn.red-btn    { background: var(--red-dim);    color: var(--red);    }
.status-btn.orange-btn { background: var(--orange-dim); color: var(--orange); }
.status-btn.green-btn  { background: var(--green-dim);  color: var(--green);  }

/* Dot colours */
.status-btn .dot.red    { background: var(--red);    }
.status-btn .dot.orange { background: var(--orange); }
.status-btn .dot.green  { background: var(--green);  }

/* Active state */
.status-btn.active { opacity: 1; }
.status-btn.red-btn.active    { border-color: var(--red);    box-shadow: 0 0 24px var(--red-glow);    }
.status-btn.orange-btn.active { border-color: var(--orange); box-shadow: 0 0 24px var(--orange-glow); }
.status-btn.green-btn.active  { border-color: var(--green);  box-shadow: 0 0 24px var(--green-glow);  }

/* ---- Traffic light ---- */
.traffic-light {
  background: #111;
  border: 4px solid #2A2A2A;
  border-radius: 999px;   /* pill shape */
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
}
/* Size variants */
.tl-sm .light { width: 44px; height: 44px; }
.tl-sm        { gap: 10px; padding: 14px 16px; }

.tl-md .light { width: 68px; height: 68px; }
.tl-md        { gap: 14px; }

.tl-lg .light { width: 90px; height: 90px; }
.tl-lg        { gap: 18px; padding: 24px 28px; }

.light {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid #1A1A1A;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}
/* Default dim */
.light.red    { background: var(--red-dim); }
.light.orange { background: var(--orange-dim); }
.light.green  { background: var(--green-dim); }
/* Active / lit */
.light.red.on    { background: var(--red);    box-shadow: 0 0 30px var(--red-glow),    0 0 60px var(--red-glow);    }
.light.orange.on { background: var(--orange); box-shadow: 0 0 30px var(--orange-glow), 0 0 60px var(--orange-glow); }
.light.green.on  { background: var(--green);  box-shadow: 0 0 30px var(--green-glow),  0 0 60px var(--green-glow);  }

.traffic-light-label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-sub);
  text-align: center;
  text-transform: uppercase;
  margin-top: 4px;
}

/* Light label beneath traffic light */
.tl-state-label {
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-align: center;
  margin-top: 6px;
  transition: color 0.3s;
}
.tl-state-label.red    { color: var(--red); }
.tl-state-label.orange { color: var(--orange); }
.tl-state-label.green  { color: var(--green); }

/* ---- Car card (chief/admin grid) ---- */
.car-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}
.car-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.car-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}
.car-card-name {
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.3;
}

/* ---- Car selection buttons ---- */
.car-select-btn {
  background: var(--surface-2);
  border: 2px solid var(--border);
  color: var(--text);
  text-align: left;
  min-height: 80px;
  border-radius: var(--radius-lg);
  padding: 0 24px;
  font-size: 1.2rem;
  justify-content: flex-start;
  letter-spacing: 0;
  text-transform: none;
  font-weight: 700;
  transition: border-color 0.2s, background 0.2s;
}
.car-select-btn:hover,
.car-select-btn:active { border-color: var(--border-light); background: #2A2A2A; }

/* ---- Engineer list ---- */
.engineer-list { display: flex; flex-direction: column; gap: 8px; }
.engineer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 2px solid var(--border);
}
.engineer-info { flex: 1; min-width: 0; }
.engineer-name { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.engineer-role { font-size: 0.78rem; color: var(--text-sub); margin-top: 2px; }
.status-dot-sm {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.1);
}
.status-dot-sm.red    { background: var(--red);    box-shadow: 0 0 8px var(--red-glow);    }
.status-dot-sm.orange { background: var(--orange); box-shadow: 0 0 8px var(--orange-glow); }
.status-dot-sm.green  { background: var(--green);  box-shadow: 0 0 8px var(--green-glow);  }

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-sub);
  margin-bottom: 16px;
}

/* ---- Forms ---- */
.form-group    { display: flex; flex-direction: column; gap: 8px; }
.form-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 1px;
}
input[type="text"],
input[type="email"],
input[type="password"],
select {
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  padding: 14px 16px;
  width: 100%;
  min-height: 54px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-dim); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; padding-right: 40px; }
select option { background: var(--surface-2); }

/* ---- Tabs (admin) ---- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  flex: 1;
  min-height: 50px;
  background: transparent;
  border-radius: 8px;
  color: var(--text-sub);
  font-size: 0.8rem;
  border: 2px solid transparent;
  letter-spacing: 1px;
}
.tab-btn.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-admin    { background: #151540; color: #8888FF; border: 1px solid #3333AA; }
.badge-engineer { background: var(--surface-2); color: var(--text-sub); border: 1px solid var(--border); }
.badge-chief    { background: #0D2A18; color: #55CC88; border: 1px solid #227744; }
.badge-pending  { background: var(--orange-dim); color: var(--orange); border: 1px solid var(--orange); }
.badge-disabled { background: #141414; color: var(--text-dim); border: 1px solid #333; }

/* ---- Alerts ---- */
.alert {
  padding: 14px 16px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.9rem;
  border: 2px solid;
  line-height: 1.5;
}
.alert-warn    { background: var(--orange-dim); border-color: var(--orange); color: var(--orange); }
.alert-danger  { background: var(--red-dim);    border-color: var(--red);    color: var(--red);    }
.alert-success { background: var(--green-dim);  border-color: var(--green);  color: var(--green);  }
.alert-info    { background: var(--surface-2);  border-color: var(--border); color: var(--text);   }

/* ---- Toast notification ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 2px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px 22px;
  font-weight: 700;
  font-size: 0.95rem;
  z-index: 9999;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  animation: toastIn 0.25s ease;
  pointer-events: none;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0);   }
}

/* ---- Loading spinner ---- */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 16px;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Login page ---- */
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
}
.login-logo   { font-size: 3rem; margin-bottom: 6px; }
.login-title  { font-size: 1.7rem; font-weight: 900; text-align: center; letter-spacing: -0.5px; }
.login-sub    { color: var(--text-sub); text-align: center; font-size: 0.9rem; margin: 6px 0 28px; }
.login-card   { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-lg); padding: 28px 24px; width: 100%; max-width: 420px; }
.login-form   { display: flex; flex-direction: column; gap: 14px; }
.form-toggle  {
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  min-height: auto;
  width: auto;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.form-toggle:hover { color: var(--text); }

/* ---- Pending / error screen ---- */
.status-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
  padding: 32px 24px;
  gap: 16px;
}
.status-icon { font-size: 4rem; }

/* ---- Admin user row ---- */
.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 2px solid var(--border);
}
.user-row-info  { flex: 1; min-width: 0; }
.user-row-name  { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-row-email { font-size: 0.78rem; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-row-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---- Admin car row ---- */
.car-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 2px solid var(--border);
}
.car-row-name { flex: 1; font-weight: 700; font-size: 1rem; }

/* ---- My-status display (engineer dashboard) ---- */
.my-status-display {
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 12px;
  border: 3px solid;
  transition: background 0.3s, color 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.my-status-display.red    { background: var(--red-dim);    color: var(--red);    border-color: var(--red);    box-shadow: 0 0 20px var(--red-glow);    }
.my-status-display.orange { background: var(--orange-dim); color: var(--orange); border-color: var(--orange); box-shadow: 0 0 20px var(--orange-glow); }
.my-status-display.green  { background: var(--green-dim);  color: var(--green);  border-color: var(--green);  box-shadow: 0 0 20px var(--green-glow);  }

/* ---- Status toggle button (engineer dashboard) ---- */
.status-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 72px;
  border-radius: var(--radius);
  border: 3px solid transparent;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  width: 100%;
  opacity: 0.75;
  transition: opacity 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.status-toggle:hover:not(:disabled) { opacity: 1; }
.status-toggle.active               { opacity: 1; }
.status-toggle .dot { width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; }
.status-toggle .dot.red    { background: var(--red);    }
.status-toggle .dot.orange { background: var(--orange); }
.status-toggle .dot.green  { background: var(--green);  }
.status-toggle.red-btn    { background: var(--red-dim);    color: var(--red);    }
.status-toggle.orange-btn { background: var(--orange-dim); color: var(--orange); }
.status-toggle.green-btn  { background: var(--green-dim);  color: var(--green);  }
.status-toggle.red-btn.active    { border-color: var(--red);    box-shadow: 0 0 16px var(--red-glow);    opacity: 1; }
.status-toggle.orange-btn.active { border-color: var(--orange); box-shadow: 0 0 16px var(--orange-glow); opacity: 1; }
.status-toggle.green-btn.active  { border-color: var(--green);  box-shadow: 0 0 16px var(--green-glow);  opacity: 1; }

/* ---- Responsive adjustments ---- */
@media (max-width: 480px) {
  .car-grid { grid-template-columns: 1fr; }
  .tl-lg .light { width: 72px; height: 72px; }
  .tl-lg        { gap: 14px; padding: 18px 22px; }
  .status-btn   { min-height: 88px; }
  .status-btn .dot { width: 32px; height: 32px; }
}

@media (min-width: 768px) {
  body { font-size: 17px; }
  .car-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
}

@media (min-width: 1024px) {
  .tl-lg .light { width: 110px; height: 110px; }
  .status-btn   { min-height: 110px; }
}

.ampt-logo {
  display: block;
  margin: 0 auto 16px auto;
  width: 160px;
  mix-blend-mode: luminosity;
  background: transparent;
  border-radius: 4px;
  filter: invert(1);
}

footer {
  text-align: center;
  padding: 16px;
  color: #666;
  font-size: 12px;
  margin-top: auto;
}
