:root {
  --bg: #f4f2eb;
  --ink: #1d1b19;
  --panel: #ffffff;
  --line: #d8d2c4;
  --primary: #9a3412;
  --primary-ink: #fff9f4;
  --secondary: #3f3f46;
  --muted: #6b7280;
  --radius: 14px;
  --site-header-height: 68px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
  background: linear-gradient(145deg, #f7f4ea 0%, #f1ece1 55%, #ebe4d7 100%);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.container {
  width: min(980px, 92vw);
  margin: 0 auto;
}

.site-header {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.global-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 100%;
  z-index: 2000;
  opacity: 0;
  background: linear-gradient(90deg, #fb923c 0%, #ea580c 45%, #fb923c 100%);
  transform-origin: 0 50%;
  transform: scaleX(0.08);
  transition: opacity 120ms ease;
}

.global-progress.is-active {
  opacity: 1;
  animation: global-progress-run 1.1s ease-in-out infinite;
}

@keyframes global-progress-run {
  0% {
    transform: scaleX(0.08);
    opacity: 0.8;
  }
  50% {
    transform: scaleX(0.62);
    opacity: 1;
  }
  100% {
    transform: scaleX(1);
    opacity: 0.95;
  }
}

.header-row {
  min-height: 64px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.header-top-row {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0.3px;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.nav-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.nav-toggle-btn {
  display: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--secondary);
  min-height: 44px;
  min-width: 72px;
  padding: 0 12px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.nav-links a,
.nav-logout-btn {
  text-decoration: none;
  color: var(--secondary);
  font-weight: 600;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  padding: 0 8px;
}

.nav-logout-form {
  margin: 0;
  padding: 0;
  display: contents;
}

.nav-logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
}

.page-content {
  padding: 28px 0 48px;
}

/* Keep consistent spacing between top-level page blocks/cards across all pages. */
.page-content > * + * {
  margin-top: 18px;
}

.page-content > .hero-card,
.page-content > .grid-2 {
  margin-bottom: 0;
}

.hero-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.hero-card {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-size: 12px;
}

h1,
h2 {
  margin-top: 0;
}

.hero-copy,
.muted {
  color: var(--muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8f6ef;
  color: var(--secondary);
  font-weight: 600;
  font-size: 13px;
}

.pill-muted {
  opacity: 0.7;
}

.btn {
  border: 0;
  border-radius: 9px;
  padding: 10px 14px;
  min-height: 44px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}

.btn.is-busy {
  opacity: 0.9;
  cursor: wait;
  gap: 8px;
}

.ui-spinner {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid rgba(154, 52, 18, 0.25);
  border-top-color: #9a3412;
  animation: spin 0.75s linear infinite;
  display: inline-block;
  flex: 0 0 auto;
}

.ui-spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-state {
  border: 1px dashed var(--line);
  border-radius: 12px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.75);
  padding: 18px;
}

.loading-state-label {
  font-weight: 600;
}

.loading-full-panel {
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
}

.loading-state-full {
  min-height: 260px;
}

.is-nav-loading {
  cursor: progress;
}

.auth-wrap {
  display: flex;
  justify-content: center;
}

.auth-panel {
  width: min(460px, 100%);
}

.form-stack {
  display: grid;
  gap: 10px;
}

.compact-form {
  margin-top: 10px;
}

label {
  font-weight: 600;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
}

.select-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  min-height: 44px;
  background: #fff;
}

input {
  min-height: 44px;
}

textarea {
  resize: vertical;
}

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

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

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

.form-fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin: 4px 0;
}

.form-fieldset legend {
  padding: 0 6px;
  color: var(--secondary);
  font-weight: 700;
}

.alert {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 10px;
  padding: 10px;
  margin: 10px 0 14px;
}

.alert-success {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}

.admin-section-head {
  margin-bottom: 10px;
}

.admin-section-head h2 {
  margin-bottom: 6px;
}

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

.rfq-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.rfq-table th,
.rfq-table td {
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  font-size: 14px;
}

.rfq-table th {
  color: var(--secondary);
  font-weight: 700;
  white-space: nowrap;
}

.rfq-table th.is-sortable {
  cursor: pointer;
  user-select: none;
}

.rfq-table th.is-sortable::after {
  content: " \2195";
  font-size: 11px;
  color: var(--muted);
}

.rfq-table th[data-sort="asc"]::after {
  content: " \2191";
  color: var(--primary);
}

.rfq-table th[data-sort="desc"]::after {
  content: " \2193";
  color: var(--primary);
}

.rfq-table tbody tr {
  cursor: pointer;
}

.rfq-table tbody tr.is-row-selected {
  background: #fff4e8;
}

.rfq-table tbody tr.is-rejected-row {
  background: #f9fafb;
  color: #6b7280;
}

.rfq-table tbody tr.is-retracted-row,
.rfq-table tbody tr.is-deleted-row {
  background: #f3f4f6;
  color: #6b7280;
}

.rfq-table tbody tr.is-import-error-row {
  background: #fef2f2;
}

.rfq-table tbody tr.is-temporary-highlight {
  animation: shipment-focus-pulse 2.6s ease-out 1;
  background: #fef3c7;
}

@keyframes shipment-focus-pulse {
  0% {
    background: #fde68a;
    box-shadow: inset 0 0 0 2px #f59e0b;
  }
  50% {
    background: #fef3c7;
    box-shadow: inset 0 0 0 2px #fbbf24;
  }
  100% {
    background: transparent;
    box-shadow: inset 0 0 0 0 transparent;
  }
}

.rfq-table .col-expanded-only {
  display: none;
}

.dashboard-data-panel.expanded .rfq-table .col-expanded-only {
  display: table-cell;
}

.bulk-actions {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffbf5;
  padding: 10px 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.at-a-glance-panel {
  background: linear-gradient(145deg, #fffaf1 0%, #fff7ed 100%);
}

.at-a-glance-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.at-a-glance-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 124px;
}

.at-a-glance-card-link {
  text-decoration: none;
  color: inherit;
}

.at-a-glance-card-link:hover {
  border-color: #f59e0b;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.15);
}

.at-a-glance-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--secondary);
}

