:root {
  --bg: #f0f3fa;
  --panel: #ffffff;
  --border: #dfe3ee;
  --text: #1c2440;
  --text-muted: #64708f;
  --blue: #3b6df0;
  --blue-dark: #2952c8;
  --teal: #0f9d8f;
  --amber: #e2932a;
  --purple: #7c5cf0;
  --green: #1ea672;
  --gray: #8993ac;
  --red: #e5484d;
  --shadow: 0 1px 2px rgba(28, 36, 64, 0.12), 0 0 1px rgba(28, 36, 64, 0.24);
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: linear-gradient(120deg, var(--blue-dark), var(--blue) 60%, var(--purple));
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(28, 36, 64, 0.18);
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.01em;
}

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

.pipeline-total {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.whoami {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
}

.topbar .btn-ghost {
  color: #ffffff;
}
.topbar .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.16);
}

.view-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 2px;
}

.btn-view {
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  padding: 5px 12px;
  border-radius: 6px;
}

.btn-view:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-view.active {
  background: #ffffff;
  color: var(--blue-dark);
  font-weight: 600;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.filter-input {
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  background: var(--bg);
}

.filter-input:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--panel);
}

#filter-customer { width: 200px; }
.filter-amount { width: 110px; }
#filter-employee { min-width: 140px; }
#sort-by-select { min-width: 160px; }
#sort-dir-btn { white-space: nowrap; }

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.filter-date-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.filter-date-label .filter-input {
  width: 140px;
}

.lifecycle-view {
  padding: 16px 24px;
  height: calc(100vh - 108px);
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* border-spacing (not border-collapse) is what gives every column real
   breathing room instead of cells butting straight up against each other —
   each stage-card reads as its own floating card rather than a table cell. */
.lifecycle-table {
  min-width: 760px;
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 14px 10px;
  background: transparent;
  box-shadow: none;
}

.lifecycle-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--bg);
  padding: 8px 14px;
  border-radius: 6px;
}

.lifecycle-cell {
  vertical-align: top;
  padding: 6px;
  width: 25%;
  border-radius: 8px;
}

.lifecycle-cell.empty::after {
  content: "—";
  color: var(--border);
  display: block;
  text-align: center;
  padding: 14px 0;
}

.lifecycle-row {
  cursor: pointer;
}

.lifecycle-row.archived {
  opacity: 0.7;
}

/* Whole-row tint signals lifecycle progress at a glance: red while stuck at
   RFQ Received with no quote sent yet, yellow once quoted but short of
   Purchase Order, green once it has ever reached Purchase Order — applied
   per-cell (not on <tr>) since border-spacing keeps row backgrounds from
   showing through otherwise. */
.lifecycle-row.rfq-only .lifecycle-cell {
  background: rgba(229, 72, 77, 0.1);
}

.lifecycle-row.pending-po .lifecycle-cell {
  background: rgba(226, 147, 42, 0.1);
}

.lifecycle-row.reached-po .lifecycle-cell {
  background: rgba(30, 166, 114, 0.1);
}

.stage-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 148px;
  overflow: hidden;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(137, 147, 172, 0.14);
  border-left: 3px solid var(--gray);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.stage-card:hover {
  box-shadow: 0 2px 6px rgba(28, 36, 64, 0.2);
}


.stage-card-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 46px;
}

.stage-card-customer {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.stage-card-price {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue-dark);
  font-variant-numeric: tabular-nums;
}

.stage-card .employee-chip {
  align-self: flex-start;
}

