/* ── Reset & Base ─────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg:          #f5f5f0;
  --color-surface:     #ffffff;
  --color-border:      #ddd;
  --color-primary:     #2d6a4f;
  --color-primary-dk:  #1b4332;
  --color-accent:      #74c69d;
  --color-text:        #1a1a1a;
  --color-muted:       #6b7280;
  --color-error:       #dc2626;
  --color-success:     #16a34a;

  --radius:            8px;
  --shadow:            0 2px 8px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}

.app-header__brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  font-size: 20px;
  color: var(--color-accent);
}

.auth-status {
  font-size: 13px;
  opacity: .85;
}

.auth-status a {
  color: #fff;
  text-decoration: underline;
}

/* ── Main ────────────────────────────────────────────────────────────────── */

.app-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 16px;
}

/* ── Screens ─────────────────────────────────────────────────────────────── */

.screen {
  display: block;
}

.screen[hidden] {
  display: none;
}

.screen--centered {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 64px;
}

.screen--centered[hidden] {
  display: none;
}

/* ── Cards & Panels ──────────────────────────────────────────────────────── */

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 48px;
}

.card--auth {
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.card--auth h1 {
  font-size: 22px;
  margin-bottom: 12px;
  color: var(--color-primary-dk);
}

.card--auth p {
  color: var(--color-muted);
  margin-bottom: 28px;
}

.panel {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.panel__title {
  font-size: 17px;
  font-weight: 600;
  color: var(--color-primary-dk);
  margin-bottom: 18px;
}

.panel--selected {
  border-left: 4px solid var(--color-accent);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--color-primary-dk);
}

.btn--ghost {
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
}

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

.btn--large {
  padding: 14px 32px;
  font-size: 16px;
}

.btn--sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ── Inputs ──────────────────────────────────────────────────────────────── */

.input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.input:focus {
  border-color: var(--color-primary);
}

/* ── Search Bar ──────────────────────────────────────────────────────────── */

.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.search-bar .input {
  flex: 1;
}

/* ── Contact List ─────────────────────────────────────────────────────────── */

.contact-list {
  list-style: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 8px;
}

.contact-list[hidden] {
  display: none;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background .12s;
}

.contact-item:last-child {
  border-bottom: none;
}

.contact-item:hover {
  background: var(--color-bg);
}

.contact-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-primary-dk);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.contact-info__name {
  font-weight: 600;
  font-size: 14px;
}

.contact-info__meta {
  font-size: 12px;
  color: var(--color-muted);
}

/* ── Selected Contact Card ───────────────────────────────────────────────── */

.contact-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.contact-card__avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.contact-card__name {
  font-weight: 700;
  font-size: 16px;
}

.contact-card__meta {
  font-size: 13px;
  color: var(--color-muted);
  margin-top: 2px;
}

/* ── Status & Errors ─────────────────────────────────────────────────────── */

.search-status {
  font-size: 13px;
  color: var(--color-muted);
  padding: 6px 0;
}

.search-status[hidden] {
  display: none;
}

.search-status--error {
  color: var(--color-error);
}

.error-msg {
  color: var(--color-error);
  font-size: 13px;
  margin-top: 12px;
}

.error-msg[hidden] {
  display: none;
}

/* ── Loading Spinner ─────────────────────────────────────────────────────── */

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* ── Input modifier ──────────────────────────────────────────────────────── */

.input--sm {
  padding: 6px 10px;
  font-size: 13px;
}

/* ── Quote Builder — Line Items ──────────────────────────────────────────── */

.line-item {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}

.line-item__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.line-item__num {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.line-item__row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.line-item__row--top {
  margin-bottom: 10px;
  align-items: flex-end;
}

.line-item__row--bottom {
  align-items: flex-end;
}

/* ── Field ───────────────────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field--grow {
  flex: 1;
  min-width: 120px;
}

.field--auto {
  flex-shrink: 0;
}

.field--narrow {
  width: 110px;
  flex-shrink: 0;
}

.field--xnarrow {
  width: 72px;
  flex-shrink: 0;
}

.field__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  white-space: nowrap;
}

/* ── Line Total display cell ─────────────────────────────────────────────── */

.line-total {
  height: 38px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14px;
  color: var(--color-primary-dk);
  white-space: nowrap;
}

/* ── Add Line button spacing ─────────────────────────────────────────────── */

.add-line-btn {
  margin-top: 4px;
  margin-bottom: 20px;
}

/* ── Quote Summary ───────────────────────────────────────────────────────── */

.quote-divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin-bottom: 20px;
}

