/*
 * VEZILINK visual system
 * A native-CSS compatibility layer for the existing product markup.
 * The operational UI follows Carbon-like density and hierarchy without
 * claiming to be the official IBM Carbon package.
 */

:root {
  --bg: #f1f3f5;
  --surface: #fbfcfd;
  --surface-raised: #ffffff;
  --surface-subtle: #f5f7f9;
  --sidebar: #111a28;
  --sidebar-hover: #1a2739;
  --sidebar-active: #223b5f;
  --line: #d7dde5;
  --line-strong: #b8c2cf;
  --muted: #637083;
  --text: #172233;
  --text-strong: #0f1928;
  --accent: #245fc5;
  --accent-strong: #174da8;
  --accent-soft: #e8effb;
  --ok: #087a55;
  --ok-soft: #e7f6ef;
  --warn: #a85612;
  --warn-soft: #fff2e5;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --shadow: 0 16px 42px rgba(23, 34, 51, .12);
  --radius-control: 6px;
  --radius-panel: 8px;
  --font-ui: "Avenir Next", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #aeb8c6 transparent;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: -.005em;
}

button,
input,
select,
textarea {
  border-color: var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface-raised);
  color: var(--text);
  font-family: inherit;
}

button,
.button-link {
  min-height: 38px;
  font-weight: 650;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease, transform .08s ease;
}

button:hover,
.button-link:hover {
  border-color: #8e9bad;
  background: var(--surface-subtle);
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

input::placeholder,
textarea::placeholder {
  color: #7b8798;
  opacity: 1;
}

:where(button, a, input, select, textarea, [role="button"]):focus-visible {
  outline: 3px solid rgba(36, 95, 197, .22);
  outline-offset: 2px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: none;
}

.btn-primary,
.row button:last-child,
#loginBtn,
#createTripBtn,
#orgCreateBtn,
#uCreateBtn,
#createRouteBtn,
#createDriverBtn,
#saveOfflineBtn {
  border-color: var(--accent);
  background: var(--accent);
  color: #f8fbff;
  box-shadow: none;
}

.btn-primary:hover,
.row button:last-child:hover,
#loginBtn:hover,
#createTripBtn:hover,
#orgCreateBtn:hover,
#uCreateBtn:hover,
#createRouteBtn:hover,
#createDriverBtn:hover,
#saveOfflineBtn:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.btn-danger {
  border-color: #e3a09a;
  background: transparent;
  color: var(--danger);
}

.btn-danger:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* Application shell */

#appShell {
  grid-template-columns: 232px minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr);
  background: var(--bg);
}

#brand {
  min-width: 0;
  padding: 0 16px;
  border: 0;
  background: var(--sidebar);
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex-basis: 32px;
  border-radius: 5px;
  background: #f5f8fc;
  color: var(--accent-strong);
  font-size: 11px;
  letter-spacing: -.03em;
  box-shadow: none;
}

.brand-copy {
  color: #f6f8fb;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -.02em;
}

.brand-copy small {
  margin-top: 3px;
  color: #8fa0b7;
  font-size: 9px;
  letter-spacing: .12em;
}

.nav-collapse {
  color: #91a1b7;
}

.nav-collapse:hover {
  border-color: transparent;
  background: var(--sidebar-hover);
}

#nav {
  padding: 14px 10px 24px;
  border: 0;
  background: var(--sidebar);
}

.nav-section {
  margin: 20px 12px 7px;
  color: #718198;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .13em;
}

.nav-section:first-child {
  margin-top: 8px;
}

.tab {
  min-height: 40px;
  margin: 0 0 3px;
  padding: 9px 11px;
  border-radius: var(--radius-control);
  color: #b7c1cf;
  font-size: 13px;
  font-weight: 600;
}

.tab:hover {
  background: var(--sidebar-hover);
  color: #f6f8fb;
}

.tab.active {
  background: var(--sidebar-active);
  color: #ffffff;
}

.tab.active::before {
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 0;
  background: #78a7ef;
}

