:root {
  --ink: #162022;
  --muted: #617077;
  --line: #d8e0df;
  --paper: #fbfcfa;
  --panel: #ffffff;
  --blue: #185a7d;
  --green: #2f7258;
  --gold: #b88925;
  --red: #9f3d32;
  --shadow: 0 16px 40px rgba(21, 33, 38, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(16px, 4vw, 48px);
  background: rgba(251, 252, 250, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 22px;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.top-actions, .button-row, .import-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sync-status {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sync-status.ready {
  color: #174a3c;
  background: #ecf4f2;
  border-color: #c8ddd6;
}

.hidden {
  display: none !important;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 750;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

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

.secondary-btn {
  background: #ecf4f2;
  color: #174a3c;
  border-color: #c8ddd6;
}

.ghost-btn, .icon-btn {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.remove {
  min-height: 32px;
  color: var(--red);
  background: #fff8f6;
  border-color: #f1cbc4;
  font-size: 12px;
}

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 18px auto 48px;
}

.auth-gate {
  width: min(820px, calc(100% - 32px));
  margin: clamp(42px, 8vh, 96px) auto;
  padding: clamp(18px, 4vw, 34px);
  background:
    linear-gradient(135deg, rgba(24, 90, 125, 0.08), rgba(47, 114, 88, 0.08)),
    #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  max-width: 590px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.auth-mark {
  width: 52px;
  height: 52px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 900;
}

.auth-gate h2 {
  margin-bottom: 0;
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.08;
}

.auth-copy {
  max-width: 620px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.auth-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: start;
  gap: 10px;
  max-width: 620px;
  margin: 24px 0 16px;
}

.auth-form label {
  margin: 0;
}

.auth-form input {
  min-height: 46px;
}

.auth-form .primary-btn {
  min-height: 46px;
  margin-top: 20px;
}

.auth-message {
  grid-column: 1 / -1;
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-message.error {
  color: var(--red);
}

.auth-assurance {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-assurance span {
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #315057;
  font-size: 12px;
  font-weight: 800;
}

.hero-band {
  min-height: 220px;
  display: flex;
  align-items: end;
  padding: clamp(18px, 4vw, 34px);
  background:
    linear-gradient(90deg, rgba(13, 31, 35, 0.86), rgba(13, 31, 35, 0.48), rgba(13, 31, 35, 0.12)),
    url("./assets/hero-porsche.jpg") center 52% / cover;
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-copy {
  max-width: 780px;
}

.hero-copy p {
  margin-bottom: 18px;
  font-size: clamp(18px, 2vw, 25px);
  line-height: 1.32;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(92px, 1fr));
  gap: 10px;
  max-width: 560px;
}

.stat-grid div {
  min-height: 74px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
}

.stat-grid strong {
  display: block;
  font-size: 24px;
}

.stat-grid span {
  color: rgba(255, 255, 255, 0.84);
  font-size: 12px;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 18px 0 12px;
  overflow-x: auto;
}

.tab {
  flex: 0 0 auto;
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
}

.tab.active {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.panel {
  display: none;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel.active { display: block; }

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

.section-head p {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.data-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-head h3 { margin: 0; }

.form-grid, .email-tools, .global-settings, .selector-panel, .template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.global-settings {
  margin-bottom: 18px;
  padding: 14px;
  background: #f3f7f4;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.subhead {
  margin: 0 0 14px;
  padding-top: 4px;
}

.subhead p {
  margin-bottom: 0;
  color: var(--muted);
}

label {
  display: grid;
  gap: 6px;
  color: #415057;
  font-size: 12px;
  font-weight: 800;
}

input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cfd9d8;
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.import-row {
  justify-content: space-between;
  padding: 12px;
  margin-bottom: 12px;
  background: #f3f7f4;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.broker-list {
  display: grid;
  gap: 10px;
}

.quote-dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.dashboard-card {
  min-height: 82px;
  padding: 14px;
  background: #f8fbfa;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.dashboard-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.dashboard-card strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quote-table-wrap {
  overflow-x: auto;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quote-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}

.quote-table th,
.quote-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
}

.quote-table th {
  color: #415057;
  background: #f3f7f4;
  font-size: 12px;
  text-transform: uppercase;
}

.quote-table tr:last-child td {
  border-bottom: 0;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.inline-check input {
  width: 18px;
  min-height: 18px;
}

.broker-row {
  display: grid;
  grid-template-columns: 132px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.broker-row.excluded {
  border-color: #e7c5bf;
  background: #fff8f6;
}

.broker-actions {
  display: grid;
  gap: 8px;
}

.select-broker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  color: #415057;
  font-size: 12px;
  font-weight: 800;
}

.select-broker input {
  min-height: auto;
  width: 20px;
  height: 20px;
}

.exclude-toggle {
  color: var(--red);
}

.broker-body {
  display: grid;
  gap: 10px;
}

.broker-contact-card {
  min-height: 74px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.broker-contact-card h3 {
  margin-bottom: 8px;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.broker-contact-lines {
  display: flex;
  gap: 8px 16px;
  flex-wrap: wrap;
}

.broker-contact-lines span,
.broker-contact-lines a {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}

.broker-contact-lines a:not(.empty) {
  color: var(--blue);
}

.broker-contact-lines .empty {
  pointer-events: none;
}

.edit-broker {
  width: 40px;
  padding: 0;
  font-size: 18px;
}

.broker-edit-panel {
  display: none;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.broker-row.editing .broker-edit-panel {
  display: grid;
}

.broker-edit-actions {
  display: flex;
  justify-content: flex-end;
}

.broker-fields {
  display: grid;
  grid-template-columns: 1.2fr 1.1fr 0.7fr 1.3fr;
  gap: 8px;
}

.broker-fields label {
  gap: 4px;
}

.broker-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.broker-details summary {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  cursor: pointer;
  color: #415057;
  font-size: 12px;
  font-weight: 850;
}

.broker-extra {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.broker-extra label:first-child,
.broker-extra label:last-child,
.quote-links {
  grid-column: span 3;
}

.quote-links {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.quote-link-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.quote-link-head h4 {
  margin: 0 0 4px;
  font-size: 14px;
}

.quote-link-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.file-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  color: #174a3c;
  background: #ecf4f2;
  border: 1px solid #c8ddd6;
  border-radius: 8px;
  cursor: pointer;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.attachment-list {
  display: grid;
  gap: 8px;
}

.attachment-empty {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.attachment-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.attachment-row strong {
  display: block;
  font-size: 13px;
}

.attachment-row span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.attachment-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.attachment-actions a,
.attachment-actions button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.attachment-actions button {
  color: var(--red);
  border-color: #f1cbc4;
}

.email-tools {
  padding-bottom: 18px;
}

.selector-panel {
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.picker-list {
  display: grid;
  gap: 8px;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.picker-item input {
  width: 18px;
  min-height: 18px;
}

.email-tools label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

input[type="checkbox"] {
  width: 20px;
  min-height: 20px;
}

.quote-strategy {
  margin: 0 0 18px;
  padding: 14px;
  background: #fffaf0;
  border: 1px solid #ead6a5;
  border-radius: 8px;
}

.template-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.template-head h3 {
  margin: 0;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
}

.check-grid label {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: start;
  gap: 9px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #ead6a5;
  border-radius: 6px;
}

.check-grid textarea {
  min-height: 58px;
  padding: 6px 8px;
  font-size: 12px;
}

.template-editor {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.template-editor summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
}

.template-grid {
  padding: 14px;
  border-top: 1px solid var(--line);
}

.variable-bank {
  display: flex;
  align-content: start;
  align-items: start;
  gap: 8px;
  flex-wrap: wrap;
}

.token-btn {
  min-height: 32px;
  padding: 0 10px;
  color: #174a3c;
  background: #ecf4f2;
  border-color: #c8ddd6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.template-body {
  grid-column: span 2;
}

#bodyTemplate {
  min-height: 320px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.compose-layout {
  display: grid;
  gap: 12px;
}

#emailBody {
  min-height: 430px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.rich-email-buffer {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 760px;
  min-height: 20px;
  opacity: 0;
  pointer-events: none;
}

.rich-preview-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.rich-preview-panel summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
}

.rich-preview-actions {
  padding: 12px 14px 0;
  border-top: 1px solid var(--line);
}

.rich-email-preview {
  margin: 12px 14px 14px;
  padding: 18px;
  min-height: 180px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #1f2933;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11pt;
  line-height: 1.45;
  user-select: text;
}

@media (max-width: 760px) {
  .topbar, .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions, .section-head .button-row {
    width: 100%;
  }

  .top-actions button, .section-head button {
    flex: 1;
  }

  .stat-grid, .form-grid, .email-tools, .broker-fields, .quote-dashboard, .broker-extra, .global-settings, .selector-panel, .template-grid {
    grid-template-columns: 1fr;
  }

  .auth-form {
    grid-template-columns: 1fr;
  }

  .auth-form .primary-btn {
    margin-top: 0;
  }

  .auth-brand {
    align-items: flex-start;
  }

  .broker-row {
    grid-template-columns: 1fr;
  }

  .broker-row .remove {
    grid-column: 1 / -1;
  }

  .broker-extra label:first-child,
  .broker-extra label:last-child,
  .quote-links,
  .template-body {
    grid-column: auto;
  }

  .attachment-row,
  .quote-link-head {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}
