:root {
  --color-bg: #f6f7f9;
  --color-surface: #ffffff;
  --color-border: #d9dce1;
  --color-text: #1f2430;
  --color-muted: #5b6270;
  --color-primary: #1f5eff;
  --color-primary-text: #ffffff;
  --color-warning-bg: #fff4e5;
  --color-warning-text: #8a5300;
  --color-error-bg: #fdecec;
  --color-error-text: #a3231b;
  --color-manual-bg: #eef1ff;
  --color-manual-text: #33399e;
}

* { box-sizing: border-box; }

/* The native [hidden] attribute is how JS shows/hides picker levels and
   add-new rows. Without this, class rules like .picker-level's
   `display: flex` (higher specificity than the UA stylesheet's
   `[hidden] { display: none }`) would force those elements to stay
   visible even while hidden is set. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.brand { font-weight: 600; text-decoration: none; color: var(--color-text); }

.site-main { max-width: 900px; margin: 0 auto; padding: 1.5rem; }
/* The Project page is table-heavy -- let it use the full window so every
   column is visible without horizontal scrolling. */
.site-main.main-wide { max-width: min(1700px, 97vw); }

.breadcrumb { color: var(--color-muted); font-size: 0.95rem; margin-top: -0.5rem; }

h1, h2, h3 { line-height: 1.25; }

a { color: var(--color-primary); }

.link-button {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.tile-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.tile {
  display: block;
  padding: 1.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--color-text);
}
.tile h2 { margin-top: 0; }
.tile p { color: var(--color-muted); margin-bottom: 0; }

.auth-card {
  max-width: 360px;
  margin: 3rem auto;
  padding: 1.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

form { display: flex; flex-direction: column; gap: 0.85rem; }
form.line-item-form { max-width: 480px; }

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--color-muted); }
label.checkbox-label { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--color-text); }

input, select, button {
  font: inherit;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
}

button { cursor: pointer; }
/* Primary action = a submit button. Deliberately NOT "form button" -- that
   also swept up the lamination option buttons and the secondary "Continue"
   button and painted them all primary-blue, so you couldn't tell which
   lamination was selected. */
button[type="submit"] {
  background: var(--color-primary);
  color: var(--color-primary-text);
  border-color: var(--color-primary);
  align-self: flex-start;
}

.button-secondary {
  align-self: flex-start;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--color-text);
}

.button-danger,
button[type="submit"].button-danger {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border: 1px solid var(--color-error-text);
}

