:root {
  color-scheme: light;
  --bg: #edf3f8;
  --panel: #ffffff;
  --ink: #142033;
  --muted: #63728a;
  --line: #d6e1ed;
  --primary: #0f766e;
  --primary-dark: #0a5b55;
  --accent: #2463eb;
  --warning: #d97706;
  --danger: #dc2626;
  --success: #15803d;
  --shadow: 0 14px 34px rgba(20, 38, 65, 0.10);
  --soft-shadow: 0 8px 20px rgba(20, 38, 65, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #dfeaf4 0, #f6f8fb 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: max(12px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 auto 12px;
  max-width: 760px;
}

.app-topbar h1,
.driver-card h2,
.panel h2,
.guide-card h3 {
  margin: 0;
}

.app-topbar h1 {
  font-size: 22px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  margin: 6px 0 0;
  overflow-wrap: anywhere;
}

.panel,
.driver-card,
.summary-card,
.toolbar,
.guide-card,
.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.panel {
  width: min(100%, 520px);
  max-width: 520px;
  margin: 18px auto;
  padding: 18px;
}

.form-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

label {
  color: #42526a;
  display: grid;
  font-size: 12px;
  font-weight: 800;
  gap: 6px;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  border: 1px solid #c9d5e5;
  border-radius: 7px;
  color: var(--ink);
  min-height: 48px;
  padding: 12px 12px;
  outline: none;
  background: #fff;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

button {
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 800;
  min-height: 46px;
  padding: 11px 14px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-btn {
  background: linear-gradient(180deg, #118176 0%, var(--primary-dark) 100%);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
  color: white;
}

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

.secondary-btn {
  background: #e5f3f1;
  color: var(--primary-dark);
}

.ghost-btn,
.icon-btn {
  background: #eef3fa;
  color: #42526a;
}

.manual-box {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 12px;
}

.manual-box summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.connection-field {
  margin-top: 12px;
}

.hidden {
  display: none !important;
}

#appView {
  max-width: 980px;
  margin: 0 auto;
}

.driver-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  position: sticky;
  top: max(8px, env(safe-area-inset-top));
  z-index: 10;
}

.driver-actions {
  display: flex;
  gap: 8px;
}

.status-pill {
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
  padding: 8px 10px;
}

.status-pill.online {
  background: #dcfce7;
  color: var(--success);
}

.status-pill.offline {
  background: #fee2e2;
  color: var(--danger);
}

.summary-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
  margin: 12px 0;
}

.summary-card {
  padding: 13px;
}

.summary-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  font-size: 28px;
  line-height: 1;
  margin-top: 8px;
}

.toolbar {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 180px;
  margin-bottom: 12px;
  padding: 12px;
}

.notice {
  border-left: 4px solid var(--warning);
  color: #6b4a00;
  margin-bottom: 12px;
  padding: 12px;
}

.guides-list {
  display: grid;
  gap: 12px;
}

.guide-card {
  padding: 14px;
}

.guide-head {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.guide-number {
  font-size: 20px;
}

.guide-status {
  border-radius: 999px;
  color: white;
  font-size: 12px;
  font-weight: 800;
  padding: 7px 10px;
  text-align: center;
}

.guide-status.pending {
  background: var(--warning);
}

.guide-status.transit {
  background: var(--accent);
}

.guide-status.done {
  background: var(--success);
}

.guide-status.other {
  background: #64748b;
}

.guide-data {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 14px 0;
}

.guide-data div {
  border-top: 1px solid #edf2f7;
  padding-top: 8px;
}

.guide-data dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.guide-data dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
}

.guide-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1.2fr 1fr 1fr;
}

.empty-state {
  color: var(--muted);
  padding: 28px 12px;
  text-align: center;
}

.module-switch {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(2, 1fr);
  margin: 12px 0;
  padding: 6px;
  position: sticky;
  top: 82px;
  z-index: 9;
  backdrop-filter: blur(10px);
}

.module-btn {
  background: transparent;
  color: #52637a;
}

.module-btn.active {
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
  color: #fff;
}

