:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #16a34a;
  --accent-soft: #dcfce7;
  --brand-orange: #ff6b35;
  --brand-orange-deep: #e85a24;
  --brand-green: #22c55e;
  --shadow: 0 8px 32px rgba(15, 23, 42, 0.08);
  --sidebar-width: 360px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  background: var(--bg);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }

.dashboard-layout {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.dashboard-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-content {
  flex: 1 1 auto;
  padding: 0 24px 24px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.app-header-left,
.app-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-lockup { display: inline-flex; align-items: center; }
.brand-logo {
  width: min(180px, 36vw);
  height: auto;
  display: block;
}

.live-sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: #f3f4f6;
}

.live-sync-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
}

.live-sync-badge.connected {
  color: #15803d;
  background: var(--accent-soft);
}

.live-sync-badge.connected::before {
  background: var(--brand-green);
}

.live-sync-badge.error {
  color: #b91c1c;
  background: #fee2e2;
}

.live-sync-badge.error::before {
  background: #ef4444;
}

.period-toggle {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fafb;
}

.period-toggle-btn {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  background: transparent;
}

.period-toggle-btn.active {
  color: var(--brand-orange-deep);
  background: #fff1eb;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  background: var(--panel);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--brand-orange);
}

.user-profile-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.user-profile-copy strong {
  font-size: 14px;
  line-height: 1.2;
}

.user-profile-copy span {
  font-size: 12px;
  color: var(--muted);
}

/* Tabs */
.view-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-bottom: 0;
  border-bottom: 1px solid var(--line);
}

.view-tabs {
  display: inline-flex;
  gap: 28px;
}

.view-tab {
  position: relative;
  border: none;
  padding: 12px 0 14px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  background: transparent;
}

.view-tab.active {
  color: var(--brand-orange);
}

.view-tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--brand-orange);
}

.view-tabs-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-bottom: 10px;
}

.view-panel { display: none; }
.view-panel.active { display: block; }

.eyebrow, .stat-label, .meta-label, .table-meta, .field span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.table-header h3, .stat-card h2, .dialog-head h3, .summary-card h2 { margin: 0; }

/* Trip filters */
.trip-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-field span {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  text-transform: none;
  letter-spacing: normal;
}

.filter-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.filter-input-wrap input,
.filter-input-wrap select,
.filter-input-with-icon {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  appearance: none;
}

.filter-input-with-icon {
  padding-left: 40px;
}

.filter-input-icon {
  position: absolute;
  right: 12px;
  width: 18px;
  height: 18px;
  color: #9ca3af;
  pointer-events: none;
}

.filter-input-icon-left {
  left: 12px;
  right: auto;
}