.quote-summary {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 24px;
}

.quote-summary__row {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
}

.quote-summary__label {
  color: var(--color-muted);
  min-width: 72px;
  text-align: right;
}

.quote-summary__value {
  min-width: 90px;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.quote-summary__row--total {
  font-size: 17px;
  font-weight: 700;
  color: var(--color-primary-dk);
  border-top: 2px solid var(--color-border);
  padding-top: 10px;
  margin-top: 4px;
}

.quote-summary__row--total .quote-summary__label,
.quote-summary__row--total .quote-summary__value {
  font-weight: 700;
}

/* ── Tax row ─────────────────────────────────────────────────────────────── */

.tax-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tax-label {
  font-size: 13px;
  color: var(--color-muted);
}

/* ── Quote Actions ───────────────────────────────────────────────────────── */

.quote-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.quote-destination {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.quote-actions__save {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.quote-actions__save .search-status {
  margin: 0;
}

/* ── Panel titlebar (title + role selector) ──────────────────────────────── */

.panel__titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel__titlebar .panel__title {
  margin-bottom: 0;
}

.role-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-selector__select {
  width: auto;
}

/* ── Line item sections ──────────────────────────────────────────────────── */

.line-item__section {
  margin-bottom: 12px;
}

.line-item__section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 3px;
}

/* ── Admin-only section ──────────────────────────────────────────────────── */

.admin-section {
  display: none;
  background: #fffbf0;
  border: 1px dashed #d97706;
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 10px;
}

#quote-panel[data-role="admin"] .admin-section {
  display: block;
}

.admin-section__label {
  color: #b45309;
  border-bottom-color: #fcd34d;
  margin-bottom: 8px;
}

/* ── Margin display (read-only derived) ──────────────────────────────────── */

.margin-display {
  height: 38px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14px;
  color: var(--color-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 80px;
}

/* ── Notes collapsible ───────────────────────────────────────────────────── */

.notes-details {
  margin-top: 8px;
}

.notes-details__summary {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.notes-details__summary::before {
  content: '▶';
  font-size: 8px;
  transition: transform .15s;
}

.notes-details[open] .notes-details__summary::before {
  transform: rotate(90deg);
}

.notes-details__body {
  padding-top: 10px;
}

/* ── Textarea input ──────────────────────────────────────────────────────── */

.input--textarea {
  resize: vertical;
  min-height: 58px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
}

/* ── Full-width field in flex row ────────────────────────────────────────── */

.field--full {
  flex: 1 1 100%;
}

.field--med {
  width: 150px;
  flex-shrink: 0;
}

/* ── Searchable Select (SearchableSelect component) ──────────────────────── */

.ss-wrap {
  position: relative;
  width: 100%;
}

.ss-input {
  width: 100%;
}

.ss-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 220px;
  overflow-y: auto;
  list-style: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

.ss-item {
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
}

.ss-item:last-child {
  border-bottom: none;
}

.ss-item:hover {
  background: var(--color-bg);
  color: var(--color-primary);
}

.ss-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 301;
  background: #fffbeb;
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  white-space: nowrap;
}

.ss-popover[hidden] {
  display: none;
}

.ss-popover__msg {
  font-size: 12px;
  color: var(--color-text);
}

.ss-popover__btn {
  padding: 3px 10px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.4;
}

.ss-popover__yes {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.ss-popover__yes:hover { background: var(--color-primary-dk); }
.ss-popover__no:hover  { background: var(--color-bg); }

/* ── Mount type — locked state hint ─────────────────────────────────────── */

.mount-hint {
  font-size: 11px;
  color: #d97706;
  font-style: italic;
  margin-top: 4px;
}

/* ── Compound measurement rows (OB / MFF mounts) ────────────────────────── */

.mount-fields--compound {
  margin-top: 6px;
}

.compound-meas {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.compound-meas__dim-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  min-width: 44px;
  padding-bottom: 10px;
}

.compound-meas__op {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-muted);
  padding-bottom: 8px;
  flex-shrink: 0;
}

.compound-total {
  height: 38px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 13px;
  color: var(--color-primary-dk);
  white-space: nowrap;
  min-width: 80px;
}

/* ── Disabled dim fields before mount is chosen ─────────────────────────── */

.dim-input:disabled {
  background: var(--color-bg);
  color: var(--color-muted);
  cursor: not-allowed;
}
