/* ==========================================================================
   MCI Portal — App layout (post-login)
   White sidebar + light page bg theme. Used by /dashboard, /orders,
   /order/:ref, /wallet, /profile, /settings.
   Source: Figma node 299-34377.
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  background: var(--blue-b10);
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 64px 1fr; }
}

/* ---- Sidebar ------------------------------------------------------------- */
.app-sidebar {
  background: var(--white);
  border-right: 1px solid var(--blue-b30);
  padding: 28px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.app-sidebar-brand {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  margin: 0 4px 36px;
  text-decoration: none;
  align-self: flex-start;
}
.app-sidebar-brand img { height: 36px; width: auto; display: block; }

.nav-section-label {
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--blue-b80);
  padding: 16px 12px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-700);
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-link:hover {
  background: var(--blue-b10);
  color: var(--blue-darker);
  text-decoration: none;
}
.nav-link.is-active {
  background: var(--blue-b30);
  color: var(--blue-darker);
  font-weight: 600;
}
.nav-link svg {
  flex-shrink: 0;
  color: var(--gray-500);
  transition: color 0.12s ease;
}
.nav-link:hover svg,
.nav-link.is-active svg { color: var(--blue-normal); }

.app-sidebar-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--blue-b30);
}
.app-sidebar-foot .nav-link { color: var(--gray-700); }
.app-sidebar-foot .nav-link svg { color: var(--gray-500); }

@media (max-width: 900px) {
  .app-sidebar {
    flex-direction: row;
    height: 64px;
    padding: 12px 16px;
    gap: 4px;
    overflow-x: auto;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--blue-b30);
  }
  .app-sidebar-brand { margin: 0 8px 0 0; }
  .app-sidebar-brand img { height: 28px; }
  .nav-section-label { display: none; }
  .nav-link { padding: 8px 12px; white-space: nowrap; }
  .app-sidebar-foot { display: none; }
}

/* ---- Main ---------------------------------------------------------------- */
.app-main {
  padding: 0 40px 40px;
  max-width: 100%;
  overflow-x: hidden;
}
@media (max-width: 900px) { .app-main { padding: 0 20px 24px; } }

/* ---- Top bar ------------------------------------------------------------- */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0 32px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--blue-b10);
}

.app-search {
  flex: 1;
  max-width: 400px;
  position: relative;
}
.app-search svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-500);
  pointer-events: none;
}
.app-search input {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 40px;
  border: 1px solid var(--blue-b30);
  border-radius: 999px;
  background: var(--white);
  color: var(--blue-darker);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.app-search input::placeholder { color: var(--gray-500); }
.app-search input:focus {
  outline: none;
  border-color: var(--blue-normal);
  box-shadow: 0 0 0 3px rgba(0, 53, 102, 0.08);
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 4px 4px;
  background: var(--white);
  border: 1px solid var(--blue-b30);
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.user-pill:hover {
  border-color: var(--blue-normal);
  box-shadow: var(--shadow-xs);
  text-decoration: none;
}
.user-pill-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-normal), var(--blue-darker));
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 600;
  position: relative;
  font-family: var(--font-heading);
}
.user-pill-avatar::after {
  content: "";
  position: absolute;
  bottom: 0; right: 0;
  width: 10px; height: 10px;
  background: var(--color-success);
  border: 2px solid var(--white);
  border-radius: 50%;
}
.user-pill-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-pill-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--blue-darker);
}
.user-pill-role {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 2px;
}
.user-pill-caret {
  color: var(--gray-500);
  margin-left: 4px;
}

@media (max-width: 720px) {
  .app-search { max-width: 100%; }
  .user-pill-meta { display: none; }
}

/* ---- Page heading (below topbar) ---------------------------------------- */
.app-page-head {
  margin-bottom: 24px;
}
.app-page-head h1 {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: 600;
  color: var(--blue-darker);
  margin: 0;
  letter-spacing: -0.02em;
}
.app-page-head .sub {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin: 6px 0 0;
  max-width: 600px;
}
.app-page-head .actions {
  margin-top: 16px;
  display: flex;
  gap: 12px;
}

/* ---- KPI cards ----------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 1024px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px)  { .kpi-grid { grid-template-columns: 1fr; } }

.kpi {
  background: var(--white);
  border: 1px solid var(--blue-b30);
  border-radius: var(--radius-md);
  padding: 18px 20px;
}
.kpi-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-500);
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-value {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 28px;
  color: var(--blue-darker);
  margin-top: 8px;
  letter-spacing: -0.02em;
}
.kpi-sub {
  font-size: var(--text-xs);
  color: var(--gray-500);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-trend-up   { color: var(--color-success); font-weight: 600; }
.kpi-trend-down { color: var(--color-error);   font-weight: 600; }

/* ---- Card / Panel -------------------------------------------------------- */
.card {
  background: var(--white);
  border: 1px solid var(--blue-b30);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--blue-b30);
  gap: 16px;
}
.card-head h2 {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--blue-darker);
  margin: 0;
}
.card-body { padding: 20px 24px; }
.card-body.tight { padding: 0; }

