:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #e4e7ee;
  --soft: #eef2f7;
  --blue: #2f6fed;
  --blue-dark: #2158c9;
  --green: #20a866;
  --green-bg: #e7f7ef;
  --yellow: #d89512;
  --yellow-bg: #fff4d8;
  --red: #d94841;
  --red-bg: #fdecea;
  --gray-bg: #eef0f4;
  --shadow: 0 14px 38px rgba(23, 32, 51, .08);
  --slot-width: 34px;
  --vehicle-col: 154px;
  --slot-count: 28;
  --track-height: 42px;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 14px 8px;
  color: #d9e1ef;
  background: #101827;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 16px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  color: #fff;
  font-size: 14px;
}

.brand small {
  margin-top: 2px;
  color: #93a0b8;
  font-size: 10px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-btn {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  color: #aeb8ca;
  background: transparent;
  text-align: left;
  font-size: 13px;
}

.nav-btn:hover,
.nav-btn.active {
  color: #fff;
  background: rgba(255, 255, 255, .1);
}

.nav-btn.locked {
  color: #667085;
}

.workspace {
  min-width: 0;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.16;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 17px;
  letter-spacing: 0;
}

.top-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.text-btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.primary-btn {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--blue-dark);
}

.primary-btn:disabled,
.primary-btn:disabled:hover {
  cursor: not-allowed;
  border-color: #cfd7e6;
  background: #d9e0eb;
  color: #7b8798;
}

.danger-btn {
  border-color: rgba(217, 72, 65, .35);
  color: #b72f2a;
  background: #fff;
}

.text-btn {
  min-height: 32px;
  padding: 0 10px;
}

.toast {
  display: none;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(47, 111, 237, .25);
  border-radius: 8px;
  color: #1f4fab;
  background: #edf4ff;
}