.stage-card-time {
  align-self: flex-end;
  margin-top: 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.line-items-preview {
  position: relative;
  cursor: help;
}

.line-items-summary {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  font-size: 12px;
  color: var(--text-muted);
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.line-items-tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  z-index: 20;
  margin-bottom: 6px;
  background: var(--text);
  color: #fff;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  min-width: 220px;
  max-width: 300px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.line-items-preview:hover .line-items-tooltip {
  display: block;
}

.list-view {
  padding: 16px 24px;
  height: calc(100vh - 108px);
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.quote-list-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.quote-list-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--bg);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.quote-list-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}

.quote-list-table th[data-sort]:hover {
  color: var(--blue-dark);
}

.quote-list-table th[data-sort]::after {
  content: "";
  margin-left: 4px;
}

.quote-list-table th.sorted[data-dir="asc"]::after {
  content: "\2191";
}

.quote-list-table th.sorted[data-dir="desc"]::after {
  content: "\2193";
}

.quote-list-table th.sorted {
  color: var(--blue-dark);
}

.quote-list-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.quote-list-table tbody tr {
  cursor: pointer;
}

.quote-list-table tbody tr:hover {
  background: rgba(59, 109, 240, 0.06);
}

.quote-list-table td.list-price-cell {
  font-weight: 700;
  color: var(--blue-dark);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.list-status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 10px;
  white-space: nowrap;
  background: rgba(137, 147, 172, 0.16);
  color: var(--text-muted);
}

.list-status-badge[data-status="RFQ_RECEIVED"] { background: rgba(59, 109, 240, 0.14); color: var(--blue-dark); }
.list-status-badge[data-status="QUOTED"] { background: rgba(15, 157, 143, 0.14); color: var(--teal); }
.list-status-badge[data-status="FOLLOW_UP"] { background: rgba(226, 147, 42, 0.16); color: #974f0c; }
.list-status-badge[data-status="PURCHASE_ORDER"] { background: rgba(124, 92, 240, 0.16); color: var(--purple); }

.list-status-badge.archived { background: rgba(137, 147, 172, 0.2); color: var(--text-muted); }

.restore-btn {
  padding: 4px 10px;
  font-size: 12px;
}

.employee-chip {
  background: rgba(59, 109, 240, 0.12);
  color: var(--blue-dark);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 11px;
}

.line-count {
  font-size: 11px;
  color: var(--text-muted);
}

.archive-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.03em;
}
.archive-badge.won { background: rgba(30, 166, 114, 0.16); color: var(--green); }
.archive-badge.lost { background: rgba(229, 72, 77, 0.14); color: var(--red); }

/* buttons */
.btn {
  display: inline-block;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
}

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: rgba(28, 36, 64, 0.06); }
.btn-secondary { background: #e9eefd; color: var(--blue-dark); }
.btn-secondary:hover { background: #dbe4fc; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { background: #b7bfd6; cursor: not-allowed; }
.btn-danger-ghost { background: transparent; color: var(--red); }
.btn-danger-ghost:hover { background: rgba(229, 72, 77, 0.1); }
.btn-success-ghost { background: transparent; color: var(--green); }
.btn-success-ghost:hover { background: rgba(30, 166, 114, 0.1); }
.btn-icon {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 6px;
}

/* modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 36, 64, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--panel);
  border-radius: 10px;
  width: 100%;
  max-width: 780px;
  box-shadow: 0 8px 24px rgba(28, 36, 64, 0.35);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  background: linear-gradient(120deg, #eef1fd, #f3effd);
}

.modal-title-input {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  border: none;
  outline: none;
  color: var(--text);
  background: transparent;
}

.modal-title-input:focus { background: rgba(255, 255, 255, 0.6); border-radius: 4px; }

.status-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(59, 109, 240, 0.14);
  color: var(--blue-dark);
  white-space: nowrap;
}

.status-badge.archived-badge {
  background: rgba(137, 147, 172, 0.2);
  color: var(--text-muted);
}

.status-select {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 5px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(59, 109, 240, 0.14);
  color: var(--blue-dark);
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.modal-body {
  padding: 16px 20px;
  max-height: 70vh;
  overflow-y: auto;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 16px;
  margin-bottom: 8px;
}

.meta-grid label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: var(--text-muted);
  gap: 3px;
}

.meta-grid input {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
}

.meta-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.save-status {
  font-size: 12px;
  color: var(--teal);
  font-weight: 600;
}

h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 18px 0 8px;
}

.email-section .email-content {
  background: var(--bg);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

.email-content .email-subject {
  font-weight: 600;
  margin-bottom: 6px;
}

.email-content .email-empty {
  color: var(--text-muted);
  font-style: italic;
}

.items-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 8px;
}

.items-section-header h3 {
  margin: 0;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

/* Pre-quote, the pricing-app match/price is only an internal estimate —
   collapsed by default (toggle-estimate-btn) so nobody mistakes it for
   what the customer was actually quoted. */
.items-section.prices-collapsed .price-detail {
  display: none;
}

/* Real quoted-from-email values only exist/matter once a quote has
   actually gone out — hidden until then regardless of the estimate toggle. */
.quoted-detail {
  display: none;
}

.items-section.show-quoted .quoted-detail {
  display: table-cell;
}

.quoted-detail:nth-last-child(1) {
  font-weight: 700;
  color: var(--green);
}

.items-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
}

.items-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px;
  vertical-align: top;
}

