/* ═══════════════════════════════════════
   Design tokens
═══════════════════════════════════════ */
:root {
  --color-bg:        #f3f4f6;
  --color-surface:   #ffffff;
  --color-border:    #e2e6ea;
  --color-border-2:  #ced4da;
  --color-text:      #1c2b3a;
  --color-muted:     #5e737d;
  --color-navy:      #0c2461;
  --color-blue:      #1e5fd6;
  --color-blue-soft: #eef3fd;
  --color-teal:      #0e8c8c;
  --color-success:   #1a7a55;
  --color-success-bg:#eaf6f0;
  --color-danger:    #b83232;
  --color-danger-bg: #fdf1f1;

  --topbar-h: 56px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
}

/* ═══════════════════════════════════════
   Base reset
═══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
img { max-width: 100%; display: block; }
a { color: var(--color-blue); }

/* ═══════════════════════════════════════
   Top navigation bar
═══════════════════════════════════════ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  padding: 10px;
}

.brand-mark img { height: 40px; }

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--color-border);
}

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-navy);
  letter-spacing: -0.01em;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ═══════════════════════════════════════
   App shell
═══════════════════════════════════════ */
.app-shell {
  max-width: 1520px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

/* ═══════════════════════════════════════
   Summary bar
═══════════════════════════════════════ */
.summary-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 0 4px;
  margin-bottom: 20px;
  overflow: hidden;
}

.summary-item {
  display: flex;
  flex-direction: column;
  padding: 14px 22px;
  flex: 1;
  min-width: 0;
}

.summary-item--highlight {
  background: var(--color-navy);
  border-radius: var(--radius-md);
  margin: 6px;
}

.summary-item--highlight .summary-label,
.summary-item--highlight strong,
.summary-item--highlight .summary-sub { color: #fff; }

.summary-item--highlight .summary-sub { color: rgba(255,255,255,0.65); }

.summary-label {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-muted);
  margin-bottom: 2px;
}

.summary-item strong {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-sub {
  font-size: 14px;
  color: var(--color-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-divider {
  width: 1px;
  height: 40px;
  background: var(--color-border);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════
   Layout
═══════════════════════════════════════ */
.layout {
  display: grid;
  grid-template-columns: 0.6fr 0.4fr;
  gap: 20px;
  align-items: start;
}

.builder-col, .preview-col { min-width: 0; }

/* ═══════════════════════════════════════
   Stepper
═══════════════════════════════════════ */
.stepper-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 28px;
  margin-bottom: 16px;
}

.stepper {
  display: flex;
  align-items: center;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.step-connector {
  flex: 1;
  height: 2px;
  background: var(--color-border);
  margin: 0 8px;
  margin-bottom: 26px; /* push line up to circle center */
  position: relative;
  top: -6px;
}

.step-bubble {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--color-border-2);
  background: var(--color-surface);
  color: var(--color-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.step-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-muted);
  transition: color 0.15s;
  white-space: nowrap;
}

.step:hover .step-bubble {
  border-color: var(--color-blue);
  color: var(--color-blue);
}

.step.is-active .step-bubble {
  background: var(--color-navy);
  border-color: var(--color-navy);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(12,36,97,0.15);
}

.step.is-active .step-label {
  color: var(--color-navy);
  font-weight: 700;
}

/* ═══════════════════════════════════════
   Step panels
═══════════════════════════════════════ */
.step-panel {
  display: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.step-panel.is-active { display: block; }

.panel-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.panel-header--row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.panel-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.panel-desc {
  font-size: 16px;
  color: var(--color-muted);
}

/* Field sections (grouped areas within a panel) */
.field-section {
  margin-bottom: 24px;
}

.field-section:last-child { margin-bottom: 0; }

.field-section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-muted);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}

/* ═══════════════════════════════════════
   Inputs / fields
═══════════════════════════════════════ */
.field { display: flex; flex-direction: column; gap: 5px; }
.field + .field { margin-top: 0; }

.field-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

.input {
  width: 100%;
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  background: #fff;
  color: var(--color-text);
  resize: vertical;
  transition: border-color 0.12s, box-shadow 0.12s;
  font-size: 14px;
}

.input:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(30,95,214,0.14);
}

.input:read-only {
  background: var(--color-bg);
  color: var(--color-muted);
}

.input--search {
  padding-left: 14px;
  background: var(--color-bg);
}

.input--mono { font-family: "SF Mono", "Fira Code", Consolas, monospace; font-size: 14px; }
.input--sm { width: 80px; }

/* Form grids */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 14px;
}

.form-grid--3 {
  grid-template-columns: repeat(3, minmax(0,1fr));
}