/* Trip summary cards */
.trip-summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.summary-card {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.summary-label {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  letter-spacing: normal;
}

.summary-card h2 {
  margin-top: 8px;
  font-size: clamp(22px, 2.5vw, 30px);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.summary-card h2.summary-plate {
  font-size: clamp(16px, 1.8vw, 20px);
  font-family: "IBM Plex Mono", monospace;
}

.summary-trend,
.summary-sub {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
  text-transform: none;
  letter-spacing: normal;
}

.summary-trend.trend-up { color: #16a34a; }
.summary-trend.trend-down { color: #dc2626; }

/* Capture dashboard (Figma) */
.capture-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.filter-input-with-icon-both {
  padding-left: 40px !important;
  padding-right: 36px !important;
}

.filter-select {
  width: 100%;
  min-width: 0;
  padding: 12px 36px 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  appearance: none;
}

.filter-input-chevron {
  right: 12px;
  pointer-events: none;
}

.capture-summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.capture-summary-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border: 1px solid #f3d4c8;
  border-radius: 14px;
  background: #fff6f2;
}

.capture-summary-label {
  font-size: 14px;
  font-weight: 600;
  color: #6b7c93;
}

.capture-summary-value {
  font-size: 14px;
  font-weight: 600;
  color: #334155;
  white-space: nowrap;
}

.capture-summary-value strong {
  font-size: 18px;
  font-weight: 700;
  color: #1a1a1a;
}

.capture-type-section {
  margin-top: 18px;
}

.capture-table-card {
  margin-top: 20px;
}

.type-breakdown-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.type-tile {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}

.type-tile h4 {
  margin: 6px 0 12px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: #1a1a1a;
}

.type-label {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #6b7c93;
  text-transform: none;
  letter-spacing: normal;
}

.type-meta {
  margin: 10px 0 0;
  font-size: 12px;
  color: #8a94a6;
  text-transform: none;
  letter-spacing: normal;
}

.type-meter {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #ffe8dc;
}

.type-meter span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: #ff6b35;
}

.empty-type-tile {
  grid-column: 1 / -1;
  color: var(--muted);
  text-align: center;
  background: #fafafa;
}

/* Capture view stats */
.stats-grid, .trip-summary-grid.capture-stats {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

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

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

.stat-card {
  padding: 18px 20px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.stat-card h2 {
  margin-top: 10px;
  font-size: clamp(24px, 3vw, 36px);
}

.table-card { margin-top: 20px; overflow: hidden; }

.table-wrap { overflow-x: auto; }

.toolbar-group, .toolbar-actions, .pagination-controls, .dialog-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field input, .field select, .refresh-button, .secondary-button, .dialog-close {
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
}

.field input, .field select {
  min-width: 200px;
  padding: 12px 14px;
  background: var(--panel);
}

.refresh-button, .secondary-button, .dialog-close {
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}

.refresh-button, .dialog-close {
  color: white;
  border-color: transparent;
  background: var(--brand-orange);
}

.secondary-button {
  color: var(--ink);
  background: var(--panel);
}

.secondary-button:disabled,
.page-nav-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.table-header, .dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.table-header { padding: 18px 20px 10px; }

.trip-table-header h3 {
  font-size: 18px;
  font-weight: 700;
}

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: #fafafa;
}

td { font-size: 14px; }

.trip-table tbody tr:hover { background: #fafafa; }

.customer-cell strong {
  display: block;
  font-weight: 600;
}

.customer-cell span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.confidence-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 120px;
}

.confidence-value {
  width: 28px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.confidence-bar {
  flex: 1 1 auto;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #e5e7eb;
}

.confidence-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.confidence-fill.high { background: #22c55e; }
.confidence-fill.medium { background: #f59e0b; }
.confidence-fill.low { background: #ef4444; }

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
}

.trip-pagination .table-meta {
  text-transform: none;
  letter-spacing: normal;
  font-size: 13px;
}

.trip-pagination-controls {
  align-items: center;
}

.trip-page-size {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  background: var(--panel);
}

.page-nav-btn,
.page-num-btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  background: var(--panel);
}

.page-num-btn.active {
  color: #fff;
  border-color: var(--brand-orange);
  background: var(--brand-orange);
}

.pagination-pages {
  display: inline-flex;
  gap: 6px;
}

.mono { font-family: "IBM Plex Mono", monospace; }
.verified-cell { font-weight: 700; color: #14583d; }
.remarks-cell { min-width: 280px; color: var(--muted); line-height: 1.45; }
.empty-state { padding: 34px 16px; color: var(--muted); text-align: center; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
  font-size: 12px;
  font-weight: 700;
}

.thumb-button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
}

/* Chat sidebar */
.chat-sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
}

.chat-sidebar.collapsed {
  display: none;
}

.chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  color: white;
  cursor: pointer;
  background: var(--brand-orange);
  box-shadow: 0 12px 32px rgba(255, 107, 53, 0.35);
}

.chat-launcher.visible { display: inline-flex; }

.chat-launcher-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
}

.chat-launcher-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid #ececee;
  background: #ffffff;
  flex-shrink: 0;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-header-icon {
  display: inline-flex;
  width: 22px;
  height: 22px;
  color: #171717;
}

.chat-header-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.chat-header-title h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.chat-close-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  color: #6b6b6f;
  cursor: pointer;
  background: transparent;
}

.chat-close-button svg {
  width: 18px;
  height: 18px;
}

.chat-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.chat-welcome.hidden { display: none; }

.chat-welcome-card {
  padding: 20px 18px;
  border-radius: 18px;
  background: #f7f7f8;
}

.chat-welcome-greeting {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
}

.chat-welcome-hint {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: #6b6b6f;
}

.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.chat-chip {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #e2e2e5;
  border-radius: 999px;
  background: #ffffff;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages:empty { display: none; }

.chat-message {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.45;
}

.chat-message.user {
  align-self: flex-end;
  background: #fff1e8;
  border: 1px solid #ffd9c4;
}

.chat-message.assistant {
  align-self: flex-start;
  background: #f7f7f8;
  border: 1px solid #ececee;
}

.chat-message-label {
  margin: 0 0 4px;
  color: #8a8a8f;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.chat-message-body {
  margin: 0;
  white-space: pre-wrap;
  font-size: 14px;
}

.chat-form {
  flex-shrink: 0;
  padding: 14px 16px 16px;
  border-top: 1px solid #ececee;
}

.chat-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 16px;
  border: 1px solid #e2e2e5;
  border-radius: 999px;
}

.chat-input-wrap input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  padding: 8px 0;
  font: inherit;
  font-size: 14px;
  outline: none;
  background: transparent;
}