.items-table .raw-text {
  font-weight: 500;
}

.items-table .specs {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.items-table select {
  font-size: 12px;
  padding: 4px;
  border-radius: 4px;
  border: 1px solid var(--border);
  max-width: 220px;
}

.needs-review {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #974f0c;
  background: #fff0b3;
  border-radius: 3px;
  padding: 1px 6px;
  margin-left: 6px;
  text-transform: uppercase;
}

.quote-total-row {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 10px 8px 0;
  font-weight: 700;
  font-size: 15px;
  color: var(--blue-dark);
}

.notes-content {
  background: var(--bg);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  white-space: pre-wrap;
  font-family: inherit;
  max-height: 140px;
  overflow-y: auto;
  margin: 0 0 8px;
  color: var(--text);
}

.notes-content:empty::before {
  content: "No notes yet.";
  color: var(--text-muted);
  font-style: italic;
}

.note-add {
  display: flex;
  gap: 8px;
}

.note-add textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.modal-footer-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ poller */

.poller-view {
  padding: 16px 24px;
  height: calc(100vh - 108px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.poller-status-card {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.poller-status-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.poller-running-badge {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 4px 12px;
  border-radius: 12px;
  background: rgba(137, 147, 172, 0.16);
  color: var(--text-muted);
}

.poller-running-badge.running {
  background: rgba(30, 166, 114, 0.16);
  color: var(--green);
}

.poller-next-cycle {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
}

.poller-run-error {
  margin-top: 10px;
  font-size: 13px;
  color: var(--red);
}

.poller-section {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.poller-section h3 {
  margin-top: 0;
}

.poller-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  margin: 14px 0 6px;
}

.poller-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.poller-detail-row:last-child {
  border-bottom: none;
}

.poller-error-text {
  color: var(--red);
  font-weight: 600;
}

.poller-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

/* ---------------------------------------------------------------- mobile */
@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 8px;
  }

  .topbar h1 {
    font-size: 15px;
  }

  .topbar-right {
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .pipeline-total {
    order: 3;
    width: 100%;
    font-size: 11px;
  }

  .whoami {
    display: none;
  }

  .filter-bar {
    padding: 10px 14px;
    gap: 8px;
  }

  #filter-customer,
  #filter-employee,
  .filter-date-label,
  .filter-date-label .filter-input,
  .filter-checkbox,
  #filter-clear-btn {
    width: 100%;
  }

  .filter-amount {
    width: calc(50% - 4px);
  }

  /* Status changes go through the modal's status dropdown on mobile (no
     HTML5 drag-and-drop on touch); the lifecycle table itself just needs
     the same horizontal-scroll treatment as the list/archive tables. */
  .lifecycle-view,
  .list-view,
  .poller-view {
    height: auto;
    max-height: calc(100vh - 160px);
    padding: 12px;
  }

  .modal-backdrop {
    padding: 0;
    align-items: stretch;
  }

  .modal {
    max-width: 100%;
    min-height: 100vh;
    border-radius: 0;
  }

  .modal-header {
    flex-wrap: wrap;
    border-radius: 0;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .modal-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .modal-footer-left {
    width: 100%;
  }

  .modal-footer-left .btn,
  .modal-footer > .btn {
    flex: 1 1 auto;
  }

  .btn {
    padding: 8px 14px;
  }
}