.form-grid--li {
  grid-template-columns: repeat(3, minmax(0,1fr));
}

.field--span2 { grid-column: span 2; }
.field--inline { flex-direction: row; align-items: center; gap: 8px; }
.field--inline .field-label { white-space: nowrap; margin-bottom: 0; }

/* ═══════════════════════════════════════
   Buttons
═══════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.12s, box-shadow 0.12s, transform 0.1s;
  line-height: 1.4;
}

.btn:hover { opacity: 0.85; transform: translateY(-1px); }
.btn:active { transform: none; opacity: 1; }

.btn-primary {
  background: var(--color-navy);
  color: #fff;
  box-shadow: 0 2px 6px rgba(12,36,97,0.25);
}

.btn-ghost {
  background: #fff;
  color: var(--color-text);
  border-color: var(--color-border-2);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid rgba(184,50,50,0.3);
  border-radius: var(--radius-md);
  padding: 6px 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-danger-ghost:hover { background: var(--color-danger-bg); }

.btn-group { display: flex; gap: 8px; flex-shrink: 0; }
.btn--sm { padding: 5px 14px; font-size: 14px; }

/* ═══════════════════════════════════════
   Result lists (deals, products, docs)
═══════════════════════════════════════ */
.result-list { display: grid; gap: 8px; margin-top: 8px; }
.result-list--products { gap: 10px; }

/* Empty state */
.empty-state {
  padding: 20px;
  border: 1px dashed var(--color-border-2);
  border-radius: var(--radius-md);
  color: var(--color-muted);
  text-align: center;
  font-size: 16px;
  background: var(--color-bg);
}

/* Deal search results */
.search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: default;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.search-item:hover { border-color: var(--color-blue); box-shadow: var(--shadow-sm); }

.search-item__meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.search-item strong { font-size: 14px; font-weight: 700; }
.search-item small { font-size: 14px; color: var(--color-muted); }

/* Product results */
.product-item {
  display: grid;
  grid-template-columns: 64px minmax(0,1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color 0.12s;
}

.product-item:hover { border-color: var(--color-border-2); }

.product-thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: var(--color-blue-soft);
  border: 1px solid var(--color-border);
  overflow: hidden;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-thumb span { font-size: 22px; font-weight: 700; color: var(--color-navy); }

.product-item__copy { min-width: 0; }
.product-item__copy strong { font-size: 14px; display: block; margin-bottom: 4px; }
.product-item__copy p { font-size: 14px; color: var(--color-muted); margin-bottom: 8px; }

.product-item__meta { display: flex; gap: 6px; flex-wrap: wrap; }

.meta-pill {
  font-size: 14px;
  font-weight: 600;
  padding: 3px 8px;
  background: var(--color-blue-soft);
  color: var(--color-navy);
  border-radius: 4px;
}

/* Documents list */
.documents-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.documents-item__meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.documents-item strong { font-size: 16px; font-weight: 700; }
.documents-item small { font-size: 14px; color: var(--color-muted); }

.documents-item__actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.documents-link { font-size: 14px; font-weight: 600; color: var(--color-blue); text-decoration: none; }
.documents-link:hover { text-decoration: underline; }

.documents-status {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-teal);
  padding: 2px 7px;
  background: rgba(14,140,140,0.09);
  border-radius: 4px;
}

/* ═══════════════════════════════════════
   Line items
═══════════════════════════════════════ */
.line-items { display: grid; gap: 10px; }

.line-item-card {
  display: grid;
  grid-template-columns: 72px minmax(0,1fr);
  gap: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.line-item-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  background: var(--color-blue-soft);
  border: 1px solid var(--color-border);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.line-item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.line-item-thumb span { font-size: 24px; font-weight: 700; color: var(--color-navy); }

.line-item-body { min-width: 0; }

.line-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
}

.line-item-total {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-navy);
}

/* ═══════════════════════════════════════
   Totals block
═══════════════════════════════════════ */
.totals-block {
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 24px;
  margin-top: 16px;
  padding: 16px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.totals-table {
  border-collapse: collapse;
  min-width: 240px;
}

.totals-table td {
  padding: 7px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}

.totals-table td:first-child { color: var(--color-muted); padding-right: 32px; }
.totals-table td:last-child { text-align: right; font-weight: 600; }

.totals-table tr:last-child td { border-bottom: none; }

.totals-grand td {
  font-size: 17px;
  font-weight: 800;
  color: var(--color-navy);
  padding-top: 14px;
  border-top: 2px solid var(--color-border-2) !important;
}

.totals-tax { display: flex; align-items: center; align-self: flex-end; }

/* ═══════════════════════════════════════
   Review action cards
═══════════════════════════════════════ */
.action-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 14px;
  margin-top: 20px;
}