.at-a-glance-value {
  font-size: 30px;
  line-height: 1;
  color: var(--primary);
}

.at-a-glance-hint {
  font-size: 12px;
  color: var(--muted);
}

/* =============================================
   Detail Modal Layout
   ============================================= */

.detail-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-route {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-city {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

.detail-arrow {
  font-size: 18px;
  color: var(--muted);
}

.detail-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-ok {
  background: #f0fdf4;
  border-color: #86efac;
  color: #166534;
}

.pill-status-submitted {
  background: #fef9c3;
  border-color: #facc15;
  color: #854d0e;
}

.pill-status-accepted {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.pill-status-cancelled {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.pill-status-rejected {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #374151;
}

.pill-status-retracted,
.pill-status-deleted {
  background: #e5e7eb;
  border-color: #cbd5e1;
  color: #334155;
}

.pill-status-done {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #374151;
}

.pill-shipment-active {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.pill-shipment-on-hold {
  background: #fef9c3;
  border-color: #facc15;
  color: #854d0e;
}

.pill-shipment-cancelled {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.pill-shipment-deleted {
  background: #e5e7eb;
  border-color: #cbd5e1;
  color: #334155;
}

.pill-shipment-done {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #374151;
}

.detail-kpi-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.detail-kpi {
  flex: 1 1 100px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.detail-kpi-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.detail-section-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.detail-section {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
}

.detail-section p {
  margin: 2px 0;
}

.detail-section-title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary);
}

.detail-loc-name {
  font-weight: 700;
}

.detail-contact {
  color: var(--muted);
  font-size: 13px;
}

.detail-label {
  font-weight: 600;
  color: var(--secondary);
  margin-right: 4px;
}

.detail-meta {
  font-size: 12px;
  color: var(--muted);
}

.detail-notes-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.detail-note-block {
  flex: 1 1 200px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
}

.detail-note-block p {
  margin: 4px 0 0;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.modal-card-detail {
  width: min(860px, 94vw);
}

.modal-card-bol {
  width: min(1100px, 96vw);
}

.bol-inline-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.bol-inline-frame {
  width: 100%;
  min-height: 72vh;
  border: 0;
  background: #fff;
}

.cal-event-inner {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 4px;
  overflow: hidden;
  pointer-events: none;  /* let clicks pass through to FullCalendar's wrapper */
}

.cal-event-time {
  font-size: 10px;
  font-weight: 700;
  opacity: 0.8;
  white-space: nowrap;
  pointer-events: none;
}

.cal-event-route {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.cal-event-bol {
  font-size: 10px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.is-ported-row {
  opacity: 0.55;
}

.row-action-wrap {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.row-action-wrap .btn {
  min-height: 32px;
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 600;
}

.row-action-wrap form {
  margin: 0;
}

.inline-notes-editor {
  width: 100%;
  min-height: 62px;
  font-size: 16px;
  padding: 8px 10px;
  border-radius: 8px;
}

.inline-notes-status {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--muted);
  min-height: 14px;
}

.inline-notes-status.is-saving {
  color: #92400e;
}

.inline-notes-status.is-saved {
  color: #166534;
}

.inline-notes-status.is-error {
  color: #991b1b;
}

.btn-big {
  font-size: 15px;
  padding: 12px 16px;
}

.new-customer-wrap.hidden {
  display: none;
}

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

.table-grouping-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.table-export-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.import-staged-table-scroll {
  max-height: min(62vh, 680px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.import-staged-table-scroll .rfq-table-wrap {
  max-height: 100%;
}

.import-staged-table-scroll .rfq-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
}

.table-grouping-controls .btn.is-active {
  background: var(--primary);
  color: var(--primary-ink);
}

.table-group-row td {
  background: #f8f5ee;
  color: var(--secondary);
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  padding: 8px 8px;
}

.panel-view.hidden {
  display: none;
}

.hidden {
  display: none;
}

.calendar-host {
  min-height: 520px;
}

.dashboard-data-panel.expanded {
  position: fixed;
  top: calc(var(--site-header-height, 68px) + 8px);
  left: 8px;
  right: 8px;
  bottom: 8px;
  margin: 0;
  z-index: 90;
  overflow: auto;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
}

/* Dashboard preview: keep shipments panel a fixed-height viewport with inner scroll. */
#shipment-panel {
  height: min(76vh, 840px);
  display: flex;
  flex-direction: column;
}

#shipment-panel .panel-view {
  flex: 1 1 auto;
  min-height: 0;
}

#shipment-panel .panel-view-table {
  overflow: auto;
  padding-right: 2px;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.checkbox-line input {
  width: auto;
  min-height: auto;
}

.modal-shell {
  position: fixed;
  inset: var(--site-header-height, 68px) 0 0 0;
  z-index: 1200;
  display: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-shell.is-open {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-card {
  position: relative;
  margin: max(80px, 5vh) auto 4vh;
  width: min(940px, 94vw);
  max-height: calc(100dvh - var(--site-header-height, 68px) - max(80px, 5vh) - 4vh);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

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

.modal-head h3 {
  margin: 0;
}

.modal-close-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-height: 36px;
  padding: 5px 11px;
  cursor: pointer;
}

@media (max-width: 760px) {
  .header-row {
    gap: 6px;
    padding: 8px 0;
  }

  .header-top-row {
    min-height: 52px;
  }

  .brand {
    padding: 8px 0;
  }

  .nav-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(6px);
  }

  .nav-links[data-mobile-open="true"] {
    display: flex;
  }

  .nav-links a,
  .nav-logout-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 10px 12px;
    font-size: 14px;
    border-radius: 8px;
  }

  .nav-links a:active,
  .nav-logout-btn:active {
    background: #f3f4f6;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .page-content {
    padding: 16px 0 32px;
  }

  .btn {
    width: 100%;
    padding: 12px 14px;
    font-size: 14px;
  }

  .button-row {
    flex-direction: column;
  }

  .row-action-wrap {
    flex-direction: column;
  }

  label {
    font-size: 15px;
  }

  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }

  .form-fieldset {
    padding: 10px;
  }

  textarea {
    min-height: 120px;
  }

  .table-panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .table-grouping-controls {
    flex-direction: column;
  }

  .import-staged-table-scroll {
    max-height: 56vh;
  }

  .at-a-glance-grid {
    grid-template-columns: 1fr;
  }

  .row-action-wrap .btn {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 14px;
  }

  input,
  textarea,
  .select-input {
    min-width: 0;
  }

  .inline-notes-editor {
    min-height: 80px;
  }

  .calendar-host {
    min-height: 420px;
  }

  .dashboard-data-panel.expanded {
    top: var(--site-header-height, 126px);
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0;
  }

  .modal-card {
    margin: 0;
    width: 100vw;
    max-height: calc(100dvh - var(--site-header-height, 126px));
    min-height: calc(100dvh - var(--site-header-height, 126px));
    border-radius: 0;
    padding-top: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .modal-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel);
    padding-top: 4px;
    padding-bottom: 6px;
  }

  .modal-close-btn {
    min-height: 44px;
  }

  .modal-card .form-stack {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .modal-card .form-stack > button[type="submit"].btn {
    position: sticky;
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 2;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.14);
  }
}
