/* ─── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --dark-blue:   #02495a;
  --turquoise:   #3db3ce;
  --orange:      #ff6602;
  --green:       #2d7a1b;
  --green-light: #76d45b;
  --error:       #ba1a1a;
  --bg:          #f0f5f7;
  --card:        #ffffff;
  --text:        rgba(0,0,0,.87);
  --text-muted:  rgba(0,0,0,.54);
  --border:      rgba(0,0,0,.12);
  --radius:      8px;
  --shadow:      0 2px 8px rgba(0,0,0,.10);
  --font:        'Maven Pro', sans-serif;
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14px; }

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.app-header {
  background: #fff;
  height: 56px;
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #e5e7eb;
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  display: flex; align-items: stretch;
  max-width: 1280px; width: 100%; margin: 0 auto; padding: 0 20px;
}

/* Logo */
.header-logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; margin-right: 28px; flex-shrink: 0;
}
.logo-img { height: 28px; width: auto; display: block; }
.logo-fallback { display: flex; align-items: center; gap: 8px; }
.logo-mark {
  width: 28px; height: 28px; background: #0057b8; border-radius: 4px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.logo-wordmark { font-size: 20px; font-weight: 700; color: #0057b8; letter-spacing: .01em; font-family: var(--font); }
.logo-wordmark span { color: #02495a; }

/* Nav */
.main-nav { display: flex; align-items: stretch; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 5px;
  padding: 0 14px;
  font-size: 14px; font-weight: 600;
  color: #02495a; text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  white-space: nowrap; user-select: none;
}
.nav-item:hover { color: #000; }
.nav-item--active { color: #0057b8; border-bottom-color: #0057b8; }
.nav-badge {
  font-size: 9px; font-weight: 700; letter-spacing: .04em;
  background: #0057b8; color: #fff;
  border-radius: 2px; padding: 1px 4px;
}

/* Header actions */
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.header-icon-btn {
  width: 30px; height: 30px; border: none; background: transparent;
  display: flex; align-items: center; justify-content: center;
  color: #02495a; cursor: pointer; border-radius: 4px;
}
.header-icon-btn:hover { background: #f3f4f6; color: #000; }
.header-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: #0057b8; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; cursor: pointer; user-select: none;
}

/* ─── Layout ─────────────────────────────────────────────────────────────────── */
.app-main { max-width: 1280px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }

/* ─── Card ───────────────────────────────────────────────────────────────────── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }

/* ─── Section title ──────────────────────────────────────────────────────────── */
.section-title {
  font-size: 15px; font-weight: 700; color: var(--dark-blue);
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 2px solid var(--turquoise);
  display: flex; align-items: center; gap: 8px;
}
.section-title--toggle { cursor: pointer; user-select: none; }
.section-title--toggle:hover { color: var(--turquoise); }
.toggle-icon { margin-left: auto; font-size: 11px; transition: transform .2s; }
.toggle-icon.collapsed { transform: rotate(-90deg); }

/* ─── Form ───────────────────────────────────────────────────────────────────── */
.product-row { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 10px; }
.form-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 180px; }
.form-field--small { flex: 0 0 100px; min-width: 0; }
label { font-size: 11px; font-weight: 700; color: var(--dark-blue); text-transform: uppercase; letter-spacing: .5px; }
input[type="text"], input[type="number"], select {
  height: 40px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 4px;
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: white; outline: none; transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus { border-color: var(--turquoise); box-shadow: 0 0 0 2px rgba(61,179,206,.2); }

.btn-remove-line {
  height: 40px; width: 36px; border: 1px solid var(--border); border-radius: 4px;
  background: white; color: var(--text-muted); cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .15s, color .15s;
}
.btn-remove-line:hover { background: rgba(186,26,26,.08); color: var(--error); border-color: var(--error); }
.btn-remove-placeholder { width: 36px; flex-shrink: 0; }

.form-footer {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 8px;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.priority-group { display: flex; align-items: center; gap: 10px; }
#analyze-btn { margin-left: auto; }
.priority-label { font-size: 11px; font-weight: 700; color: var(--dark-blue); text-transform: uppercase; letter-spacing: .5px; }
.priority-toggle { display: flex; gap: 4px; background: var(--bg); border-radius: 6px; padding: 3px; }
.priority-option {
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer;
  padding: 4px 12px; border-radius: 4px; transition: background .15s, color .15s;
}
.priority-option:has(input:checked) { background: white; color: var(--dark-blue); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.priority-option input { display: none; }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  height: 40px; padding: 0 20px; border: none; border-radius: 4px;
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: opacity .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover:not(:disabled) { opacity: .88; box-shadow: var(--shadow); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary   { background: var(--dark-blue); color: white; }
.btn-approve   { background: var(--dark-blue); color: white; height: 44px; padding: 0 24px; font-size: 15px; }
.btn-secondary { background: white; color: var(--text-muted); border: 1px solid var(--border); }

/* ─── Loading ────────────────────────────────────────────────────────────────── */
.loading-content { display: flex; flex-direction: column; align-items: center; padding: 16px; gap: 16px; }
.spinner { width: 40px; height: 40px; border: 4px solid var(--bg); border-top-color: var(--turquoise); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-muted); }

/* ─── Requested line ─────────────────────────────────────────────────────────── */
.requested-line { font-size: 12.5px; color: var(--text-muted); margin: -6px 0 14px; }
.requested-line strong { color: var(--text); font-weight: 600; }

/* ─── Table ──────────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.offers-table { width: 100%; border-collapse: collapse; }
.offers-table th {
  background: var(--bg); color: var(--dark-blue);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  text-align: left; padding: 10px 16px; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.offers-table th.col-price { text-align: right; }
.offers-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.offers-table tr:last-child td { border-bottom: none; }
.offers-table tbody tr:hover { background: rgba(61,179,206,.06); cursor: default; }
.offers-table tr.row-recommended td:first-child { border-left: 3px solid var(--turquoise); }
.offers-table tr.row-recommended { background: rgba(61,179,206,.07); }
.offers-table tr.row-selected td:first-child { border-left: 3px solid var(--dark-blue); }
.offers-table tr.row-selected { background: rgba(2,73,90,.07); }

/* Price columns */
.col-currency { color: var(--text-muted); font-size: 12px; white-space: nowrap; padding-right: 4px !important; }
.col-price { text-align: right; font-weight: 700; white-space: nowrap; }
.price-currency { color: var(--text-muted); font-size: 12px; margin-right: 2px; }
.price-amount { font-weight: 700; }

/* Stock badges */
.stock-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 12px; }
.stock-badge--in  { background: rgba(118,212,91,.15); color: #1e6611; }
.stock-badge--out { background: rgba(186,26,26,.10);  color: var(--error); }

/* Severity chips */
.chip { display: inline-flex; align-items: center; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; letter-spacing: .3px; cursor: default; }
.chip--high   { background: rgba(186,26,26,.12); color: var(--error); }
.chip--medium { background: rgba(255,102,2,.12);  color: #b84a00; }
.chip--low    { background: rgba(61,179,206,.12); color: var(--dark-blue); }
.chip--rec    { background: rgba(61,179,206,.15); color: var(--dark-blue); }
.chip--sel    { background: rgba(2,73,90,.14); color: var(--dark-blue); }

/* Select button */
.btn-select {
  font-size: 12px; padding: 3px 12px; height: 28px;
  background: transparent; color: var(--turquoise); border: 1px solid var(--turquoise);
  border-radius: 4px; cursor: pointer; font-family: var(--font); font-weight: 600;
  transition: background .15s, color .15s;
}
.btn-select:hover, .btn-select.active { background: var(--turquoise); color: white; }

/* Supplier cell */
.supplier-name { font-weight: 600; }
.supplier-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.supplier-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

/* ─── Anomalies ──────────────────────────────────────────────────────────────── */
.count-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: 11px; font-weight: 700; background: var(--error); color: white; display: inline-flex; align-items: center; justify-content: center; }
.anomaly-list { list-style: none; display: flex; flex-direction: column; }
.anomaly-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.anomaly-item:last-child { border-bottom: none; }
.anomaly-body strong { color: var(--dark-blue); }
.anomaly-desc { color: var(--text-muted); margin-top: 2px; }

/* ─── Recommendation box ─────────────────────────────────────────────────────── */
.recommendation-box { border: 2px solid var(--dark-blue); border-radius: var(--radius); overflow: hidden; }
.rec-split-note { padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--turquoise); border-bottom: 1px solid var(--border); }
.recommendation-group + .recommendation-group { border-top: 2px solid var(--dark-blue); }
.rec-group-heading {
  padding: 6px 16px; background: var(--dark-blue); color: #fff;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}
.rec-grand-total {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-top: 2px solid var(--dark-blue);
}
.rec-grand-total .rec-label { font-size: 13px; }
.rec-grand-total .rec-value { font-size: 20px; }
.rec-grid { display: grid; grid-template-columns: 2fr repeat(auto-fit, minmax(140px,1fr)); }
.rec-field { padding: 14px 16px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.rec-field:last-child { border-right: none; }
.rec-field--supplier { min-width: 240px; }
.rec-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.rec-value { font-size: 18px; font-weight: 700; color: var(--dark-blue); margin-top: 4px; }
.rec-field-note { font-size: 11px; font-weight: 600; margin-top: 3px; }
.rec-field-note--active { color: var(--green); }
.rec-field-note--pending { color: var(--text-muted); font-weight: 400; }
.rec-supplier-name { font-size: 20px; font-weight: 700; color: var(--dark-blue); margin-top: 4px; }
.rec-switch { background: rgba(255,102,2,.08); color: #b84a00; padding: 10px 16px; font-size: 13px; font-weight: 600; border-top: 1px solid rgba(255,102,2,.2); }
.rec-justification { padding: 14px 16px; font-size: 13px; color: var(--text-muted); line-height: 1.6; border-top: 1px solid var(--border); }
.rec-savings { padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--green); border-top: 1px solid var(--border); }
.rec-delivery { padding: 10px 16px; font-size: 13px; color: var(--text-muted); border-top: 1px solid var(--border); }

/* Rebate info in recommendation */
.rec-rebate { border-top: 1px solid var(--border); padding: 10px 16px; display: flex; flex-direction: column; gap: 6px; background: rgba(45,122,27,.04); }
.rebate-row { display: flex; align-items: center; gap: 12px; font-size: 12px; flex-wrap: wrap; }
.rebate-distributor { font-weight: 700; color: var(--dark-blue); min-width: 40px; }
.rebate-spend { color: var(--text-muted); }
.rebate-active { background: rgba(45,122,27,.12); color: var(--green); font-weight: 700; padding: 1px 8px; border-radius: 4px; }
.rebate-none { color: var(--text-muted); font-style: italic; }
.rebate-next { color: var(--turquoise); }

/* Product lines in recommendation */
.rec-lines-table { width: 100%; border-collapse: collapse; border-top: 1px solid var(--border); }
.rec-lines-table th, .rec-lines-table td { padding: 8px 16px; text-align: left; font-size: 13px; }
.rec-lines-table thead th {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.rec-lines-table tbody td { border-top: 1px solid var(--border); color: var(--text); }
.rec-lines-qty { text-align: right; color: var(--text-muted); white-space: nowrap; }
.rec-lines-cost { text-align: right; font-weight: 600; color: var(--dark-blue); white-space: nowrap; }
.rec-lines-cost-inner { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

/* Per-product result blocks */
.product-result-block { display: flex; flex-direction: column; gap: 16px; }

/* ─── Approval ───────────────────────────────────────────────────────────────── */
.approval-actions { display: flex; gap: 16px; align-items: center; }
.approval-note { margin-top: 10px; font-size: 12px; color: #b84a00; }

/* ─── Receipt ────────────────────────────────────────────────────────────────── */
.receipt-card { border-left: 4px solid var(--green-light); }
.receipt-success { color: var(--green); font-weight: 600; margin-bottom: 16px; font-size: 15px; }
.receipt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; margin-top: 8px; }
.receipt-field { display: flex; flex-direction: column; gap: 4px; }
.receipt-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.receipt-value { font-size: 15px; font-weight: 600; color: var(--dark-blue); }

/* ─── Error ──────────────────────────────────────────────────────────────────── */
.error-card { border-left: 4px solid var(--error); }
.error-text { color: var(--error); font-size: 14px; }

/* ─── Not-found banner (partial — some products missing) ───────────────────── */
.notfound-banner {
  background: rgba(255,102,2,.08); border: 1px solid rgba(255,102,2,.3); border-left: 4px solid var(--orange);
  border-radius: var(--radius); padding: 12px 16px; font-size: 13px; color: #7a3900;
  display: flex; gap: 10px; align-items: flex-start;
}
.notfound-banner .icon { font-size: 16px; flex-shrink: 0; margin-top: -1px; }
.notfound-banner strong { color: #5a2b00; }
.notfound-banner .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.notfound-chip { font-family: monospace; font-size: 11.5px; background: rgba(255,102,2,.14); color: #7a3900; padding: 2px 7px; border-radius: 4px; }

/* ─── Purchase request layout (product rows + bulk paste) ───────────────────── */
.request-layout { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) { .request-layout { grid-template-columns: 1fr; } }

.paste-panel {
  border: 1.5px dashed var(--turquoise); border-radius: var(--radius); padding: 14px;
  background: rgba(61,179,206,.05); display: flex; flex-direction: column; gap: 8px;
}
.paste-panel textarea {
  height: 120px; resize: vertical; padding: 8px 10px; font-family: monospace; font-size: 12.5px;
  border: 1px solid var(--border); border-radius: 4px; outline: none; color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}
.paste-panel textarea:focus { border-color: var(--turquoise); box-shadow: 0 0 0 2px rgba(61,179,206,.2); }
.paste-hint { font-size: 11px; color: var(--text-muted); }
.paste-actions { display: flex; align-items: center; gap: 10px; }
.btn-parse { height: 32px; padding: 0 14px; font-size: 12.5px; }
.paste-feedback { font-size: 12px; font-weight: 600; }
.paste-feedback.ok { color: var(--green); }
.paste-feedback.warn { color: var(--orange); }

/* ─── Settings gear ──────────────────────────────────────────────────────────── */
.gear-btn {
  margin-left: auto; width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border);
  background: white; color: var(--dark-blue); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s;
}
.gear-btn:hover { background: var(--bg); }

/* ─── Distributor terms modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(2,20,26,.5); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px;
}
.modal-box {
  background: white; border-radius: var(--radius); width: 100%; max-width: 640px;
  box-shadow: 0 12px 32px rgba(0,0,0,.28); max-height: 84vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h4 { margin: 0; font-size: 15px; color: var(--dark-blue); font-weight: 700; }
.modal-close {
  margin-left: auto; background: none; border: none; font-size: 16px; color: var(--text-muted); cursor: pointer;
  width: 26px; height: 26px; border-radius: 4px;
}
.modal-close:hover { background: var(--bg); }
.modal-tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--border); }
.modal-tab {
  padding: 10px 4px; margin-right: 18px; font-size: 13px; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; cursor: pointer; background: none; border-top: none; border-left: none; border-right: none;
  font-family: var(--font);
}
.modal-tab.active { color: var(--dark-blue); border-bottom-color: var(--turquoise); }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.modal-pane { display: none; } .modal-pane.active { display: block; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.settings-note { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.settings-note.error { color: var(--error); font-weight: 600; }

.dist-card { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 12px; overflow: hidden; }
.dist-card-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--bg); }
.dist-name { font-weight: 600; font-size: 13px; }
.dist-gln { font-family: monospace; font-size: 12px; color: var(--text-muted); margin-left: auto; }
.dist-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; }
.dist-remove:hover { color: var(--error); }

.tier-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tier-table td { padding: 8px 14px; border-bottom: 1px solid var(--border); }
.tier-table tr:last-child td { border-bottom: none; }
.tier-table input { height: 30px; font-size: 13px; }
.tier-threshold-input { max-width: 120px; }
.tier-rebate-input { max-width: 70px; }
.tier-remove {
  background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px;
  width: 24px; height: 24px; border-radius: 4px;
}
.tier-remove:hover { color: var(--error); background: rgba(186,26,26,.08); }
.add-tier-row { padding: 8px 14px; }
.link-btn { background: none; border: none; color: var(--turquoise); font-weight: 600; font-size: 12px; cursor: pointer; padding: 0; font-family: var(--font); }
.link-btn:hover { text-decoration: underline; }
.add-distributor-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.add-distributor-row input { max-width: 160px; height: 34px; }

.ship-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ship-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 6px 14px; border-bottom: 1px solid var(--border); }
.ship-table td { padding: 7px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ship-table input { height: 30px; }
.ship-cost-input { max-width: 100px; }
.ship-free-above-input { max-width: 100px; }

/* ─── Utilities ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