.nav-icon,
.tab.active .nav-icon,
.tab:hover .nav-icon {
  color: currentColor;
}

.topbar {
  gap: 8px;
  padding: 0 18px;
  border-color: var(--line);
  background: rgba(251, 252, 253, .96);
  box-shadow: none;
  backdrop-filter: blur(12px);
}

.global-search {
  width: min(520px, 43vw);
  height: 38px;
  border-color: var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-subtle);
}

.global-search:focus-within {
  border-color: var(--accent);
  background: var(--surface-raised);
}

.global-search kbd {
  border-color: #c8d0da;
  border-radius: 4px;
  background: #fff;
  box-shadow: none;
}

.workspace-mode {
  min-height: 36px;
  border-color: #b9c9e3;
  border-radius: var(--radius-control);
  background: #eef3fa;
  color: var(--accent-strong);
}

#orgSwitch {
  min-width: 190px;
  margin-left: 2px;
}

#who {
  position: relative;
  max-width: 250px;
  min-height: 38px;
  padding: 6px 11px 6px 30px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--surface-subtle);
  color: #344054;
  font-size: 12px;
}

#who::before {
  left: 12px;
  width: 7px;
  height: 7px;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

#logoutBtn {
  width: 38px;
  min-width: 38px;
  padding: 0;
  border-color: var(--line);
  background: transparent;
}

#logoutBtn span:last-child {
  display: none;
}

#workspace {
  background: var(--bg);
}

.panel,
.panel:not(#panel-map) {
  padding: 26px 30px 44px;
  background: var(--bg);
}

.page-head {
  align-items: flex-end;
  margin-bottom: 20px;
}

.page-title {
  color: var(--text-strong);
  font-size: clamp(23px, 2vw, 28px);
  font-weight: 720;
  letter-spacing: -.035em;
}

.page-subtitle {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.page-actions {
  gap: 7px;
}

.page-actions > * {
  white-space: nowrap;
}

/* Core surfaces and content hierarchy */

.surface,
.metric,
.department,
.driver-card,
.trip-card,
.shipment-card,
.platform-company,
.platform-ops-grid,
.driver-table,
details {
  border-color: var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface-raised);
  box-shadow: none;
}

.surface {
  padding: 18px;
}

.surface-title {
  margin-bottom: 14px;
}

.surface-title h2,
.trip-list-head h2 {
  color: var(--text-strong);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.015em;
}

.surface-title h3 {
  font-size: 14px;
}

.surface-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.list {
  border-color: var(--line);
  border-radius: var(--radius-panel);
  background: transparent;
  box-shadow: none;
}

.item {
  border-color: #e5e9ee;
}

.pill,
.status,
.meta-chip {
  border-color: var(--line);
  border-radius: 999px;
  box-shadow: none;
}

.status::before {
  width: 5px;
  height: 5px;
}

.metric-grid {
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--line);
}

.metric {
  min-height: 102px;
  border: 0;
  border-radius: 0;
  background: var(--surface-raised);
}

.metric::after {
  display: none;
}

.metric span {
  color: var(--muted);
  font-size: 11px;
}

.metric b,
.fleet-kpis b,
.fleet-secondary b,
.attention-count b {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.04em;
}

.field {
  gap: 5px;
}

.field > span,
.form-grid label > span {
  color: #465365;
  font-size: 11px;
  font-weight: 650;
}

textarea {
  font-family: inherit;
}

.code-block,
.code-tool pre,
.trip-code,
.shipment-credential small b {
  font-family: var(--font-mono);
}

/* Operations dashboard */

.operations-dashboard {
  grid-template-columns: minmax(0, 1.18fr) minmax(330px, .82fr);
  gap: 12px;
}

.operations-dashboard > .surface {
  padding: 20px;
}

.attention-command,
.fleet-command {
  min-height: 278px;
}

.attention-count {
  min-width: 82px;
  border-color: #efb9b4;
  border-radius: var(--radius-control);
  background: var(--danger-soft);
}

