:root {
  --bg: #f5f6f8;
  --ink: #111827;
  --muted: #6b7280;
  --card: #ffffff;
  --line: #e5e7eb;
  --navy: #101828;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --amber: #f59e0b;
  --red: #dc2626;
  --shadow: 0 18px 55px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: ui-sans-serif, "Segoe UI", "Microsoft YaHei", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1180px, calc(100vw - 28px)); margin: 0 auto; padding: 28px 0 48px; }
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
  padding: 28px;
  border-radius: 30px;
  background: linear-gradient(135deg, #101828 0%, #1e293b 62%, #334155 100%);
  color: white;
  box-shadow: var(--shadow);
}
.eyebrow { margin: 0 0 8px; color: #93c5fd; font-size: 12px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(34px, 5vw, 64px); line-height: .95; letter-spacing: -.055em; }
.lead { margin: 14px 0 0; max-width: 720px; color: #dbeafe; line-height: 1.7; font-size: 16px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.primary, .secondary, .danger {
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 900;
}
.primary { background: var(--blue); color: white; box-shadow: 0 10px 24px rgba(37, 99, 235, .28); }
.secondary { background: white; color: var(--navy); border: 1px solid var(--line); }
.danger { background: #fff1f2; color: var(--red); border: 1px solid #fecdd3; }
.full { width: 100%; }

.vehicle-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.vehicle-card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
  padding: 18px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .06);
}
.vehicle-card header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.plate { font-size: 24px; font-weight: 1000; letter-spacing: -.03em; }
.status { display: inline-flex; align-items: center; height: 28px; padding: 0 10px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-size: 12px; font-weight: 900; }
.vehicle-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; color: var(--muted); font-size: 13px; }
.vehicle-meta strong { display: block; color: var(--ink); font-size: 16px; margin-top: 3px; }