.action-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 18px;
}

.action-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.action-card-header strong { font-size: 14px; font-weight: 700; display: block; margin-bottom: 4px; }
.action-card-header p { font-size: 14px; color: var(--color-muted); }

/* ═══════════════════════════════════════
   Status messages
═══════════════════════════════════════ */
.action-status {
  margin-top: 10px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  white-space: pre-line;
}

.action-status--ok {
  background: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid rgba(26,122,85,0.2);
}

.action-status--error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid rgba(184,50,50,0.2);
}

/* ═══════════════════════════════════════
   Panel navigation
═══════════════════════════════════════ */
.panel-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
}

/* ═══════════════════════════════════════
   Preview sidebar
═══════════════════════════════════════ */
.preview-card {
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 16px;
}

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

.preview-eyebrow {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-muted);
}

.preview-badge {
  font-size: 14px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--color-bg);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
}

.preview-root {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
  min-height: 560px;
  overflow: hidden;
}

/* Quote document inside preview */
.preview-document { padding: 20px; }

.preview-brand {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
}
.brand {
    display: flex;
    align-items: flex-start;
    gap: 18px;
    flex-direction: column;
}

.preview-brand img { width: 120px; }

.preview-brand__badge {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 9px;
  background: var(--color-blue-soft);
  color: var(--color-navy);
  border-radius: 4px;
}

.preview-document h1 {
  font-size: 20px;
  color: var(--color-navy);
  margin-bottom: 14px;
}

.preview-document .meta,
.preview-document .preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 8px;
}

.preview-box {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--color-bg);
  font-size: 16px;
}

.preview-box strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: 4px;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 16px;
}

.preview-table th,
.preview-table td {
  padding: 9px 0;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.preview-table th {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}

.preview-table th:nth-child(n+2),
.preview-table td:nth-child(n+2) {
  width: 64px;
  text-align: right;
}

.preview-line-item {
  display: grid;
  grid-template-columns: 48px minmax(0,1fr);
  gap: 10px;
  align-items: start;
}

.preview-line-item--no-image { grid-template-columns: 1fr; }

.preview-line-item__thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-blue-soft);
  border: 1px solid var(--color-border);
}

.preview-line-item__thumb img { width: 100%; height: 100%; object-fit: cover; }
.preview-line-item__copy { min-width: 0; }

.preview-total {
  margin-top: 16px;
  margin-left: auto;
  width: min(100%, 260px);
  font-size: 16px;
}

.preview-total-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-top: 1px solid var(--color-border);
}

.preview-total-row span { color: var(--color-muted); }

.preview-total-row.grand {
  font-weight: 800;
  font-size: 16px;
  border-top: 2px solid var(--color-border-2);
}

.preview-total-row.grand span { color: var(--color-text); }

/* ═══════════════════════════════════════
   Sidebar card (saved quotes)
═══════════════════════════════════════ */
.sidebar-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

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

.sidebar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
}

/* ═══════════════════════════════════════
   Product modal
═══════════════════════════════════════ */
.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,20,40,0.42);
  backdrop-filter: blur(3px);
}

.modal-box {
  position: relative;
  z-index: 1;
  width: min(900px, 100%);
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h2 { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.modal-header p { font-size: 16px; color: var(--color-muted); }

.close-btn {
  appearance: none;
  border: 1px solid var(--color-border-2);
  background: var(--color-surface);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--color-muted);
  flex-shrink: 0;
  transition: background 0.12s;
}

.close-btn:hover { background: var(--color-bg); color: var(--color-text); }

/* ═══════════════════════════════════════
   Responsive
═══════════════════════════════════════ */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 1fr; }
  .preview-card { position: static; }
}

@media (max-width: 900px) {
  .summary-bar { flex-wrap: wrap; }
  .summary-divider { display: none; }
  .summary-item { flex: 1 1 120px; min-width: 120px; }
}

@media (max-width: 720px) {
  .app-shell { padding: 16px 14px 40px; }
  .topbar { padding: 0 16px; }
  .stepper-wrap { padding: 16px; }
  .step-connector { margin-bottom: 18px; }

  .form-grid,
  .form-grid--3,
  .form-grid--li,
  .action-cards { grid-template-columns: 1fr; }

  .field--span2 { grid-column: auto; }

  .line-item-card { grid-template-columns: 1fr; }
  .line-item-thumb { width: 100%; height: 80px; }

  .totals-block { flex-direction: column; }
  .totals-table { width: 100%; }

  .panel-header--row { flex-direction: column; }
  .panel-nav .btn { flex: 1 1 auto; }
}