.attention-list .item {
  min-height: 66px;
  padding: 12px 2px;
}

.fleet-kpis {
  border-radius: var(--radius-control);
  background: var(--line);
  gap: 1px;
}

.fleet-kpis button {
  min-height: 64px;
  border: 0 !important;
  background: var(--surface-raised);
}

.fleet-kpis button:hover,
.fleet-secondary button:hover {
  background: var(--surface-subtle);
}

.fleet-secondary {
  margin-top: 10px;
  border-color: var(--line);
}

.dashboard-activity {
  min-height: 190px;
}

.activity-list {
  max-height: 218px;
}

/* Trips: reduce nested-card noise and keep action hierarchy clear */

.issues-strip {
  margin-bottom: 12px;
  padding: 14px 16px;
  border-color: #e3c18d;
  background: #fffaf2;
}

.issues-strip .surface-title {
  margin-bottom: 10px;
}

.issues-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.issue-item {
  min-height: 54px;
  padding: 9px 11px;
  border: 0;
  border-left: 2px solid #d58a2d;
  border-radius: 0;
  background: rgba(255, 255, 255, .72);
}

.trip-workspace {
  grid-template-columns: minmax(600px, 1.2fr) minmax(400px, .8fr);
  gap: 12px;
}

.trip-master,
.trip-inspector {
  padding: 16px;
}

.trip-master {
  min-width: 0;
}

.trip-inspector {
  top: 0;
  max-height: calc(100dvh - 122px);
}

.dispatcher-toolbar {
  grid-template-columns: minmax(210px, 1fr) minmax(150px, .44fr) minmax(145px, .4fr) 38px;
  gap: 7px;
  margin-bottom: 12px;
  padding: 10px;
  border-radius: var(--radius-control);
  background: var(--surface-subtle);
}

.dispatcher-toolbar input,
.dispatcher-toolbar select {
  min-height: 36px;
}

.view-switch,
.detail-tabs {
  border-color: var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-subtle);
}