.layout { display: grid; grid-template-columns: 190px 1fr; gap: 16px; align-items: start; }
.rail {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 8px;
  border-radius: 22px;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--line);
}
.rail-btn {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 900;
}
.rail-btn.active { background: var(--navy); color: white; }
.workspace { min-width: 0; }
.tab { display: none; }
.tab.active { display: grid; gap: 16px; }
.section-head {
  border-radius: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  padding: 22px;
}
.section-head span { color: var(--amber); font-weight: 1000; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.section-head h2 { margin: 5px 0 8px; font-size: 30px; letter-spacing: -.04em; }
.section-head p { margin: 0; color: var(--muted); line-height: 1.65; }
.card {
  border-radius: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 12px 34px rgba(15, 23, 42, .07);
}
.form-card { padding: 22px; display: grid; gap: 16px; }
.form-card.compact { margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
label { display: grid; gap: 7px; font-size: 13px; color: #374151; font-weight: 900; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 11px 13px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
textarea { min-height: 104px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(37, 99, 235, .12); }
.check-panel, .promise-box, .upload-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: #f9fafb;
  display: grid;
  gap: 10px;
}
.check-panel h3, .promise-box h3, .upload-panel h3 { margin: 0; }
.promise-box { background: #fffbeb; border-color: #fde68a; }
.upload-panel { background: #eff6ff; border-color: #bfdbfe; }
.promise-box p { margin: 0; color: #92400e; line-height: 1.65; }
.check-panel label, .promise-box label { display: flex; align-items: flex-start; gap: 9px; line-height: 1.5; }
.check-panel input, .promise-box input { width: auto; min-height: auto; margin-top: 3px; }
.signature-field {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}
.signature-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.mini {
  min-height: 36px;
  padding: 7px 12px;
  border-radius: 12px;
  font-size: 12px;
}
#signature-pad {
  width: 100%;
  height: 190px;
  border: 2px dashed #d6a239;
  border-radius: 18px;
  background:
    linear-gradient(transparent calc(100% - 42px), rgba(146, 64, 14, .12) calc(100% - 42px)),
    #fffdf7;
  touch-action: none;
  cursor: crosshair;
}
.signature-field small { color: #92400e; line-height: 1.5; }
.owner-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.owner-card { padding: 18px; }
.owner-card h3 { margin: 0 0 10px; }
.owner-card p { margin: 6px 0; color: var(--muted); }
.records { display: grid; gap: 12px; }
.record {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: white;
  display: grid;
  gap: 12px;
}
.record header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.record header strong { min-width: 0; word-break: break-word; }
.record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.record-row {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid #eef2f7;
  word-break: break-word;
}
.record-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
}
.record-row strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
.record-row a { color: var(--blue); }
.tag { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-size: 12px; font-weight: 900; white-space: nowrap; }

@media (max-width: 860px) {
  body { background: #f8fafc; }
  .app-shell {
    width: 100%;
    padding: 10px 10px calc(96px + env(safe-area-inset-bottom));
  }
  .hero, .layout, .vehicle-strip, .owner-grid, .form-grid { grid-template-columns: 1fr; }
  .hero {
    padding: 20px;
    border-radius: 0 0 28px 28px;
    margin: -10px -10px 14px;
    min-height: 238px;
    align-items: end;
  }
  h1 { font-size: 42px; }
  .lead { font-size: 15px; line-height: 1.65; }
  .hero-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .primary, .secondary, .danger { min-height: 52px; border-radius: 16px; }
  .vehicle-strip {
    display: flex;
    overflow-x: auto;
    gap: 12px;
    margin: 0 -10px 14px;
    padding: 0 10px 4px;
    scroll-snap-type: x mandatory;
  }
  .vehicle-card {
    min-width: min(86vw, 360px);
    scroll-snap-align: start;
    border-radius: 22px;
    padding: 16px;
  }
  .vehicle-meta { grid-template-columns: 1fr 1fr; }
  .vehicle-meta div:last-child { grid-column: 1 / -1; }
  .layout { display: block; }
  .rail {
    position: fixed;
    z-index: 20;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    border-radius: 22px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, .2);
  }
  .rail-btn {
    min-height: 56px;
    padding: 6px 4px;
    text-align: center;
    font-size: 12px;
    line-height: 1.2;
    border-radius: 16px;
  }
  .section-head {
    padding: 18px;
    border-radius: 22px;
  }
  .section-head h2 { font-size: 26px; }
  .form-card { padding: 16px; border-radius: 22px; gap: 14px; }
  label { font-size: 14px; }
  input, select, textarea {
    min-height: 52px;
    border-radius: 16px;
    font-size: 16px;
  }
  textarea { min-height: 118px; }
  .check-panel, .promise-box, .upload-panel { border-radius: 18px; padding: 14px; }
  .check-panel label, .promise-box label { min-height: 44px; align-items: center; }
  #signature-pad { height: 210px; }
  .signature-head { align-items: center; }
  .record { border-radius: 18px; padding: 14px; }
  .record-grid { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .hero-actions { grid-template-columns: 1fr; }
  .plate { font-size: 21px; }
  .vehicle-meta { grid-template-columns: 1fr; }
  .vehicle-meta div:last-child { grid-column: auto; }
  .rail-btn { font-size: 11px; }
}

/* Mobile hard override: keep navigation as compact bottom tabs on real phones. */
@media screen and (max-width: 860px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .layout {
    display: block !important;
    grid-template-columns: none !important;
  }

  .workspace {
    width: 100% !important;
    min-width: 0 !important;
  }

  .rail {
    position: fixed !important;
    top: auto !important;
    left: 10px !important;
    right: 10px !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: 76px !important;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    align-items: stretch !important;
    gap: 6px !important;
    padding: 8px !important;
    margin: 0 !important;
    border-radius: 22px !important;
    background: rgba(255, 255, 255, .96) !important;
    box-shadow: 0 18px 45px rgba(15, 23, 42, .22) !important;
  }

  .rail-btn {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 52px !important;
    height: 52px !important;
    padding: 4px 2px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: normal !important;
    text-align: center !important;
    font-size: 11px !important;
    line-height: 1.15 !important;
  }
}

/* Mobile compact redesign: short header, tiny vehicle cards, detail panel, tighter forms. */
@media screen and (max-width: 860px) {
  .app-shell {
    padding: 0 10px calc(86px + env(safe-area-inset-bottom)) !important;
  }

  .hero {
    height: clamp(86px, 15svh, 128px) !important;
    min-height: 0 !important;
    margin: 0 -10px 10px !important;
    padding: 12px 14px !important;
    border-radius: 0 0 18px 18px !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 10px !important;
    box-shadow: 0 10px 26px rgba(15, 23, 42, .14) !important;
  }

  .hero .eyebrow,
  .hero .lead {
    display: none !important;
  }

  .hero h1 {
    font-size: clamp(22px, 6vw, 28px) !important;
    line-height: 1.12 !important;
    letter-spacing: -.035em !important;
  }

  .hero-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 6px !important;
    min-width: 92px !important;
  }

  .hero-actions .primary,
  .hero-actions .secondary {
    min-height: 34px !important;
    padding: 6px 10px !important;
    border-radius: 11px !important;
    font-size: 12px !important;
    box-shadow: none !important;
  }

  .vehicle-strip {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    overflow: visible !important;
    margin: 0 0 8px !important;
    padding: 0 !important;
  }

  .vehicle-card-mini {
    min-width: 0 !important;
    width: 100% !important;
    min-height: 98px !important;
    padding: 10px !important;
    border-radius: 16px !important;
    border: 1px solid var(--line) !important;
    text-align: left !important;
    background: #fff !important;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .06) !important;
  }

  .vehicle-card-mini.selected {
    border-color: rgba(37, 99, 235, .65) !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .1), 0 8px 20px rgba(15, 23, 42, .06) !important;
  }

  .vehicle-card-mini header {
    margin-bottom: 8px !important;
    gap: 6px !important;
  }

  .vehicle-card-mini .plate {
    font-size: 15px !important;
    line-height: 1.05 !important;
    letter-spacing: -.02em !important;
  }

  .vehicle-name,
  .vehicle-card-hint {
    display: none !important;
  }

  .vehicle-card-mini .status {
    height: 22px !important;
    padding: 0 7px !important;
    font-size: 10px !important;
  }

  .vehicle-card-line {
    display: grid !important;
    gap: 2px !important;
    color: var(--muted) !important;
    font-size: 11px !important;
  }

  .vehicle-card-line strong {
    color: var(--ink) !important;
    font-size: 17px !important;
    line-height: 1.05 !important;
  }

  .vehicle-detail {
    margin: 0 0 10px !important;
    padding: 12px !important;
    border-radius: 16px !important;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .06) !important;
  }

  .vehicle-detail.empty {
    display: none !important;
  }

  .vehicle-detail-head {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
    margin-bottom: 10px !important;
  }

  .vehicle-detail-head span {
    display: block !important;
    color: var(--muted) !important;
    font-size: 11px !important;
    font-weight: 900 !important;
  }

  .vehicle-detail-head strong {
    display: block !important;
    font-size: 20px !important;
    letter-spacing: -.03em !important;
  }

  .vehicle-detail-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .vehicle-detail-grid div {
    min-height: 52px !important;
    padding: 8px !important;
    border-radius: 12px !important;
    background: #f8fafc !important;
    color: var(--muted) !important;
    font-size: 11px !important;
    font-weight: 900 !important;
  }

  .vehicle-detail-grid strong {
    display: block !important;
    margin-top: 3px !important;
    color: var(--ink) !important;
    font-size: 14px !important;
  }

  .vehicle-detail-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    margin-top: 10px !important;
  }

  .vehicle-detail-actions .primary,
  .vehicle-detail-actions .secondary {
    min-height: 42px !important;
    padding: 8px 10px !important;
    border-radius: 12px !important;
    font-size: 13px !important;
  }

  .tab.active {
    gap: 10px !important;
  }

  .section-head {
    padding: 12px 14px !important;
    border-radius: 16px !important;
  }

  .section-head span,
  .section-head p {
    display: none !important;
  }

  .section-head h2 {
    margin: 0 !important;
    font-size: 20px !important;
    line-height: 1.15 !important;
  }

  .form-card {
    padding: 12px !important;
    border-radius: 16px !important;
    gap: 10px !important;
  }

  .form-grid {
    gap: 9px !important;
  }

  label {
    gap: 4px !important;
    font-size: 12px !important;
  }

  input,
  select,
  textarea {
    min-height: 44px !important;
    border-radius: 12px !important;
    padding: 9px 11px !important;
    font-size: 16px !important;
  }

  textarea {
    min-height: 76px !important;
  }

  .check-panel,
  .promise-box,
  .upload-panel {
    padding: 10px !important;
    border-radius: 14px !important;
    gap: 7px !important;
  }

  .check-panel h3,
  .promise-box h3,
  .upload-panel h3,
  .form-card > h3 {
    font-size: 15px !important;
    margin: 0 !important;
  }

  .promise-box p,
  .signature-field small {
    display: none !important;
  }

  .check-panel label,
  .promise-box label {
    min-height: 34px !important;
    line-height: 1.3 !important;
  }

  #signature-pad {
    height: 132px !important;
    border-radius: 14px !important;
  }

  .record {
    padding: 11px !important;
    border-radius: 14px !important;
  }

  .record-row {
    padding: 9px !important;
  }

  .record-row strong {
    font-size: 12px !important;
    line-height: 1.45 !important;
  }
}


/* Mobile overflow guard: keep checkout inputs inside viewport. */
@media screen and (max-width: 860px) {
  .form-grid *,
  .form-card * {
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-wrap: anywhere;
  }

  .form-card,
  .form-grid,
  .check-panel,
  .promise-box,
  .upload-panel,
  .signature-field {
    width: 100% !important;
    max-width: calc(100vw - 20px) !important;
    overflow-x: hidden !important;
  }

  input[type="file"] {
    font-size: 12px !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  #checkout-form {
    overflow-x: hidden !important;
  }
}
