:root {
  --red: #c90000;
  --red-dark: #9e0000;
  --ink: #1d2023;
  --muted: #657078;
  --line: #dfe3e6;
  --bg: #f3f4f5;
  --surface: #fff;
  --soft: #fbf0f0;
  --shadow: 0 10px 30px rgba(25, 30, 34, .08);
}

* { box-sizing: border-box; }
[hidden], .login-view[hidden], .app-view[hidden], .page-view[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--bg); font-family: "Segoe UI", Roboto, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 3vw, 1.8rem); }
h2 { margin-bottom: 5px; font-size: clamp(1.2rem, 2.5vw, 1.45rem); }
.eyebrow { margin-bottom: 6px; color: var(--red); font-size: .7rem; font-weight: 800; letter-spacing: .12em; }

.login-view { min-height: 100vh; padding: 28px 18px; background: linear-gradient(145deg, #1b1b1c 0%, #38393a 54%, #970000 180%); display: grid; place-items: center; }
.login-card { width: min(100%, 470px); padding: 28px; border-radius: 18px; background: #fff; box-shadow: 0 18px 55px rgba(0,0,0,.24); }
.login-logo { display: block; width: min(100%, 380px); height: 82px; margin: 0 auto 22px; object-fit: contain; }
.login-copy p:not(.eyebrow) { margin-bottom: 22px; color: var(--muted); line-height: 1.45; }
.setup-alert { display: grid; gap: 4px; margin-bottom: 18px; padding: 13px; border: 1px solid #ebc7c7; border-radius: 9px; color: #811010; background: #fff4f4; font-size: .86rem; }
.login-form { display: grid; gap: 14px; }
.login-note { margin: 17px 0 0; color: var(--muted); font-size: .78rem; text-align: center; }

.topbar { min-height: 102px; padding: 14px max(20px, calc((100% - 1180px) / 2)); border-bottom: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand-block { display: flex; align-items: center; gap: 15px; min-width: 0; }
.header-logo { width: 200px; max-width: 38vw; height: 64px; object-fit: contain; }
.brand-divider { width: 1px; height: 47px; background: var(--line); }
.brand-block .eyebrow { margin-bottom: 4px; }
.user-area { display: flex; align-items: center; justify-content: flex-end; gap: 10px; text-align: right; }
.user-area strong, .user-area span { display: block; }
.user-area span { margin-top: 3px; color: var(--muted); font-size: .76rem; }

.tabs { padding: 0 max(20px, calc((100% - 1180px) / 2)); border-bottom: 1px solid var(--line); background: var(--surface); display: flex; gap: 22px; }
.tab { min-height: 49px; padding: 0 3px; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; font-weight: 700; }
.tab.active { border-bottom-color: var(--red); color: var(--red); }
.content { width: min(100%, 1180px); margin: 0 auto; padding: 28px 20px 42px; }
.page-heading, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-heading > div > p:not(.eyebrow) { margin-bottom: 0; color: var(--muted); }
.required-note { margin-top: 5px; color: var(--muted); font-size: .75rem; white-space: nowrap; }

.panel, .filter-panel { margin-top: 22px; padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field span { color: #414b50; font-size: .84rem; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #bbc3c8; border-radius: 8px; color: var(--ink); background: #fff; outline: none; }
input[readonly] { color: #636d73; background: #f1f3f4; }
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(201,0,0,.11); }
textarea { min-height: 80px; resize: vertical; }
.distance-preview { margin-top: 18px; padding: 13px 14px; border-radius: 9px; color: #5c3131; background: var(--soft); display: flex; justify-content: space-between; align-items: center; font-size: .88rem; }
.distance-preview strong { color: var(--red-dark); }
.form-actions, .filter-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px; }
.primary-button, .outline-button, .text-button { min-height: 40px; padding: 0 14px; border-radius: 8px; font-weight: 700; }
.primary-button { border: 1px solid var(--red); color: #fff; background: var(--red); }
.primary-button:hover { background: var(--red-dark); }
.primary-button:disabled { cursor: not-allowed; opacity: .55; }
.outline-button { border: 1px solid #aeb7bc; color: #303b41; background: #fff; }
.outline-button:hover, .text-button:hover { background: #f3f5f6; }
.text-button { border: 0; color: var(--red); background: transparent; }

.history-section { margin-top: 34px; }
.section-heading { align-items: center; margin-bottom: 14px; }
.trips-list { display: grid; gap: 12px; }
.trip-card { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.trip-top { display: flex; justify-content: space-between; gap: 14px; }
.trip-top h3 { margin-bottom: 3px; color: #2d3539; font-size: 1rem; }
.trip-top p { margin: 0; color: var(--muted); font-size: .85rem; }
.trip-top > strong { color: var(--red); font-size: .83rem; white-space: nowrap; }
.trip-data { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.trip-data div { padding: 8px; border-radius: 7px; background: #f4f5f6; }
.trip-data span, .trip-data b { display: block; }
.trip-data span { color: var(--muted); font-size: .67rem; letter-spacing: .04em; text-transform: uppercase; }
.trip-data b { margin-top: 4px; color: #39434a; font-size: .8rem; }
.trip-notes { margin: 12px 0 0; color: #59656c; font-size: .84rem; }
.empty-state { padding: 31px 14px; color: var(--muted); text-align: center; }
.empty-state span { display: block; margin-bottom: 9px; font-size: 2rem; }
.empty-state h3 { margin-bottom: 6px; color: #424b51; font-size: 1rem; }
.empty-state p { margin-bottom: 0; font-size: .87rem; }

.filter-panel { margin-top: 20px; box-shadow: none; }
.filter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.metrics { margin-top: 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; }
.metric-card { min-height: 91px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
.metric-card span { display: block; color: var(--muted); font-size: .75rem; }
.metric-card strong { display: block; margin-top: 7px; color: var(--red-dark); font-size: clamp(1.18rem, 2.5vw, 1.45rem); }
.table-panel { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 1120px; border-collapse: collapse; text-align: left; }
th { padding: 13px 14px; color: #6b757b; background: #f4f5f6; font-size: .71rem; letter-spacing: .04em; text-transform: uppercase; }
td { padding: 13px 14px; border-top: 1px solid var(--line); color: #3c464c; font-size: .83rem; vertical-align: top; }
td:last-child { max-width: 230px; color: #667178; }

.gps-panel { margin-top: 18px; padding: 17px; border: 1px solid #efc7c7; border-radius: 11px; background: linear-gradient(120deg, #fff9f9, #fff); }
.gps-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.gps-heading .eyebrow { margin-bottom: 4px; }
.gps-heading h3 { margin-bottom: 5px; font-size: 1rem; }
.gps-heading p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.4; }
.gps-indicator { flex: 0 0 auto; padding: 6px 9px; border-radius: 999px; color: #6d5555; background: #f1e9e9; font-size: .74rem; font-weight: 700; }
.gps-indicator[data-state="tracking"] { color: #fff; background: var(--red); }
.gps-indicator[data-state="complete"] { color: #275c3d; background: #e4f4e9; }
.gps-indicator[data-state="error"] { color: #8d4e00; background: #fff0d6; }
.gps-details { margin-top: 15px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.gps-details div { padding: 10px; border-radius: 8px; background: rgba(255,255,255,.76); border: 1px solid #f0e1e1; }
.gps-details span, .gps-details strong { display: block; }
.gps-details span { color: var(--muted); font-size: .68rem; letter-spacing: .035em; text-transform: uppercase; }
.gps-details strong { margin-top: 4px; color: #3b4247; font-size: .91rem; }
.gps-actions { margin-top: 14px; display: flex; gap: 10px; }
.route-map-button { min-height: 32px; padding: 0 9px; border: 1px solid #e2aaaa; border-radius: 7px; color: var(--red-dark); background: #fff8f8; font-weight: 700; font-size: .76rem; white-space: nowrap; }
.route-map-button:hover { background: #ffeded; }
.route-none { color: var(--muted); font-size: .78rem; }
.route-dialog { width: min(860px, calc(100vw - 30px)); max-height: min(770px, calc(100vh - 30px)); padding: 0; border: 0; border-radius: 14px; box-shadow: 0 20px 70px rgba(0,0,0,.32); }
.route-dialog::backdrop { background: rgba(14,18,21,.66); }
.route-dialog-header { padding: 20px 20px 14px; display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.route-dialog-header h2 { margin-bottom: 4px; }
.route-dialog-header p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: .84rem; }
#route-map { min-height: 430px; background: #edf0f2; }
.route-dialog-message { margin: 0; padding: 16px 20px 20px; color: var(--muted); font-size: .85rem; }
.fuel-preview { margin-top: 18px; padding: 13px 14px; border-radius: 9px; color: #5c3131; background: #fbf0f0; display: flex; justify-content: space-between; align-items: center; font-size: .88rem; }
.fuel-preview strong { color: var(--red-dark); }
.vehicle-admin-panel, .fuel-manager-panel { margin-top: 22px; }
.admin-help { margin-bottom: 0; color: var(--muted); font-size: .88rem; }
.vehicle-form { margin-top: 17px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; gap: 13px; }
.vehicle-form .primary-button { width: 100%; }
.vehicle-admin-list { margin-top: 15px; display: grid; gap: 9px; }
.vehicle-admin-card { padding: 13px 14px; border: 1px solid #dfe3e6; border-radius: 10px; background: #fff; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.vehicle-admin-card.inactive { opacity: .65; background: #f7f8f8; }
.vehicle-admin-card strong, .vehicle-admin-card span { display: block; }
.vehicle-admin-card strong { color: #30393e; font-size: .93rem; }
.vehicle-admin-card span { margin-top: 4px; color: var(--muted); font-size: .78rem; }
.vehicle-admin-actions { display: flex; align-items: center; gap: 9px; }
.vehicle-admin-card .outline-button { min-height: 34px; padding: 0 10px; font-size: .78rem; }
.vehicle-status { margin: 0 !important; padding: 5px 7px; border-radius: 999px; color: #27613d !important; background: #e5f3e9; font-weight: 700; white-space: nowrap; }
.inactive .vehicle-status { color: #727b80 !important; background: #eaedef; }
.fuel-metrics { margin-top: 16px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.fuel-manager-panel .table-wrap { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; }

.toast { position: fixed; z-index: 10; bottom: 24px; left: 50%; max-width: calc(100% - 30px); padding: 12px 16px; border-radius: 9px; color: #fff; background: #24282b; box-shadow: 0 8px 22px rgba(0,0,0,.2); font-size: .88rem; opacity: 0; transform: translate(-50%, 18px); pointer-events: none; transition: opacity .18s, transform .18s; }
.toast[data-type="error"] { background: #9b1414; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 780px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .user-area { width: 100%; justify-content: flex-start; text-align: left; flex-wrap: wrap; }
  .filter-grid, .metrics { grid-template-columns: repeat(2, 1fr); }
  .vehicle-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .login-card { padding: 23px 18px; }
  .login-logo { height: 67px; }
  .header-logo { width: 165px; max-width: 53vw; height: 49px; }
  .brand-divider { display: none; }
  .content { padding: 22px 14px 35px; }
  .page-heading { display: block; }
  .required-note { display: block; margin-top: 12px; }
  .form-grid, .filter-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .trip-data { grid-template-columns: 1fr; }
  .form-actions, .filter-actions { flex-direction: column-reverse; }
  .form-actions button, .filter-actions button { width: 100%; }
  .metrics { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .metric-card { min-height: 76px; padding: 12px; }
  .gps-heading { display: block; }
  .gps-indicator { display: inline-block; margin-top: 10px; }
  .gps-details { grid-template-columns: 1fr; }
  .gps-actions { flex-direction: column; }
  .gps-actions button { width: 100%; }
  .vehicle-form, .fuel-metrics { grid-template-columns: 1fr; }
  .vehicle-admin-card { align-items: flex-start; flex-direction: column; }
  .vehicle-admin-actions { width: 100%; justify-content: space-between; }
  .fuel-preview { align-items: flex-start; flex-direction: column; gap: 6px; }
  .route-dialog-header { display: block; }
  .route-dialog-header .outline-button { width: 100%; margin-top: 13px; }
  #route-map { min-height: 340px; }
}