.view-switch button.active,
.detail-tabs button.active {
  background: var(--surface-raised);
  color: var(--accent-strong);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.trip-board {
  gap: 8px;
}

.trip-column {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.trip-column + .trip-column {
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.trip-column-head {
  padding: 4px 3px 9px;
  color: #526073;
  font-size: 10px;
  letter-spacing: .09em;
}

.trip-column-count {
  height: 22px;
  min-width: 22px;
  border-radius: 999px;
  background: transparent;
}

.trip-column-body {
  gap: 6px;
}

.trip-card {
  padding: 12px;
  border-color: var(--line);
  border-radius: var(--radius-control);
}

.trip-card:hover {
  border-color: #91a5c1;
  box-shadow: none;
}

.trip-card.selected {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.trip-client-line {
  border: 0;
  border-radius: 0;
  background: var(--surface-subtle);
}

.trip-code {
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.detail-tabs {
  position: sticky;
  top: -16px;
  z-index: 2;
  margin: 0 -16px 14px;
  padding: 4px 16px 0;
  border-width: 0 0 1px;
  border-radius: 0;
  background: rgba(255, 255, 255, .97);
}

.detail-tabs button {
  border-radius: 0;
}

.trip-detail-empty {
  min-height: 150px;
  border-style: dashed;
  background: var(--surface-subtle);
}

.section-title {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.sticky-actions {
  background: var(--surface-raised);
}

/* Platform and directory screens */

.platform-metrics {
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--line);
}

.platform-metric {
  border: 0;
  border-radius: 0;
}

.platform-metric::after {
  display: none;
}

.platform-layout,
.platform-ops-section,
.content-wrap,
.dashboard-content {
  max-width: 1480px;
}

.platform-company,
.platform-ops-grid {
  box-shadow: none;
}

.directory-toolbar,
.driver-toolbar,
.shipment-toolbar {
  padding: 10px;
  border-radius: var(--radius-control);
  background: var(--surface-subtle);
}

.driver-table-head,
.platform-lead-head {
  background: var(--surface-subtle);
}

.driver-table-row:hover,
.platform-lead-row:hover,
.trip-table tbody tr:hover,
.archive-table tbody tr:hover {
  background: #f4f6f8;
}

.trip-table tbody tr.selected,
.archive-table tbody tr.selected {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}

/* Map, dialogs and feedback */

#panel-map .map-tools,
.map-drawer,
.timelapse-panel {
  border-color: #cbd3dd;
  border-radius: var(--radius-panel);
  background: rgba(251, 252, 253, .96);
  box-shadow: var(--shadow);
}

#panel-map .map-tools {
  top: 16px;
  right: 16px;
  width: 284px !important;
  padding: 11px !important;
}

.map-layer-menu,
.map-settings {
  border-color: var(--line);
  background: transparent;
}

.map-options label {
  border-radius: var(--radius-control);
}

.entity-drawer {
  top: 64px;
  border-color: var(--line);
  background: var(--surface-raised);
  box-shadow: -18px 0 48px rgba(23, 34, 51, .14);
}

.entity-drawer-head {
  background: rgba(255, 255, 255, .96);
}

.toast-stack {
  right: 16px;
  bottom: 16px;
}

.toast {
  border: 1px solid #314057;
  border-radius: var(--radius-panel);
  background: #182335;
  box-shadow: 0 16px 38px rgba(17, 26, 40, .22);
}

.confirm-backdrop {
  background: rgba(17, 26, 40, .56);
}

.confirm-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
}

.login {
  padding: 20px;
  background:
    linear-gradient(90deg, rgba(36, 95, 197, .05) 1px, transparent 1px),
    linear-gradient(rgba(36, 95, 197, .05) 1px, transparent 1px),
    #edf1f5;
  background-size: 40px 40px;
}

.login-card {
  width: min(410px, 100%);
  padding: 30px;
  border: 1px solid #cbd3dd;
  border-radius: var(--radius-panel);
  box-shadow: 0 22px 58px rgba(23, 34, 51, .14);
}

.login-logo {
  border-radius: 5px;
  background: var(--accent);
}

/* Motion is feedback only. */

.motion-panel-enter {
  animation: vl-panel-enter .18s ease-out both;
}

.motion-popover {
  animation: vl-popover-enter .14s ease-out both;
}

@keyframes vl-panel-enter {
  from { opacity: .65; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

@keyframes vl-popover-enter {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Responsive shell and dense surfaces */

@media (max-width: 1180px) {
  .operations-dashboard,
  .trip-workspace {
    grid-template-columns: 1fr;
  }

  .trip-inspector {
    position: static;
    max-height: none;
  }
}

@media (max-width: 900px) {
  #appShell,
  #appShell.nav-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 58px minmax(0, 1fr) 66px;
  }

  #brand,
  #appShell.nav-collapsed #brand {
    grid-column: 1;
    grid-row: 1;
    justify-content: flex-start;
    width: 74px;
    padding: 0 14px;
    background: var(--surface-raised);
    z-index: 1002;
  }

  .brand-mark {
    background: var(--accent);
    color: #fff;
  }

  .brand-copy,
  #appShell.nav-collapsed .brand-copy,
  .nav-collapse,
  .global-search,
  #who {
    display: none;
  }

  .topbar {
    grid-column: 1;
    grid-row: 1;
    justify-content: flex-end;
    padding: 0 10px 0 76px;
    background: var(--surface-raised);
  }

  .workspace-mode {
    margin-left: auto;
  }

  #orgSwitch {
    width: min(168px, 44vw);
    min-width: 0;
  }

  #workspace {
    grid-column: 1;
    grid-row: 2;
  }

  #nav,
  #appShell.nav-collapsed #nav {
    grid-column: 1;
    grid-row: 3;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
    padding: 5px 7px calc(5px + env(safe-area-inset-bottom));
    border-top: 1px solid #26374f;
    background: var(--sidebar);
    overflow: visible;
    z-index: 3000;
  }

  #nav .tab[data-mobile-primary],
  #nav #mobileMoreBtn,
  #appShell.nav-collapsed #nav .tab[data-mobile-primary],
  #appShell.nav-collapsed #nav #mobileMoreBtn {
    display: flex;
    min-width: 0;
    min-height: 54px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    margin: 0;
    padding: 4px 2px;
    border: 0;
    border-radius: var(--radius-control);
    color: #aeb9c8;
    font-size: 10px;
  }

  #nav .tab.active,
  #nav #mobileMoreBtn[aria-expanded="true"] {
    background: #263d5e;
    color: #fff;
  }

  #nav .tab.active::before {
    display: none;
  }

  .mobile-more-menu {
    left: 8px;
    right: 8px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 8px;
    border-color: #cbd3dd;
    border-radius: var(--radius-panel);
    box-shadow: var(--shadow);
  }

  .mobile-more-menu button {
    min-height: 44px;
    background: var(--surface-subtle);
  }

  .panel,
  .panel:not(#panel-map) {
    padding: 20px 16px 32px;
  }

  .page-head {
    align-items: flex-start;
  }

  .page-title {
    font-size: 24px;
  }

  .page-actions {
    width: auto;
  }

  .toast-stack {
    left: 10px;
    right: 10px;
    bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .operations-dashboard > .surface {
    margin-bottom: 10px;
  }

  .activity-list {
    grid-template-columns: 1fr;
  }

  .activity-list .item:nth-child(odd) {
    border-right: 0;
  }
}

