/* styles.css — work-focused operations-app shell */

:root {
  /* sidebar */
  --sidebar-bg: #1b2532;
  --sidebar-text: #9aa6b4;
  --sidebar-text-active: #ffffff;
  --sidebar-active-bg: rgba(255, 255, 255, 0.07);
  --sidebar-border: rgba(255, 255, 255, 0.06);

  /* workspace */
  --bg: #eef1f4;
  --surface: #ffffff;
  --border: #dde2e8;
  --text: #1f2730;
  --muted: #69727d;

  /* accent */
  --accent: #3b6ea5;
  --accent-dark: #335f8e;

  /* status */
  --ok-bg: #e7f4ec;
  --ok-text: #1d5e3a;
  --err-bg: #fcebea;
  --err-text: #9b1c1c;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

/* ---- app shell ---- */
.app { display: flex; min-height: 100vh; }

/* ---- sidebar ---- */
.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-mark {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--accent);
  border-radius: 6px;
  padding: 3px 7px;
}

.brand-name { font-size: 15px; font-weight: 600; color: #fff; }

.nav { display: flex; flex-direction: column; padding: 14px 12px; gap: 3px; }

.nav-item {
  display: block;
  padding: 11px 14px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 15px;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: var(--sidebar-active-bg); color: var(--sidebar-text-active); }

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px 20px;
  font-size: 12px;
  color: var(--sidebar-text);
  border-top: 1px solid var(--sidebar-border);
}

/* ---- main workspace ---- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.page-head h1 { margin: 0; font-size: 18px; font-weight: 600; }
.page-meta { font-size: 13px; color: var(--muted); }

.content { padding: 24px 28px; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  max-width: 1000px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

/* ---- status line ---- */
.status {
  margin: 0;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--muted);
}
.status.ok  { background: var(--ok-bg);  color: var(--ok-text); }
.status.err { background: var(--err-bg); color: var(--err-text); }

/* ---- helpers ---- */
.muted { color: var(--muted); }

