/* =====================================================================
   SACS Freight OS — Layout Styles
   Version: 1.0
   Purpose: Topnav, sidebar, main panel, responsive grid
   ===================================================================== */

/* ------------------------------------------------------------------
   TOP NAVIGATION
   ------------------------------------------------------------------ */

.sacs-topnav {
  height: 58px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: stretch;
  padding: 0 18px;
  gap: 0;
  flex-shrink: 0;
  position: relative;
  z-index: var(--z-sticky);
}

.sacs-logo-area {
  display: flex;
  align-items: center;
  gap: 11px;
  padding-right: 22px;
  border-right: 1px solid var(--border-subtle);
  margin-right: 6px;
  flex-shrink: 0;
}

.sacs-logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent-blue-dark), #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  box-shadow: 0 2px 10px rgba(59,126,240,0.25);
}

.sacs-logo-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--text-primary);
  line-height: 1;
}

.sacs-logo-sub {
  font-size: var(--text-micro);
  color: var(--text-tertiary);
  font-weight: 500;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* Section buttons */
.sacs-secbtn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-caption);
  font-weight: 600;
  padding: 0 18px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-tertiary);
  border-bottom: 2px solid transparent;
  transition: all var(--duration-fast) var(--ease-default);
  letter-spacing: 0.2px;
}

.sacs-secbtn:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.03);
}

.sacs-secbtn--active-ff {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

.sacs-secbtn--active-cc {
  color: var(--accent-teal);
  border-bottom-color: var(--accent-teal);
}

.sacs-secbtn--active-sync {
  color: var(--accent-amber);
  border-bottom-color: var(--accent-amber);
}

.sacs-secbtn--active-finance {
  color: var(--accent-green);
  border-bottom-color: var(--accent-green);
}

.sacs-secbtn--active-overview {
  color: var(--accent-purple);
  border-bottom-color: var(--accent-purple);
}

/* Nav right area */
.sacs-nav-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sacs-nav-spacer {
  flex: 1;
}

/* Stats box */
.sacs-statbox {
  display: flex;
  align-items: stretch;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  overflow: hidden;
}

.sacs-statbox__cell {
  text-align: center;
  padding: 4px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border-subtle);
}

.sacs-statbox__cell:last-child {
  border-right: none;
}

.sacs-statbox__num {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.sacs-statbox__lbl {
  font-size: var(--text-micro);
  font-weight: 700;
  color: var(--text-tertiary);
  letter-spacing: 0.8px;
  margin-top: 1px;
}

/* Connection dot */
.sacs-conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: all var(--duration-normal) var(--ease-default);
}

.sacs-conn-dot--connecting {
  background: var(--accent-amber);
  animation: sacs-pulse 1.5s infinite;
}

.sacs-conn-dot--connected {
  background: var(--accent-green);
}

.sacs-conn-dot--disconnected {
  background: var(--accent-red);
}

.sacs-conn-label {
  font-size: var(--text-micro);
  font-weight: 700;
}

/* ------------------------------------------------------------------
   ALERT STRIP
   ------------------------------------------------------------------ */

.sacs-alert-strip {
  display: none;
  background: linear-gradient(90deg, #200606, #1a0808);
  border-bottom: 1px solid #4a1010;
  padding: 7px 20px;
  gap: 8px;
  overflow-x: auto;
  flex-shrink: 0;
  align-items: center;
}

.sacs-alert-strip--visible {
  display: flex;
}

.sacs-alert-chip {
  font-size: var(--text-caption);
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: filter var(--duration-fast) var(--ease-default);
}

.sacs-alert-chip:hover {
  filter: brightness(1.2);
}

/* ------------------------------------------------------------------
   MAIN LAYOUT
   ------------------------------------------------------------------ */

.sacs-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ------------------------------------------------------------------
   SIDEBAR
   ------------------------------------------------------------------ */

.sacs-sidebar {
  width: 300px;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.sacs-sidebar__top {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Search */
.sacs-search-wrap {
  position: relative;
}

.sacs-search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1.5px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 8px 12px 8px 34px;
  border-radius: var(--radius-md);
  font-size: var(--text-caption);
  transition: border-color var(--duration-fast) var(--ease-default);
}

.sacs-search-input:focus {
  border-color: var(--accent-blue);
}

.sacs-search-input::placeholder {
  color: var(--text-tertiary);
}

.sacs-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 14px;
  pointer-events: none;
}

/* Filter pills */
.sacs-filter-pills {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.sacs-pill-btn {
  font-size: var(--text-caption);
  font-weight: 600;
  padding: 4px 11px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-subtle);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  letter-spacing: 0.2px;
}

.sacs-pill-btn:hover {
  color: var(--text-secondary);
  border-color: var(--border-medium);
}

.sacs-pill-btn--active {
  border-color: var(--accent-blue);
  background: var(--bg-blue);
  color: var(--accent-blue);
}

.sacs-pill-btn--active-teal {
  border-color: var(--accent-teal);
  background: var(--bg-teal);
  color: var(--accent-teal);
}

/* Sidebar label */
.sacs-sidebar__label {
  padding: 10px 14px 7px;
  font-size: var(--text-micro);
  font-weight: 700;
  color: var(--text-tertiary);
  letter-spacing: 1px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-subtle);
}