/* ---- Table --------------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table thead th {
  text-align: left;
  padding: 14px 24px;
  background: var(--blue-b10);
  font-weight: 500;
  font-size: var(--text-xs);
  color: var(--gray-500);
  border-bottom: 1px solid var(--blue-b30);
}
.table tbody td {
  padding: 16px 24px;
  border-bottom: 1px solid var(--blue-b20);
  color: var(--blue-darker);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--blue-b10); cursor: pointer; }

/* ---- Quote split-dropdown (Buying vs Trucking & shipping) ---------------- */
.quote-dd { position: relative; display: inline-block; }
.quote-dd-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 230px;
  background: var(--white);
  border: 1px solid var(--blue-b30);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.12);
  padding: 6px;
  display: none;
  z-index: 60;
}
.quote-dd.open .quote-dd-menu { display: block; }
.quote-dd-menu a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--blue-darker);
  text-decoration: none;
  white-space: nowrap;
}
.quote-dd-menu a:hover { background: var(--blue-b10); text-decoration: none; }

/* ---- Pager (client-side table pagination) -------------------------------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 24px;
  border-top: 1px solid var(--blue-b20);
}
.pager-info { font-size: var(--text-xs); color: var(--gray-500); }
.pager-btns { display: flex; align-items: center; gap: 8px; }
.pager-page { font-size: var(--text-xs); color: var(--gray-500); padding: 0 4px; }
.pager-btn {
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--blue-normal);
  background: var(--white);
  border: 1px solid var(--blue-b30);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.pager-btn:hover:not(:disabled) { background: var(--blue-b10); border-color: var(--blue-normal); }
.pager-btn:disabled { color: var(--gray-300); cursor: not-allowed; border-color: var(--blue-b20); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: capitalize;
}
.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.chip.buying    { background: #FEF0C7; color: #B54708; }
.chip.trucking  { background: #DBE9FF; color: #1849A9; }
.chip.shipping  { background: #D1F4F0; color: #027A48; }
.chip.clearing  { background: #E9D5FF; color: #6941C6; }
.chip.delivered { background: #D1FADF; color: #027A48; }
.chip.pending   { background: #FEF3C7; color: #92400E; }
.chip.quoted    { background: #D1FAE5; color: #065F46; }
.chip.accepted  { background: #A6F4C5; color: #054F31; }
.chip.rejected  { background: #FDA29B; color: #7F1D1D; }
.chip.expired   { background: #E4E7EC; color: #475467; }
.chip.cancelled { background: #FEE4E2; color: #B42318; }
.chip.converted { background: #DBEAFE; color: #1E40AF; }
.chip.open      { background: #FEF3C7; color: #92400E; }
.chip.sourcing  { background: #DBE9FF; color: #1849A9; }
.chip.found     { background: #D1FADF; color: #027A48; }
.chip.closed    { background: #E4E7EC; color: #475467; }
.chip.unpaid    { background: #FEF3C7; color: #92400E; }
.chip.partial   { background: #FEF0C7; color: #B54708; }
.chip.paid      { background: #D1FADF; color: #027A48; }
.chip.void      { background: #E4E7EC; color: #475467; }

/* ---- Empty state --------------------------------------------------------- */
.empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--gray-500);
}
.empty h3 { color: var(--blue-darker); margin: 0 0 8px; font-family: var(--font-heading); }
.empty p { margin: 0 0 24px; }

/* ---- Tracking timeline (single order) ------------------------------------ */
.timeline { position: relative; padding-left: 32px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: var(--blue-b30);
}
.timeline-step {
  position: relative;
  padding-bottom: 24px;
}
.timeline-step::before {
  content: "";
  position: absolute;
  left: -28px;
  top: 4px;
  width: 16px;
  height: 16px;
  background: var(--blue-b30);
  border-radius: 50%;
  border: 3px solid var(--white);
}
.timeline-step.done::before  { background: var(--color-success); }
.timeline-step.current::before {
  background: var(--yellow-normal);
  box-shadow: 0 0 0 6px rgba(253, 197, 0, 0.2);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 6px rgba(253, 197, 0, 0.2); }
  50%      { box-shadow: 0 0 0 12px rgba(253, 197, 0, 0.05); }
}
.timeline-step h4 {
  font-family: var(--font-heading);
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--blue-darker);
  margin: 0 0 4px;
}
.timeline-step p {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin: 0;
}
.timeline-step time {
  display: block;
  font-size: var(--text-xs);
  color: var(--gray-500);
  margin-top: 4px;
}