/* ---- buttons ---- */
.btn {
  font-family: inherit;
  font-size: 15px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: #f3f5f7; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-sm { padding: 6px 12px; font-size: 14px; }
.btn-danger { color: var(--err-text); border-color: #f0c4c2; background: #fff; }
.btn-danger:hover { background: var(--err-bg); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f3f5f7; }

/* ---- table ---- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 600;
}
.table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---- form fields ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span { font-size: 13px; color: var(--muted); }
.input {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 110, 165, 0.15);
}
textarea.input { font-family: inherit; resize: vertical; min-height: 64px; }

/* ---- modal ---- */
#modal-root { display: none; }
#modal-root.open { display: block; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 32, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}
.modal-head { padding: 16px 20px; font-weight: 600; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; }
.modal-foot {
  padding: 14px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
}

/* ---- narrow screens ---- */
@media (max-width: 640px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex-wrap: wrap; padding: 8px; }
  .nav-item { border-left: none; }
  .nav-item.active { border-left: none; border-bottom: 3px solid var(--accent); }
  .sidebar-foot { display: none; }
}

/* ---- import screen ---- */
.card.wide { max-width: none; }
.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.map-grid .field { margin-bottom: 0; }
.subhead { font-size: 13px; font-weight: 600; margin: 16px 0 8px; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 6px;
}
.table-wrap .table th, .table-wrap .table td { white-space: nowrap; }
.content ul { margin: 6px 0; padding-left: 20px; }
.content li { font-size: 14px; margin: 2px 0; }

/* ---- wider read-only modal + scrollable body ---- */
.modal.wide-modal { max-width: 560px; }
.modal-body { max-height: 60vh; overflow: auto; }

/* ---- report stat cards ---- */
.stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 4px 0 8px; }
.stat {
  flex: 1;
  min-width: 130px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.stat-num { font-size: 22px; font-weight: 700; color: var(--text); }
.stat-lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

/* ---- box labels (Zebra direct thermal) + print ---- */
/* delivery = 4" x 2.5"; assembly = 2.25" x 1.5" */
.label-sheet { display: grid; gap: 12px; }
.label-sheet.delivery { grid-template-columns: repeat(auto-fill, 4in); }
.label-sheet.assembly { grid-template-columns: repeat(auto-fill, 2.25in); }

.label {
  box-sizing: border-box;
  background: #fff;
  border: 1px solid #111;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.delivery .label { width: 4in; height: 2.5in; padding: 0.16in 0.22in; }
.assembly .label { width: 2.25in; height: 1.5in; padding: 0.1in 0.12in; }

.label-top { flex: 1 1 auto; min-height: 0; }
.label-name { font-weight: 800; line-height: 1.1; }
.delivery .label-name { font-size: 20pt; }
.assembly .label-name { font-size: 11pt; }
.label-addr { line-height: 1.3; }
.delivery .label-addr { font-size: 12pt; }
.assembly .label-addr { display: none; }

.label-foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 6px;
  border-top: 2px solid #000;
  padding-top: 4px;
}
.assembly .label-foot { border-top-width: 1px; padding-top: 2px; }
.label-meta { line-height: 1.2; }
.delivery .label-meta { font-size: 11pt; }
.assembly .label-meta { font-size: 8pt; }
.label-box { font-weight: 800; white-space: nowrap; }
.delivery .label-box { font-size: 20pt; }
.assembly .label-box { font-size: 12pt; }

@media print {
  @page { size: 4in 2.5in; margin: 0; } /* default; printLabels() overrides per type */
  .sidebar, .page-head, .no-print { display: none !important; }
  .app, .main { display: block; }
  .content { padding: 0 !important; }
  .label-sheet { display: block; gap: 0; }
  .label { margin: 0; border: none; border-radius: 0; page-break-after: always; break-after: page; }
  .label:last-child { page-break-after: auto; break-after: auto; }
}

/* assembly (small) label content — category + box only, centered, no name */
.label-asm {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
}
.label-asm-cat { font-size: 13pt; font-weight: 700; }
.label-asm-box { font-size: 19pt; font-weight: 800; }

/* ---- status badges ---- */
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
}
.badge-open { background: #eaf1f8; color: #2f5b86; border-color: #cfe0ef; }
.badge-in_progress { background: #fdf3e2; color: #8a5a13; border-color: #f0ddb8; }
.badge-done { background: var(--ok-bg); color: var(--ok-text); border-color: #c4e6d2; }

/* ---- AI Import editable review ---- */
.review-table .input { padding: 5px 7px; font-size: 13px; }
.review-table td { vertical-align: top; }
.review-table .num { width: 70px; }
.items-sub { background: var(--bg); }
.items-sub .table { margin: 6px 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  padding: 2px 4px 2px 8px;
  margin: 2px 4px 2px 0;
  border-radius: 999px;
  border: 1px solid #cfe0ef;
  background: #eaf1f8;
  color: #2f5b86;
}
.chip .input { width: 42px; padding: 1px 4px; font-size: 12px; }
.chip-x {
  border: none;
  background: transparent;
  color: #2f5b86;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.chip-x:hover { color: var(--err-text, #b3261e); }

/* ---- auth: login wall ---- */
/* Hide the whole app until the user is signed in (set on <body> by auth.js).
   This applies from first paint, so no data flashes before login. */
body:not(.authed) .app { display: none; }

#auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
  z-index: 1000;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
}
.auth-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.auth-brand .brand-mark,
.auth-brand .brand-name { color: #1f2a37; }
.auth-brand .brand-mark { background: #1f2a37; color: #fff; }
.auth-title { margin: 0 0 16px; font-size: 18px; }
.auth-card .btn-primary { width: 100%; margin-top: 4px; }

.signed-in {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- tile grid (Batches dashboard, Providers) ---- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 4px;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tile-title { font-size: 16px; font-weight: 600; }
.tile-meta { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text); }
.tile-actions { display: flex; gap: 8px; margin-top: auto; }
.tile-actions .btn { flex: 1; }

/* ---- Order Builder ---- */
.ob-q { width: 100%; }

.ob-results { margin-top: 10px; }
.ob-hint { font-size: 14px; margin: 2px 0; }
.ob-result-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}
.ob-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.ob-result:last-child { border-bottom: none; }
.ob-result:hover, .ob-result.active { background: #eaf1f8; }
.ob-result-main { min-width: 0; }
.ob-result-name { font-size: 14px; line-height: 1.3; }
.ob-result-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.ob-result-price { font-weight: 700; white-space: nowrap; font-size: 14px; }
.ob-result mark { background: #fde7a6; color: inherit; padding: 0 1px; border-radius: 2px; }
.ob-result-note { font-size: 12px; color: var(--muted); padding: 8px 2px 0; }

.ob-custom {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.ob-custom #ob-cust-name { flex: 1 1 220px; }
.ob-custom #ob-cust-price { width: 120px; }

.ob-order-card { margin-top: 16px; }
.ob-table .ob-num { width: 92px; padding: 6px 8px; }
.ob-item-name { font-size: 14px; }
.ob-item-sub { font-size: 12px; margin-top: 1px; }
.ob-line { font-weight: 600; white-space: nowrap; }
.ob-x { padding: 4px 10px; font-size: 16px; line-height: 1; }
.ob-empty { font-size: 14px; padding: 12px; margin: 0; }
.ob-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fdf3e2;
  color: #8a5a13;
  border: 1px solid #f0ddb8;
  vertical-align: middle;
}
.ob-total {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 2px solid var(--border);
}
.ob-total:empty { display: none; }
.ob-total-lbl { font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.ob-total-num { font-size: 24px; font-weight: 700; }

/* saved-orders panel */
.ob-saved-card { margin-bottom: 16px; }
.ob-saved-rows { display: flex; flex-direction: column; gap: 8px; }
.ob-saved-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ob-saved-row.current { border-color: var(--accent); background: #eaf1f8; }
.ob-saved-main { min-width: 0; }
.ob-saved-name { font-size: 14px; font-weight: 600; }
.ob-saved-meta { font-size: 12px; margin-top: 1px; }
.ob-saved-row .row-actions { flex-shrink: 0; }

/* "editing saved order" banner above the order table */
.ob-saved-banner { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.ob-saved-banner:empty { display: none; }

/* print header is screen-hidden; revealed only when printing the order */
.ob-print-head { display: none; }

@media print {
  .ob-print-head {
    display: block;
    font-size: 18pt;
    font-weight: 700;
    margin-bottom: 12px;
  }
  .ob-order-card { border: none; border-radius: 0; padding: 0; }
  /* render qty/price inputs as plain text on paper */
  .ob-table .ob-num {
    border: none;
    padding: 2px 0;
    width: auto;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
  }
  .ob-total-num { font-size: 18pt; }
}

@media (max-width: 640px) {
  .ob-custom #ob-cust-name,
  .ob-custom #ob-cust-price { flex: 1 1 100%; width: 100%; }
  .ob-saved-row { flex-direction: column; align-items: stretch; }
  .ob-saved-row .row-actions { justify-content: flex-start; }
}