.sacs-sidebar__list {
  overflow-y: auto;
  flex: 1;
}

/* ------------------------------------------------------------------
   SHIPMENT CARD (Sidebar)
   ------------------------------------------------------------------ */

.sacs-scard {
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default);
  border-bottom: 1px solid var(--border-subtle);
  padding: 13px 14px;
  border-left: 3px solid transparent;
}

.sacs-scard:hover {
  background: var(--bg-card);
}

.sacs-scard--selected {
  background: var(--bg-card);
  border-left-color: var(--accent-blue);
}

.sacs-scard--selected-teal {
  background: var(--bg-card);
  border-left-color: var(--accent-teal);
}

.sacs-scard--alert {
  border-left-color: var(--accent-red);
}

.sacs-scard__id {
  font-size: var(--text-caption);
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 2px;
}

.sacs-scard__cnee {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 4px;
}

.sacs-scard__meta {
  font-size: var(--text-caption);
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.sacs-scard__progress {
  height: 3px;
  background: var(--bg-active);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

.sacs-scard__progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}

.sacs-scard__stage {
  font-size: var(--text-caption);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Health score badge on card */
.sacs-scard__health {
  position: absolute;
  top: 10px;
  right: 10px;
}

/* ------------------------------------------------------------------
   MAIN PANEL
   ------------------------------------------------------------------ */

.sacs-main {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-base);
}

/* ------------------------------------------------------------------
   SHIPMENT DETAIL
   ------------------------------------------------------------------ */

.sacs-detail {
  padding: 24px 28px;
  animation: sacs-fadein var(--duration-normal) var(--ease-default);
}

.sacs-detail__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 22px;
  gap: 16px;
  flex-wrap: wrap;
}

.sacs-detail__id {
  font-size: var(--text-h1);
  font-weight: var(--text-h1-weight);
  letter-spacing: 1px;
  line-height: 1;
  margin-bottom: 5px;
}

.sacs-detail__cnee {
  font-size: var(--text-h2);
  font-weight: var(--text-h2-weight);
  color: var(--text-primary);
  margin-bottom: 4px;
}

.sacs-detail__comm {
  font-size: var(--text-caption);
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.sacs-detail__route {
  font-size: var(--text-caption);
  font-weight: 600;
}

.sacs-detail__actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ETA Box */
.sacs-eta-box {
  text-align: center;
  padding: 10px 18px;
  border: 1.5px solid var(--border-medium);
  border-radius: var(--radius-lg);
  min-width: 76px;
}

.sacs-eta-box__num {
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.sacs-eta-box__lbl {
  font-size: var(--text-micro);
  font-weight: 700;
  color: var(--text-tertiary);
  letter-spacing: 0.8px;
  margin-top: 2px;
}

/* ------------------------------------------------------------------
   REFERENCE CARD (Shipment Info)
   ------------------------------------------------------------------ */

.sacs-ref-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  margin-bottom: 20px;
  overflow: hidden;
}

.sacs-ref-card__header {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.sacs-ref-card__body {
  padding: 16px 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.sacs-ref-field__label {
  font-size: var(--text-label);
  font-weight: var(--text-label-weight);
  letter-spacing: var(--text-label-ls);
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 5px;
}

.sacs-ref-field__value {
  background: var(--bg-card);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 9px 13px;
  cursor: pointer;
  min-height: 42px;
  display: flex;
  align-items: center;
  transition: border-color var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default);
}

.sacs-ref-field__value:hover {
  border-color: var(--accent-blue);
  background: var(--bg-hover);
}

.sacs-ref-field__text {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--text-primary);
}

.sacs-ref-field__placeholder {
  font-size: var(--text-body);
  color: var(--text-tertiary);
  font-style: italic;
}

.sacs-ref-status {
  font-size: var(--text-caption);
  font-weight: 600;
  margin-top: 4px;
}

/* ------------------------------------------------------------------
   GMAIL PANEL
   ------------------------------------------------------------------ */

.sacs-gmail-panel {
  position: fixed;
  top: 58px;
  right: 0;
  bottom: 0;
  width: 420px;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-subtle);
  z-index: var(--z-panel);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--duration-slow) var(--ease-out);
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}