.toast.show {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.stat-card,
.panel,
.filters,
.schedule-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat-card {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  box-shadow: 0 4px 12px rgba(23, 32, 51, .04);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.stat-card strong {
  display: block;
  margin-top: 0;
  font-size: 20px;
  line-height: 1;
}

.filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  margin-bottom: 12px;
}

.ai-booking {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  background:
    linear-gradient(135deg, rgba(47, 111, 237, .08), rgba(32, 168, 102, .05)),
    #fff;
}

.ai-entry {
  display: grid;
  grid-template-columns: minmax(180px, .36fr) minmax(320px, 1fr);
  align-items: stretch;
  gap: 14px;
}

.ai-lead {
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 8px;
}

.ai-lead strong {
  display: block;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.25;
}

.ai-lead p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.ai-submit {
  min-width: 108px;
  min-height: 42px;
  font-size: 16px;
}

.ai-input {
  min-height: 86px;
}

.ai-input-wrap {
  display: grid;
  gap: 8px;
}

.ai-formula {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.ai-formula-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ai-light {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 9px;
  border: 1px solid;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.ai-light i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.ai-confirm-inline {
  min-height: 30px;
  padding: 0 14px;
  font-size: 13px;
}

.ai-light.pending {
  border-color: rgba(216, 149, 18, .26);
  color: #865908;
  background: var(--yellow-bg);
}

.ai-light.pending i {
  background: var(--yellow);
}

.ai-light.ok {
  border-color: rgba(32, 168, 102, .24);
  color: #0f7749;
  background: var(--green-bg);
}

.ai-light.ok i {
  background: var(--green);
}

.ai-light.error {
  border-color: rgba(217, 72, 65, .24);
  color: #a62a25;
  background: var(--red-bg);
}

.ai-light.error i {
  background: var(--red);
}

.ai-result {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(47, 111, 237, .12);
}

.ai-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-summary span,
.ai-message {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  color: #1f4fab;
  background: #edf4ff;
  font-size: 12px;
  font-weight: 700;
}

.ai-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ai-candidates {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.vehicle-choice {
  min-height: 62px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.vehicle-choice:has(input:checked) {
  border-color: rgba(47, 111, 237, .55);
  box-shadow: inset 0 0 0 1px rgba(47, 111, 237, .22);
}

.vehicle-choice b,
.vehicle-choice small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vehicle-choice small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.field {
  min-height: 36px;
  min-width: 136px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.legend {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: 1px;
}

.schedule-card {
  overflow: hidden;
  box-shadow: var(--shadow);
}

.schedule-scroll {
  overflow: auto;
}

.timeline {
  min-width: calc(var(--vehicle-col) + (var(--slot-count) * var(--slot-width)));
  display: grid;
  grid-template-columns: var(--vehicle-col) repeat(var(--slot-count), var(--slot-width));
}

.corner,
.time-cell {
  position: sticky;
  top: 0;
  z-index: 4;
  min-height: 38px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--muted);
  font-size: 11px;
}

.corner {
  left: 0;
  z-index: 7;
  padding-left: 14px;
  border-right: 1px solid var(--line);
  color: var(--ink);
  font-weight: 700;
}

.time-cell {
  justify-content: center;
  border-right: 1px solid #eef0f4;
}

.time-cell.muted {
  color: #a8b0c0;
  font-size: 10px;
}

.vehicle-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  min-height: var(--track-height);
  display: grid;
  align-content: center;
  padding: 3px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.plate {
  margin-bottom: 1px;
  font-weight: 800;
  font-size: 12px;
}

.vehicle-meta {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.15;
}

.track {
  grid-column: 2 / span var(--slot-count);
  align-self: stretch;
  min-height: var(--track-height);
  display: grid;
  grid-template-columns: repeat(var(--slot-count), var(--slot-width));
  grid-template-rows: minmax(var(--track-height), 1fr);
  border-bottom: 1px solid var(--line);
  cursor: crosshair;
  touch-action: none;
  background:
    repeating-linear-gradient(to right, transparent 0, transparent 33px, #f0f2f5 33px, #f0f2f5 34px),
    linear-gradient(to bottom, transparent 0, transparent 16px, rgba(23, 32, 51, .04) 17px, transparent 18px);
}

.booking-block {
  grid-row: 1;
  z-index: 2;
  align-self: stretch;
  min-width: 0;
  width: calc(100% - 2px);
  height: 100%;
  margin: 0 1px;
  padding: 0 8px;
  border: 1px solid;
  border-radius: 4px;
  display: grid;
  align-content: center;
  gap: 1px;
  overflow: hidden;
  white-space: nowrap;
  box-shadow: 0 4px 10px rgba(23, 32, 51, .07);
  cursor: pointer;
}

.booking-block.selected {
  outline: 2px solid rgba(47, 111, 237, .7);
  outline-offset: -3px;
}

.booking-block strong,
.booking-block small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.booking-block strong {
  font-size: 11px;
  line-height: 1.15;
}

.booking-block small {
  color: rgba(23, 32, 51, .72);
  font-size: 10px;
  line-height: 1.1;
}

.draft-block {
  grid-row: 1;
  z-index: 4;
  height: 100%;
  margin: 0 1px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid #c6ccd7;
  border-radius: 4px;
  color: #5e6675;
  background: rgba(100, 116, 139, .22);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

.past-block {
  grid-row: 1;
  height: 100%;
  background: rgba(96, 165, 250, .16);
  pointer-events: none;
}

.unreturned-block {
  grid-row: 1;
  z-index: 3;
  height: 100%;
  padding: 0 8px;
  display: flex;
  align-items: center;
  overflow: hidden;
  border-left: 1px solid rgba(217, 72, 65, .28);
  color: rgba(166, 42, 37, .82);
  background: rgba(217, 72, 65, .08);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
}

.quick-booking {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(160px, .8fr) minmax(200px, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 12px;
}

.quick-booking h2 {
  margin-bottom: 4px;
}

.quick-booking p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 132px;
  padding: 6px;
  border: 1px solid rgba(23, 32, 51, .12);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 38px rgba(23, 32, 51, .18);
}

.context-menu button {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.context-menu button:hover {
  background: var(--soft);
}

.context-menu [data-menu-action="cancel"] {
  color: #b72f2a;
}

.context-menu [data-menu-action="cancel"]:hover {
  background: var(--red-bg);
}

.context-menu [data-menu-action="return"] {
  color: #0f7749;
}

.context-menu [data-menu-action="return"]:hover {
  background: var(--green-bg);
}

.action-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 24, 39, .22);
}

.action-card {
  width: min(520px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 46px rgba(23, 32, 51, .2);
}

.action-card h2 {
  margin-bottom: 0;
}

.action-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-grid.compact {
  gap: 10px;
}

.tone-green {
  border-color: rgba(32, 168, 102, .35);
  background: var(--green-bg);
}

.tone-yellow {
  border-color: rgba(216, 149, 18, .58);
  background: #fff0bf;
}

.tone-red {
  border-color: rgba(217, 72, 65, .38);
  background: var(--red-bg);
}

.tone-gray {
  border-color: #d7dbe4;
  background: var(--gray-bg);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, .95fr);
  gap: 12px;
}

.panel {
  padding: 14px;
}

.panel + .panel {
  margin-top: 12px;
}

.table-wrap {
  overflow: auto;
}

.data-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

.data-table th {
  color: var(--muted);
  background: #fbfcfe;
  font-weight: 700;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-field {
  display: grid;
  gap: 7px;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

.textarea {
  min-height: 82px;
  resize: vertical;
}

.help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.green {
  color: #0f7749;
  background: var(--green-bg);
}

.status-pill.yellow {
  color: #865908;
  background: var(--yellow-bg);
}

.status-pill.red {
  color: #a62a25;
  background: var(--red-bg);
}

.status-pill.gray {
  color: #5e6675;
  background: var(--gray-bg);
}

.kpi-list {
  display: grid;
  gap: 8px;
}

.kpi-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.kpi-item:last-child {
  border-bottom: 0;
}

.kpi-item b {
  display: block;
  margin-bottom: 4px;
}

.kpi-item span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 5px;
  min-height: 160px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .side-nav {
    position: static;
    height: auto;
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-list {
    display: flex;
    overflow: auto;
    padding-bottom: 4px;
  }

  .nav-btn {
    width: auto;
    white-space: nowrap;
  }

  .workspace {
    padding: 16px;
  }

  .topbar {
    display: block;
  }

  .top-actions {
    justify-content: flex-start;
    margin-top: 14px;
  }

  .stats-grid,
  .content-grid,
  .form-grid,
  .quick-booking,
  .ai-entry,
  .ai-fields,
  .ai-candidates {
    grid-template-columns: 1fr;
  }

  .legend {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 620px) {
  h1 {
    font-size: 24px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field,
  .top-actions > *,
  .row-actions > * {
    width: 100%;
  }
}