@media (max-width: 700px) {
  .page-head {
    display: grid;
    gap: 14px;
  }

  .page-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .page-actions > * {
    min-width: 0;
    padding-inline: 8px;
  }

  .page-actions > .pill:only-child {
    grid-column: 1 / -1;
  }

  .issues-strip {
    padding: 14px;
  }

  .issues-list {
    grid-template-columns: 1fr;
  }

  .issues-list > :nth-child(n + 4) {
    display: none;
  }

  .dispatcher-toolbar {
    grid-template-columns: 1fr 1fr 38px;
  }

  .dispatcher-toolbar .field:first-child {
    grid-column: 1 / -1;
  }

  .trip-board {
    grid-template-columns: 1fr;
  }

  .trip-column + .trip-column {
    margin-top: 14px;
    padding: 14px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .trip-column-body {
    max-height: none;
  }

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

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

  .fleet-kpis button:nth-child(odd) {
    border-right: 0;
  }

  .fleet-secondary {
    grid-template-columns: repeat(3, 1fr);
  }

  .fleet-secondary button {
    display: grid;
    grid-template-columns: 1fr;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .fleet-secondary button:last-child {
    border-right: 0;
  }

  .detail-tabs {
    top: -16px;
    overflow-x: auto;
  }
}

@media (max-width: 460px) {
  .topbar {
    gap: 5px;
  }

  .workspace-mode {
    width: 38px;
    padding: 0;
  }

  #orgSwitch {
    width: min(145px, 42vw);
  }

  .panel,
  .panel:not(#panel-map) {
    padding: 18px 12px 28px;
  }

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

  .page-actions .btn-primary:last-child:nth-child(3) {
    grid-column: 1 / -1;
  }

  .surface,
  .operations-dashboard > .surface,
  .trip-master,
  .trip-inspector {
    padding: 14px;
  }

  .attention-command,
  .fleet-command {
    min-height: 0;
  }

  .attention-count {
    min-width: 70px;
  }

  .issues-list > :nth-child(n + 3) {
    display: none;
  }

  .dispatcher-toolbar {
    grid-template-columns: 1fr 38px;
  }

  .dispatcher-toolbar .field {
    grid-column: 1 / -1;
  }

  .dispatcher-toolbar .btn-icon {
    grid-column: 2;
  }

  .metric-grid,
  .platform-metrics {
    gap: 1px;
  }

  .metric,
  .platform-metric {
    min-height: 96px;
    padding: 14px;
  }

  #panel-map .map-tools {
    top: 10px;
    right: 10px;
    width: calc(100vw - 20px) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