.chat-send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  background: #ff5722;
}

.chat-send-button svg {
  width: 18px;
  height: 18px;
}

.image-dialog {
  width: min(900px, calc(100% - 24px));
  border: none;
  border-radius: 20px;
  padding: 0;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
}

.image-dialog::backdrop {
  background: rgba(16, 15, 10, 0.5);
  backdrop-filter: blur(4px);
}

.dialog-head { padding: 18px 20px; border-bottom: 1px solid var(--line); }

.dialog-image-wrap {
  overflow: auto;
  max-height: 75vh;
  background: #f5f6f8;
}

.image-dialog img {
  display: block;
  width: 100%;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 0.12s ease-out;
}

@media (max-width: 1200px) {
  .trip-summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .type-breakdown-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .user-profile-copy { display: none; }
}

@media (max-width: 1024px) {
  .dashboard-layout { flex-direction: column; }

  .chat-sidebar {
    position: fixed;
    right: 16px;
    bottom: 88px;
    z-index: 19;
    width: min(400px, calc(100vw - 32px));
    max-height: min(640px, calc(100vh - 110px));
    height: auto;
    border: 1px solid #e8e8ea;
    border-radius: 20px;
    box-shadow: 0 24px 64px rgba(23, 23, 23, 0.12);
  }

  .chat-sidebar.collapsed { display: none; }
  .chat-launcher.visible { display: inline-flex; }
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .capture-summary-strip { grid-template-columns: 1fr; }
  .capture-filters { grid-template-columns: 1fr 1fr; }
  .trip-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trip-filters { grid-template-columns: 1fr; }
  .type-breakdown-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-header { flex-wrap: wrap; }
  .view-tabs-bar { flex-direction: column; align-items: stretch; }
  .view-tabs-actions { padding-bottom: 0; }
}

@media (max-width: 640px) {
  .app-content { padding: 0 12px 16px; }
  .app-header { padding: 12px; }
  .period-toggle { display: none; }
  .stats-grid, .trip-summary-grid, .capture-summary-strip { grid-template-columns: 1fr; }
  .capture-filters { grid-template-columns: 1fr; }
  .type-breakdown-grid { grid-template-columns: 1fr; }
  .field input, .field select { min-width: 100%; width: 100%; }
  .chat-launcher { right: 12px; bottom: 12px; }
  .chat-sidebar {
    right: 10px;
    left: 10px;
    width: auto;
  }
  .trip-pagination { flex-direction: column; align-items: flex-start; }
}
