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

:root {
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --border:      #e2e8f0;
  --border-hover:#cbd5e1;
  --text:        #0f172a;
  --text-2:      #475569;
  --text-3:      #94a3b8;
  --accent:      #2563eb;
  --shadow-xs:   0 1px 2px rgba(15,23,42,0.05);
  --shadow-sm:   0 1px 3px rgba(15,23,42,0.07), 0 1px 2px rgba(15,23,42,0.04);
  --shadow:      0 4px 12px rgba(15,23,42,0.08), 0 1px 3px rgba(15,23,42,0.05);
  --shadow-lg:   0 20px 40px rgba(15,23,42,0.10), 0 4px 12px rgba(15,23,42,0.06);
  --radius:      14px;
  --radius-sm:   8px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Layout ──────────────────────────────── */

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-xs);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--text);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.logo-badge {
  background: #f1f5f9;
  color: var(--text-2);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  letter-spacing: 0.01em;
}

.topbar-right { display: flex; align-items: center; gap: 0.75rem; }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  line-height: 1.4;
}
.btn-ghost:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: #f8fafc;
}

.content {
  flex: 1;
  max-width: 660px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  width: 100%;
}

/* ── Search hero ─────────────────────────── */

.search-hero {
  text-align: center;
  margin-bottom: 1.75rem;
}
.search-hero h1 {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  color: var(--text);
  margin-bottom: 0.3rem;
}
.search-hero p {
  font-size: 0.875rem;
  color: var(--text-3);
}

/* ── Search input ────────────────────────── */

.search-wrap { position: relative; }

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 3px rgba(37,99,235,0.1);
}

.search-icon {
  position: absolute;
  left: 1rem;
  width: 18px;
  height: 18px;
  color: var(--text-3);
  pointer-events: none;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  padding: 0.9rem 3rem 0.9rem 2.9rem;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  border-radius: var(--radius);
}
.search-input::placeholder { color: var(--text-3); }