.delete-link {
  color: var(--color-error-text);
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

/* --- Screen 1: Customer / RFQ# / Part#-Item# picker --- */
.picker-hint { color: var(--color-muted); font-size: 0.9rem; max-width: 460px; }
.hierarchy-picker { display: flex; flex-direction: column; gap: 1.25rem; max-width: 460px; }
.picker-level { display: flex; flex-direction: column; gap: 0.35rem; }
.picker-level.locked { opacity: 0.45; }
.picker-row { display: flex; gap: 0.5rem; align-items: center; }
.picker-row select { flex: 1; }
.picker-create { display: flex; gap: 0.4rem; align-items: center; }
.picker-create input { flex: 1; }
.new-btn, .create-confirm, .create-cancel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  white-space: nowrap;
  align-self: stretch;
}
.create-confirm { background: var(--color-primary); color: var(--color-primary-text); border-color: var(--color-primary); }
.picker-links { display: flex; gap: 0.25rem; min-height: 1rem; }
.picker-links a { font-size: 0.85rem; }
.continue-btn {
  align-self: flex-start;
  background: var(--color-primary);
  color: var(--color-primary-text);
  border: 1px solid var(--color-primary);
}
.continue-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* --- Toggle + option button groups (line-item type, lamination) --- */
.line-item-type-toggle { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.type-btn, .opt-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.type-btn.active, .opt-btn.active {
  background: var(--color-primary); color: var(--color-primary-text); border-color: var(--color-primary);
  font-weight: 600;
}
.opt-btn.active::before { content: "\2713\00a0"; }  /* checkmark on the selected one */
.field-block { display: flex; flex-direction: column; gap: 0.35rem; }
.field-label { font-size: 0.9rem; color: var(--color-muted); }
.button-group { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.button-group .opt-btn { padding: 0.35rem 0.6rem; }
/* Lamination: full CoolSeal names are long, and the selected one must be
   obvious -- stack them and left-align. */
.button-group-stack { flex-direction: column; align-items: stretch; max-width: 340px; }
.button-group-stack .opt-btn { text-align: left; }
.form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* --- Line-items table --- */
/* The page (.main-wide) expands to fit the table, so this scroll wrapper is
   only a last-resort fallback for very narrow windows / phones. */
.table-scroll { overflow-x: auto; margin-bottom: 1.5rem; }
.line-items-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.line-items-table th, .line-items-table td {
  border: 1px solid var(--color-border);
  padding: 0.5rem 0.6rem;
  text-align: left;
  vertical-align: top;
}
.line-items-table th { background: var(--color-surface); white-space: nowrap; }
.line-items-table td.col-details, .line-items-table th.col-details { min-width: 220px; white-space: normal; }
/* Flag messages are long -- let this column wrap instead of stretching the
   whole table wide. */
.line-items-table td.col-flags, .line-items-table th.col-flags { max-width: 260px; white-space: normal; }
.line-items-table tr.row-manual { background: var(--color-manual-bg); }

/* --- Multi-quantity: quantities panel, master + tier rows, per-tier totals --- */
.quantities-form {
  flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 8px; padding: 0.9rem 1rem; margin-bottom: 1rem;
}
.quantities-form label { flex-direction: column; }
.quantities-form input { min-width: 12rem; }
.quantities-note { color: var(--color-muted); font-size: 0.85rem; flex-basis: 100%; }

.line-items-table tr.li-master td { border-bottom-width: 0; font-weight: 600; }
.line-items-table tr.li-tier td { background: var(--color-bg); }
.line-items-table tr.li-tier td.tier-indent { border-right-width: 0; }
.line-items-table tr.tier-suppressed td { color: var(--color-error-text); }
.line-items-table tr.legacy-row td { background: var(--color-manual-bg); }
.legacy-tag {
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--color-manual-bg); color: var(--color-manual-text);
  border-radius: 3px; padding: 0 0.3rem; margin-left: 0.25rem;
}

.tier-totals { margin: 0.5rem 0 1.5rem; }
.tier-totals h3 { margin-bottom: 0.4rem; }
.tier-totals-table { border-collapse: collapse; font-size: 0.95rem; }
.tier-totals-table td, .tier-totals-table th {
  border: 1px solid var(--color-border); padding: 0.4rem 0.8rem; text-align: left;
}
.tier-totals-table tr.tier-suppressed td { color: var(--color-error-text); }
.reprice-compare { margin-bottom: 1rem; }

.add-disabled-note {
  background: var(--color-warning-bg); color: var(--color-warning-text);
  border-radius: 6px; padding: 0.75rem 1rem;
}
.field-hint { font-size: 0.8rem; color: var(--color-muted); }
.calc-tier { font-size: 0.85rem; padding: 0.15rem 0; }
.calc-tier-suppressed { color: var(--color-error-text); font-weight: 600; }

.flag-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  margin: 0.1rem 0.2rem 0.1rem 0;
}
.flag-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.flag-error { background: var(--color-error-bg); color: var(--color-error-text); }
.flag-manual { background: var(--color-manual-bg); color: var(--color-manual-text); }
/* Suppressing flags (D2) -- bold, so a "not priced" tier is obvious. */
.flag-suppress { background: var(--color-error-bg); color: var(--color-error-text); font-weight: 700; }
p.flag-error { padding: 0.5rem 0.75rem; border-radius: 6px; }

.calc-preview {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.75rem;
  background: var(--color-surface);
}
.calc-summary { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.5rem; }
.calc-row { display: flex; justify-content: space-between; font-size: 0.9rem; }
.calc-label { color: var(--color-muted); }
.calc-value { font-weight: 600; }

.diff-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.9rem; }
.diff-table th, .diff-table td { border: 1px solid var(--color-border); padding: 0.4rem 0.6rem; text-align: left; }

.admin-instructions, .parse-errors {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

/* --- Finalization / quote summary screen --- */
.summary-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.summary-actions .button-secondary, .summary-actions button {
  align-self: flex-start; padding: 0.5rem 0.9rem;
}
.summary-meta { border-collapse: collapse; margin-bottom: 1.25rem; }
.summary-meta th, .summary-meta td {
  border: 1px solid var(--color-border); padding: 0.35rem 0.8rem; text-align: left;
}
.summary-meta th { background: var(--color-surface); white-space: nowrap; }

@media print {
  .site-header, .summary-actions, .no-print { display: none !important; }
  .site-main, .site-main.main-wide { max-width: none; padding: 0; }
  a { color: inherit; text-decoration: none; }
  .table-scroll { overflow: visible; }
  .line-items-table, .tier-totals-table, .summary-meta { font-size: 11px; }
  .flag-pill { border: 1px solid #999; }
  .tier-suppressed td, .flag-suppress { color: #000; font-weight: 700; }
  body { background: #fff; }
}
