/*
 * Hand-written static CSS foundation for Phase A — NOT a Tailwind build.
 * BigRock has no Node/npm (confirmed in Phase 0), so this app cannot run a
 * Tailwind build step on the server; any future Tailwind output must be
 * compiled locally/in CI and uploaded as a static file, same as this one.
 * Tokens below (colors, radii, spacing) are matched by eye against the
 * current Next.js app's Tailwind classes (bg #F4F6F9 body, Inter font,
 * blue-700 primary, slate-200 borders, rounded-xl/2xl cards) — not a
 * pixel-perfect port, just enough for Phase A parity testing per the brief.
 */

:root {
  --ink: #1a1a2e;
  --ink-muted: #6b7280;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-disabled: #93b4f8;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #b91c1c;
  --ok-bg: #ecfdf5;
  --ok-text: #047857;
  --warn-bg: #fffbeb;
  --warn-text: #b45309;
  --radius-lg: 1rem;
  --radius-md: 0.75rem;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header__row {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-header__brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
}
.app-header__logo {
  height: 22px;
  width: auto;
  max-width: 96px;
  object-fit: contain;
}

.role-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}
.role-badge--admin      { background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
.role-badge--customer   { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.role-badge--logistics  { background: #f0fdfa; color: #0f766e; border: 1px solid #99f6e4; }
.role-badge--cs         { background: #fff1f2; color: #be123c; border: 1px solid #fecdd3; }

.app-header__right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.app-header__user { font-size: 14px; color: var(--ink-muted); }

.page { max-width: 1280px; margin: 0 auto; padding: 40px 24px; }
.page--narrow { max-width: 440px; }
.page--centered { min-height: calc(100vh - 56px); display: flex; align-items: center; justify-content: center; }
/* Wide variant for operational list pages (Admin Orders/Requests, Customer
   My Orders/My Requests) — these carry more columns than a form/detail page
   and read better with more room; forms/detail pages keep the narrower
   .page above. See app-header__row below, widened to match so the header
   never looks narrower than the page content sitting under it. */
.page--wide { max-width: 1600px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 32px;
}

h1.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
p.page-subtitle { color: var(--ink-muted); font-size: 14px; margin: 0 0 24px; }

label.field-label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }

.input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15); }

.field { margin-bottom: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: var(--primary-disabled); cursor: not-allowed; }
.btn-outline { background: var(--surface); color: #374151; border-color: var(--border); }
.btn-outline:hover { border-color: #cbd5e1; }

.alert { border-radius: var(--radius-md); padding: 12px 16px; font-size: 13.5px; margin-bottom: 18px; }
.alert-danger { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger-text); }

.status-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.status-chip--ok { background: var(--ok-bg); color: var(--ok-text); }
.status-chip--degraded { background: var(--danger-bg); color: var(--danger-text); }
.status-chip--neutral { background: #f1f5f9; color: #475569; }
.status-chip--info { background: #eff6ff; color: #1d4ed8; }
.status-chip--success { background: var(--ok-bg); color: var(--ok-text); }
.status-chip--warning { background: var(--warn-bg); color: var(--warn-text); }
.status-chip--danger { background: var(--danger-bg); color: var(--danger-text); }
.status-chip--teal { background: #f0fdfa; color: #0f766e; }
.status-chip--indigo { background: #eef2ff; color: #4338ca; }
.status-chip--orange { background: #fff7ed; color: #c2410c; }
.status-chip--purple { background: #faf5ff; color: #7e22ce; }

.foot-note { text-align: center; font-size: 12px; color: #9ca3af; margin-top: 24px; }

.error-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.error-page__code { font-size: 13px; font-weight: 700; color: var(--primary); letter-spacing: 0.06em; text-transform: uppercase; }
.error-page__title { font-size: 22px; font-weight: 700; margin: 8px 0 6px; }
.error-page__message { color: var(--ink-muted); font-size: 14px; margin: 0 0 20px; }

dl.kv { margin: 0; }
dl.kv div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
dl.kv div:last-child { border-bottom: none; }
dl.kv dt { color: var(--ink-muted); }
dl.kv dd { margin: 0; font-weight: 600; text-align: right; }

/* Nav */
.app-nav { display: flex; align-items: center; gap: 2px; }
.app-nav__link { font-size: 13.5px; padding: 6px 12px; border-radius: 8px; color: var(--ink-muted); }
.app-nav__link:hover { background: var(--bg); color: var(--ink); }
.app-nav__link.is-active { background: #eff6ff; color: var(--primary); font-weight: 600; }

/* Page header row */
.page-header-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 24px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.stat-card__top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.stat-card__label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); margin: 0; }
.stat-card__icon { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 8px; background: var(--bg); flex-shrink: 0; color: var(--ink-muted); }
.stat-card__icon svg { width: 16px; height: 16px; }
.stat-card__icon--info    { color: var(--primary); }
.stat-card__icon--warn    { color: var(--warn-text); }
.stat-card__icon--danger  { color: var(--danger-text); }
.stat-card__icon--ok      { color: var(--ok-text); }
.stat-card__value { font-size: 28px; font-weight: 700; margin: 0; line-height: 1.15; color: var(--ink); }
.stat-card__value--warn   { color: var(--warn-text); }
.stat-card__value--danger { color: var(--danger-text); }
.stat-card__value--ok     { color: var(--ok-text); }
.stat-card__sub { font-size: 12px; color: #9ca3af; margin: 4px 0 0; }

/* Filter/search toolbar — shared across every list page (Part 7/8) */
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.filter-bar__search { position: relative; flex: 1 1 220px; max-width: 320px; }
.filter-bar__search input {
  width: 100%; padding: 8px 30px 8px 34px; font-size: 13.5px;
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); color: var(--ink);
}
.filter-bar__search input::placeholder { color: #9ca3af; }
.filter-bar__search input:focus { outline: none; box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.25); background: var(--surface); }
.filter-bar__search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: #9ca3af; pointer-events: none; }
.filter-bar__search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: none; background: none; color: #9ca3af; font-size: 15px; line-height: 1; cursor: pointer; padding: 2px;
}
.filter-bar__search-clear:hover { color: var(--ink-muted); }
.filter-bar select {
  font-size: 13.5px; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 8px 10px; background: var(--surface); color: var(--ink); min-width: 140px;
}
.filter-bar select:focus { outline: none; box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.25); }
.filter-bar__clear { font-size: 12px; color: var(--primary); text-decoration: underline; background: none; border: none; cursor: pointer; padding: 0; }
.filter-bar__count { font-size: 12px; color: #9ca3af; margin-left: auto; white-space: nowrap; }
@media (max-width: 640px) {
  .filter-bar__search { max-width: none; flex-basis: 100%; }
  .filter-bar__count { margin-left: 0; flex-basis: 100%; }
}

/* Order timeline (Part 11) — vertical stepper matching Vercel's OrderTimeline */
.timeline { width: 100%; }
.timeline-item { display: flex; gap: 14px; padding-bottom: 26px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item__rail { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.timeline-item__marker {
  width: 34px; height: 34px; border-radius: 999px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; border: 2px solid var(--border); background: var(--surface); color: #cbd5e1;
}
.timeline-item__marker svg { width: 15px; height: 15px; }
.timeline-item--done .timeline-item__marker { background: var(--primary); border-color: var(--primary); color: #fff; }
.timeline-item--current .timeline-item__marker { background: var(--surface); border-color: var(--primary); color: var(--primary); }
.timeline-item__connector { width: 1px; flex: 1; min-height: 22px; margin-top: 6px; background: var(--border); }
.timeline-item--done .timeline-item__connector { background: #bfdbfe; }
.timeline-item__body { flex: 1; padding-top: 4px; }
.timeline-item__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.timeline-item__label { font-size: 13.5px; font-weight: 600; color: #94a3b8; margin: 0; }
.timeline-item--done .timeline-item__label { color: var(--ink); }
.timeline-item--current .timeline-item__label { color: var(--primary); }
.timeline-item__pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--bg); color: #94a3b8; }
.timeline-item--done .timeline-item__pill { background: #eff6ff; color: var(--primary); }
.timeline-item--current .timeline-item__pill { background: #eff6ff; color: var(--primary); border: 1px solid #bfdbfe; }
.timeline-item__sub { font-size: 11.5px; color: #cbd5e1; margin: 3px 0 0; }
.timeline-item--done .timeline-item__sub { color: #94a3b8; }

/* Payment card (Part 12) — matches Vercel's PaymentCountdown */
.payment-card { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius-md); border: 1px solid; }
.payment-card--neutral { background: var(--bg); border-color: var(--border); }
.payment-card--ok      { background: var(--ok-bg); border-color: #a7f3d0; }
.payment-card--danger  { background: var(--danger-bg); border-color: var(--danger-border); }
.payment-card__icon { width: 34px; height: 34px; border-radius: 999px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.payment-card__icon svg { width: 17px; height: 17px; color: #fff; }
.payment-card--neutral .payment-card__icon { background: #cbd5e1; }
.payment-card--ok .payment-card__icon      { background: #16a34a; }
.payment-card--danger .payment-card__icon  { background: #dc2626; }
.payment-card__title { font-size: 13.5px; font-weight: 600; margin: 0; }
.payment-card--neutral .payment-card__title { color: var(--ink); }
.payment-card--ok .payment-card__title      { color: #065f46; }
.payment-card--danger .payment-card__title  { color: #991b1b; }
.payment-card__sub { font-size: 11.5px; margin: 2px 0 0; }
.payment-card--neutral .payment-card__sub { color: #94a3b8; }
.payment-card--ok .payment-card__sub      { color: #059669; }
.payment-card--danger .payment-card__sub  { color: #ef4444; }

.payment-progress { padding: 14px; border-radius: var(--radius-md); border: 1px solid; }
.payment-progress--warn { background: var(--warn-bg); border-color: #fde68a; }
.payment-progress--info { background: #eff6ff; border-color: #bfdbfe; }
.payment-progress__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.payment-progress__days { font-size: 13.5px; font-weight: 600; margin: 0; }
.payment-progress--warn .payment-progress__days { color: #92400e; }
.payment-progress--info .payment-progress__days { color: #1e40af; }
.payment-progress__due { font-size: 11.5px; margin: 2px 0 0; }
.payment-progress--warn .payment-progress__due { color: #b45309; }
.payment-progress--info .payment-progress__due { color: #2563eb; }
.payment-progress__pct { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px; flex-shrink: 0; }
.payment-progress--warn .payment-progress__pct { background: #fde68a; color: #92400e; }
.payment-progress--info .payment-progress__pct { background: #dbeafe; color: #1d4ed8; }
.payment-progress__bar { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.6); border: 1px solid rgba(255, 255, 255, 0.4); overflow: hidden; }
.payment-progress__fill { height: 100%; border-radius: 999px; }
.payment-progress--warn .payment-progress__fill { background: #fbbf24; }
.payment-progress--info .payment-progress__fill { background: #60a5fa; }

/* Documents card (Part 9) — unified Quotation/Invoice PDF list, matching Vercel's Documents card presentation over the same underlying, already-authorized download routes. */
.doc-list { display: flex; flex-direction: column; gap: 1px; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.doc-list__item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--bg); }
.doc-list__meta { display: flex; align-items: center; gap: 10px; min-width: 0; }
.doc-list__icon { flex-shrink: 0; width: 30px; height: 30px; border-radius: 6px; background: var(--danger-bg); color: var(--danger-text); display: flex; align-items: center; justify-content: center; }
.doc-list__icon svg { width: 15px; height: 15px; }
.doc-list__name { font-size: 13px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-list__sub { font-size: 11.5px; color: var(--ink-muted); margin: 1px 0 0; }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 760px; }
table.data-table thead tr { background: var(--bg); border-bottom: 1px solid var(--border); }
table.data-table th { text-align: left; padding: 10px 18px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-muted); white-space: nowrap; }
table.data-table td { padding: 12px 18px; border-top: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
table.data-table tbody tr:hover { background: #fafafa; }
table.data-table a.row-link { color: var(--primary); text-decoration: none; }
table.data-table a.row-link:hover { text-decoration: underline; }
.cell-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; color: var(--primary); }
.cell-wrap { white-space: normal; max-width: 260px; }

/*
 * Fixed-layout operational tables (Frontend Fix Round 1).
 *
 * The plain .data-table above uses the browser's default `table-layout:
 * auto`, where column widths are driven by content — a single very long
 * opportunity/product string can force that column (and the whole table)
 * wider than intended, visually crowding or bleeding into neighboring
 * columns despite .cell-wrap's `max-width` (a soft hint auto-layout is
 * free to ignore once ANY cell's unbroken content demands more room).
 *
 * .data-table--fixed switches to `table-layout: fixed`, which makes each
 * column's width authoritative (taken from the .col-* class on that
 * column's <col> element below) and makes overflow WITHIN a cell always
 * stay within that cell's box — the standard, structural fix for this
 * class of layout bug, not a per-table patch. Combined with the existing
 * .table-scroll (already `overflow-x: auto`), a table whose declared
 * column widths sum wider than the viewport scrolls horizontally instead
 * of squeezing — the deliberate responsive strategy for these operational
 * tables (over a separate mobile card layout per table), since it reuses
 * a mechanism already in place and guarantees zero overlap at any width.
 */
table.data-table--fixed { table-layout: fixed; }

/* Semantic <col>/<th>/<td> width classes — reused across every list table
   instead of one-off inline styles or magic nth-child rules. Pick the one
   matching the column's role; combine with .text-ellipsis/.text-clamp-2
   below for the actual overflow behavior on long values. */
.col-id       { width: 108px; }
.col-name     { width: 240px; }
.col-products { width: 210px; }
.col-narrow   { width: 96px; }
.col-date     { width: 100px; }
.col-amount   { width: 112px; }
.col-status   { width: 128px; }
.col-person   { width: 150px; }
.col-action   { width: 88px; }
.col-action-wide { width: 130px; }

td.col-id, td.col-narrow, td.col-date, td.col-status, td.col-action, td.col-action-wide { white-space: nowrap; }
td.col-status { overflow: hidden; text-overflow: ellipsis; }
td.col-status .status-chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; }
td.col-action-wide { text-align: right; }
td.col-date { color: var(--ink-muted); font-size: 12.5px; }
td.col-amount { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
td.col-action { text-align: right; }
td.col-person { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-muted); font-size: 12.5px; }

/* Single-line ellipsis truncation — for values that should never wrap. */
.text-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Two-line clamp with a trailing ellipsis — for opportunity/product text
   that's fine to wrap, just not indefinitely. overflow-wrap/word-break
   cover the pathological case of one long unbroken token (e.g. a code
   with no spaces) that wouldn't wrap on its own. */
.text-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Secondary line under a primary value in the same cell (e.g. order
   status under an order number, or location under a customer name). */
.cell-sub { display: block; color: var(--ink-muted); font-size: 11.5px; margin-top: 2px; }

.empty-state { text-align: center; padding: 64px 24px; }
.empty-state p.title { font-weight: 600; color: #374151; margin: 0 0 4px; }
.empty-state p.sub { font-size: 13.5px; color: var(--ink-muted); margin: 0; }

.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.select { font-size: 13.5px; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; background: var(--surface); min-width: 150px; }

.card-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .card-grid { grid-template-columns: 1fr; } }
.card h2.card-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); margin: 0 0 16px; }
.card + .card { margin-top: 20px; }

.timeline-item { border-left: 2px solid var(--border); padding: 2px 0 14px 14px; margin-left: 4px; font-size: 13.5px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item .body { color: #374151; }
.timeline-item .meta { color: #9ca3af; font-size: 11.5px; margin-top: 3px; }

.placeholder-note { background: var(--bg); border: 1px dashed var(--border); border-radius: var(--radius-md); padding: 12px 14px; font-size: 12.5px; color: var(--ink-muted); }

/*
 * Responsive breakpoints (Frontend Fix Round 1).
 *
 * Previously the only responsive rule in this file was the 900px
 * card-grid collapse above — the header and page padding had no
 * adaptation at all below desktop width. Operational tables use
 * controlled horizontal scrolling (.table-scroll, already in place) as
 * their responsive strategy rather than a separate mobile card layout per
 * table — .data-table--fixed's declared column widths give every table a
 * predictable min-width, so on a narrow viewport it scrolls cleanly
 * instead of squeezing or overlapping.
 */
@media (max-width: 1024px) {
  .page, .page--wide { padding: 28px 20px; }
  .app-header__row { padding: 0 16px; }
}

@media (max-width: 768px) {
  .page, .page--wide { padding: 20px 16px; }
  .app-header__row { gap: 10px; }
  .app-header__user { display: none; }
  .app-nav { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .app-nav__link { white-space: nowrap; }
}

@media (max-width: 480px) {
  .app-header__row {
    padding: 8px 12px; gap: 6px; height: auto; flex-wrap: wrap;
  }
  .role-badge { display: none; }
  .app-nav { order: 3; flex-basis: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 4px; }
  .app-nav__link { padding: 5px 8px; font-size: 12.5px; }
  .app-header__right { gap: 6px; }
  .page, .page--wide { padding: 16px 12px; }
  .card { padding: 20px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  dl.kv div { flex-direction: column; align-items: flex-start; gap: 2px; }
  dl.kv dd { text-align: left; }
}