.sacs-gmail-panel--open {
  transform: translateX(0);
}

.sacs-gmail-panel__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.sacs-gmail-panel__title {
  font-size: var(--text-h3);
  font-weight: var(--text-h3-weight);
}

.sacs-gmail-panel__status {
  font-size: var(--text-caption);
  color: var(--text-tertiary);
  margin-top: 1px;
}

.sacs-email-card {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default);
}

.sacs-email-card:hover {
  background: var(--bg-card);
}

/* ------------------------------------------------------------------
   DOCUMENT VIEWER PANEL
   ------------------------------------------------------------------ */

.sacs-docviewer {
  display: none;
  position: fixed;
  top: 58px;
  right: 0;
  bottom: 0;
  width: 50%;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-subtle);
  z-index: var(--z-panel);
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}

.sacs-docviewer--open {
  display: flex;
}

.sacs-docviewer iframe {
  flex: 1;
  width: 100%;
  border: none;
  min-height: 0;
}

/* ------------------------------------------------------------------
   SAVING INDICATOR
   ------------------------------------------------------------------ */

.sacs-saving {
  font-size: var(--text-caption);
  color: var(--text-tertiary);
  display: none;
  align-items: center;
  gap: 5px;
}

.sacs-saving--visible {
  display: flex;
}

/* ------------------------------------------------------------------
   OVERVIEW / DASHBOARD COMPONENTS
   ------------------------------------------------------------------ */

.sacs-kpi {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sacs-kpi__num {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
}

.sacs-kpi__lbl {
  font-size: var(--text-micro);
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  text-transform: uppercase;
}

.sacs-kpi__bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}

.sacs-kpi__bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.sacs-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
  margin-bottom: 16px;
}

.sacs-section__header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sacs-section__body {
  padding: 16px 18px;
}

.sacs-stat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.sacs-stat-row:last-child {
  margin-bottom: 0;
}

.sacs-stat-row__label {
  width: 100px;
  font-size: var(--text-caption);
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.sacs-stat-row__bar {
  flex: 1;
  height: 8px;
  background: var(--bg-hover);
  border-radius: 4px;
  overflow: hidden;
}

.sacs-stat-row__bar-fill {
  height: 100%;
  border-radius: 4px;
}

.sacs-stat-row__value {
  width: 32px;
  text-align: right;
  font-size: var(--text-caption);
  font-weight: 700;
  flex-shrink: 0;
}

/* ------------------------------------------------------------------
   SYNC QUEUE COMPONENTS
   ------------------------------------------------------------------ */

.sacs-sync-card {
  animation: sacs-fadein var(--duration-normal) var(--ease-default);
}

.sacs-sync-state {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.sacs-sync-state--error {
  border-color: #5a1010;
  background: linear-gradient(90deg, #1c0404, #140606);
}

.sacs-sync-state--warn {
  border-color: #6b4b12;
  background: linear-gradient(90deg, #1c1200, #151004);
}

/* ------------------------------------------------------------------
   RESPONSIVE
   ------------------------------------------------------------------ */

@media (max-width: 980px) {
  html, body {
    overflow: auto;
  }

  .sacs-layout {
    flex-direction: column;
  }

  .sacs-sidebar {
    width: 100%;
    max-height: 42vh;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .sacs-main {
    min-height: 58vh;
  }

  .sacs-detail__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .sacs-detail__actions {
    justify-content: flex-start;
  }

  .sacs-ref-card__body,
  .sacs-info-grid {
    grid-template-columns: 1fr;
  }

  .sacs-gmail-panel,
  .sacs-docviewer {
    width: 100%;
  }
}