.gate-hero {
  align-items: center;
  background: linear-gradient(135deg, #ffffff 0%, #edf8f5 55%, #eef5ff 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 16px;
}

.gate-hero h2,
.gate-panel h3,
.panel-head h3 {
  margin: 0;
}

.gate-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scroll-snap-type: x proximity;
}

.gate-tab-btn {
  background: #fff;
  border: 1px solid var(--line);
  color: #52637a;
  flex: 0 0 158px;
  min-height: 50px;
  scroll-snap-align: start;
}

.gate-tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.22);
  color: #fff;
}

.gate-panel {
  margin-top: 0;
  max-width: none;
  padding: 16px;
}

.gate-panel h3 {
  font-size: 18px;
  margin-bottom: 12px;
}

.scan-row,
.gate-grid,
.compact-buttons {
  display: grid;
  gap: 10px;
}

.scan-row {
  grid-template-columns: minmax(0, 1fr) 74px 92px;
  margin-bottom: 12px;
}

.gate-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 10px 0;
}

.compact-buttons {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 6px 0 12px;
}

.gate-result {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #52637a;
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  min-height: 58px;
  padding: 12px;
}

.gate-result strong {
  color: var(--ink);
}

.gate-result span,
.gate-result small {
  overflow-wrap: anywhere;
}

textarea {
  border: 1px solid #c9d5e5;
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  min-height: 88px;
  outline: none;
  padding: 10px 12px;
  resize: vertical;
  width: 100%;
}

textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.check-list {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.check-list label {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: row;
  gap: 10px;
  min-height: 46px;
  padding: 10px 12px;
  text-transform: none;
}

.check-list input {
  min-height: auto;
  width: auto;
}

.full-btn {
  margin-top: 12px;
  width: 100%;
}

.gate-details {
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 10px 0;
  padding: 12px;
}

.native-select-hidden {
  display: none;
}

.search-select {
  position: relative;
}

.search-select-input {
  padding-right: 38px;
  background:
    linear-gradient(45deg, transparent 50%, #6b7b90 50%) right 18px center / 7px 7px no-repeat,
    #fff;
}

.search-select-list {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
  left: 0;
  max-height: 248px;
  overflow: auto;
  padding: 6px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
}

.search-select-option {
  background: transparent;
  border-radius: 6px;
  color: var(--ink);
  display: block;
  min-height: 42px;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.search-select-option:hover,
.search-select-option:focus {
  background: #eaf2ff;
  color: #174eb9;
}

.search-select-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px;
  text-align: center;
}

.gate-details summary {
  color: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.gate-details label {
  margin-top: 10px;
}

.panel-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 12px;
}

.history-item span,
.history-item small {
  color: var(--muted);
}

.qr-scan-overlay {
  align-items: center;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 9999;
}

.qr-scan-box {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
  display: grid;
  gap: 12px;
  max-width: 460px;
  padding: 14px;
  width: 100%;
}

.qr-scan-box video {
  background: #0f172a;
  border-radius: 8px;
  min-height: 280px;
  object-fit: cover;
  width: 100%;
}

.qr-scan-box p {
  color: var(--muted);
  margin: 0;
  text-align: center;
}

@media (max-width: 680px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .app-topbar {
    align-items: flex-start;
    margin-bottom: 8px;
  }

  .panel {
    margin: 12px 0;
    max-width: 100%;
  }

  .driver-card,
  .guide-head {
    align-items: stretch;
    flex-direction: column;
  }

  .driver-actions,
  .guide-actions,
  .toolbar {
    grid-template-columns: 1fr;
  }

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

  .guide-data {
    grid-template-columns: 1fr;
  }

  .module-switch,
  .gate-grid,
  .compact-buttons,
  .scan-row {
    grid-template-columns: 1fr;
  }

  .module-switch {
    top: 112px;
  }

  .gate-tabs {
    margin-left: -10px;
    margin-right: -10px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .gate-tab-btn {
    flex-basis: 138px;
  }

  .gate-hero,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .gate-tab-btn {
    min-height: 48px;
  }

  .qr-scan-box video {
    min-height: 220px;
  }
}