.search-clear {
  position: absolute;
  right: 0.85rem;
  background: #f1f5f9;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, background 0.15s;
  color: var(--text-3);
}
.search-clear.visible {
  opacity: 1;
  pointer-events: auto;
}
.search-clear:hover { background: #e2e8f0; color: var(--text); }

/* ── Dropdown ────────────────────────────── */

.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  overflow: hidden;
  display: none;
}
.search-dropdown.visible { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover,
.dropdown-item.active { background: #f8fafc; }

.dropdown-avatar {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #dbeafe, #e0e7ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #3b82f6;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.dropdown-info { flex: 1; min-width: 0; }
.dropdown-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dropdown-sub {
  font-size: 0.75rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-arrow { color: var(--text-3); width: 12px; height: 12px; flex-shrink: 0; }

.dropdown-empty,
.dropdown-error  { padding: 1.1rem; text-align: center; font-size: 0.85rem; color: var(--text-3); }
.dropdown-error  { color: #b91c1c; }

.dropdown-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.1rem;
  font-size: 0.85rem;
  color: var(--text-3);
}

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

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Section cards ───────────────────────── */

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-top: 1.25rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-3);
}

.section-count {
  background: #f1f5f9;
  color: var(--text-2);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ── Client card ─────────────────────────── */

.client-info { padding: 1.25rem; }

.client-name-lg {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.025em;
  margin-bottom: 0.8rem;
}

.client-facts { display: flex; flex-direction: column; gap: 0.4rem; }

.fact-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.875rem;
  color: var(--text-2);
}

.fact-icon { width: 15px; height: 15px; color: var(--text-3); flex-shrink: 0; }

/* ── Opportunity rows ────────────────────── */

.opp-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.opp-row:last-child { border-bottom: none; }
.opp-row:hover { background: #fafbfc; }

.opp-body { flex: 1; min-width: 0; }

.opp-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.opp-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.badge {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: 5px;
  font-size: 0.7rem;
  font-weight: 500;
}
.badge-stage { background: #eff6ff; color: #1d4ed8; }
.badge-value { background: #f0fdf4; color: #166534; }
.badge-prob  { background: #fefce8; color: #854d0e; }
.badge-date  { background: #f5f3ff; color: #6d28d9; }

.btn-quote {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--text);
  color: #fff;
  border: none;
  padding: 0.48rem 0.95rem;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}
.btn-quote:hover  { background: #1e293b; transform: translateY(-1px); }
.btn-quote:active { transform: translateY(0); }

.opp-empty,
.state-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 2rem 1.25rem;
  font-size: 0.875rem;
  color: var(--text-3);
}

/* ── Login ───────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.75rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.login-heading {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 0.2rem;
}
.login-sub {
  font-size: 0.85rem;
  color: var(--text-3);
  margin-bottom: 1.5rem;
}

/* ── Forms ───────────────────────────────── */

.field { margin-bottom: 1rem; }

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 0.35rem;
  letter-spacing: 0.02em;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: #f8fafc;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.btn-primary {
  width: 100%;
  background: var(--text);
  color: #fff;
  border: none;
  padding: 0.7rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
  margin-top: 0.5rem;
}
.btn-primary:hover { background: #1e293b; }

.error-card {
  background: #fff5f5;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: #991b1b;
  margin-bottom: 1rem;
}

/* ── Opportunity detail ──────────────────── */

.content-wide {
  flex: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  width: 100%;
}

.detail-header { margin-bottom: 1.5rem; }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.38rem 0.85rem;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  margin-bottom: 0.9rem;
  line-height: 1.4;
}
.btn-back:hover {
  background: var(--surface);
  border-color: var(--border-hover);
  color: var(--text);
}

.detail-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.25;
}

/* ── Detail form ─────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.25rem;
  padding: 1.25rem 1.25rem 0;
}

.field-full { grid-column: 1 / -1; }

select,
textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: #f8fafc;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
select { cursor: pointer; }
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }

.form-footer {
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1.25rem;
}

.btn-save {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
}
.btn-save:hover    { background: #1d4ed8; }
.btn-save:disabled { opacity: 0.6; cursor: default; }

.save-ok  { font-size: 0.78rem; color: #166534; background: #f0fdf4; border: 1px solid #bbf7d0; padding: 0.2rem 0.6rem; border-radius: 5px; }
.save-err { font-size: 0.78rem; color: #991b1b; background: #fff5f5; border: 1px solid #fecaca; padding: 0.2rem 0.6rem; border-radius: 5px; }

/* ── Quote rows ──────────────────────────── */

.quote-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.quote-row:last-child { border-bottom: none; }
.quote-row:hover { background: #fafbfc; }

.quote-body { flex: 1; min-width: 0; }

.quote-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quote-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-3);
}

.quote-date { color: var(--text-3); }

/* ── Quote detail header row ─────────────── */

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

/* ── Detail fields grid ──────────────────── */

.detail-fields {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem 1.5rem;
  padding: 1.25rem;
}

.detail-field label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  display: block;
  margin-bottom: 0.3rem;
}

.detail-field-value {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
  word-break: break-word;
}

/* ── Line items table ────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.quote-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  min-width: 580px;
}

.quote-table th {
  text-align: left;
  padding: 0.65rem 1rem;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
  white-space: nowrap;
}

.quote-table td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
  line-height: 1.45;
}

.quote-table tbody tr:last-child td { border-bottom: none; }
.quote-table tbody tr.row-alt       { background: #f8fafc; }
.quote-table tbody tr:hover         { background: #eff6ff; }

.col-num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.col-desc {
  color: var(--text-2);
  font-size: 0.82rem;
  max-width: 200px;
}

.line-name { font-weight: 500; }

/* ── Totals section ──────────────────────── */

.totals-section {
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  justify-content: flex-end;
}

.totals-inner { min-width: 260px; }

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0;
  font-size: 0.875rem;
  color: var(--text-2);
  gap: 3rem;
}

.totals-row span:last-child {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.total-final {
  border-top: 1px solid var(--border);
  margin-top: 0.4rem;
  padding-top: 0.7rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Clickable opp body ───────────────────── */

.opp-body-link {
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 0;
}
.opp-body-link:hover .opp-title { color: var(--accent); }

/* ── Mobile ──────────────────────────────── */

@media (max-width: 560px) {
  .content { padding: 1.5rem 1rem 3rem; }
  .search-hero h1 { font-size: 1.35rem; }
  .topbar { padding: 0 1rem; }
  .logo-name { display: none; }

  .opp-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .btn-quote {
    width: 100%;
    justify-content: center;
  }
}
