/* AnyVan Storage — Quote Builder */

:root {
  --navy: #0f2240;
  --primary: #41a5dd;
  --primary-dark: #106799;
  --accent: #ffc907;
  --surface: #f7f9fb;
  --card: #ffffff;
  --text: #16202e;
  --muted: #5c6b7f;
  --line: #e2e8f0;
  --good: #1da851;
  --warn: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 34, 64, .08), 0 8px 24px rgba(15, 34, 64, .06);
  --header-h: 72px;
  /* Height the subject row takes out of the preview column at desktop density,
     measured rather than guessed — the preview must still fit without the page
     itself scrolling. */
  --subject-h: 53px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--surface);
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -.02em; margin: 0; }

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--navy);
  border-bottom: 3px solid var(--primary);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  min-height: var(--header-h);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.av-logo { height: 22px; width: auto; color: #fff; flex: none; }

.header-divider {
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, .25);
  flex: none;
}

.header-title {
  color: #fff;
  font-size: 1.0625rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.header-title span {
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--primary);
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 12px;
  align-items: center;
}

.ghost-btn, .primary-btn {
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  padding: .6rem 1.25rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s, transform .2s;
}

.ghost-btn {
  background: transparent;
  color: rgba(255, 255, 255, .85);
  border: 1px solid rgba(255, 255, 255, .3);
}

.ghost-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }

.primary-btn {
  background: var(--accent);
  color: var(--navy);
  border: 1px solid var(--accent);
  padding: .6rem 1.6rem;
}

.primary-btn:hover { background: #e6b500; border-color: #e6b500; }
.primary-btn:active { transform: translateY(1px); }
.primary-btn.done { background: var(--good); border-color: var(--good); color: #fff; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */

.wrap { max-width: 1400px; margin: 0 auto; padding: 20px 24px; }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

/* grid children default to min-width:auto, which lets wide content push the page */
.grid > * { min-width: 0; }

/* Both columns hold their own scroll so the page itself never scrolls on
   desktop: the form stays put while the email is read, and vice versa. */
@media (min-width: 1024px) {
  .grid { grid-template-columns: minmax(340px, 400px) 1fr; }

  .col-form, .col-preview {
    position: sticky;
    top: calc(var(--header-h) + 20px);
  }

  .col-form {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - var(--header-h) - 40px);
  }

  .form-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
  }

}

/* ---------- form cards ---------- */

.form-scroll { display: grid; gap: 16px; align-content: start; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--primary-dark);
  margin-bottom: 12px;
}

.field { margin-bottom: 12px; }
.card > .field:last-child, .card > .row-2:last-child { margin-bottom: 0; }
.row-2 > .field:last-child { margin-bottom: 0; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.row-2 .field { margin-bottom: 0; }
@media (max-width: 479px) { .row-2 { grid-template-columns: 1fr; } .row-2 .field:empty { display: none; } }

label {
  display: block;
  font-weight: 700;
  font-size: .8125rem;
  margin-bottom: 4px;
  line-height: 1.35;
}

.hint {
  font-weight: 400;
  font-size: .75rem;
  color: var(--muted);
  letter-spacing: 0;
}

/* The percentage cap is a business rule, so it says so rather than silently
   rewriting what the agent typed. */
.hint.over { color: var(--warn); font-weight: 700; }

input[type="text"], input[type="date"], input[type="time"] {
  width: 100%;
  font: inherit;
  font-size: .9375rem;
  padding: .5rem .65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 40px;
}

input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(65, 165, 221, .2);
}

.input-wrap { position: relative; display: block; }

.input-wrap .prefix {
  position: absolute;
  left: .65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 700;
  font-size: .9375rem;
  pointer-events: none;
}

.input-wrap input { padding-left: 1.7rem; }

.input-wrap.pct .prefix { left: auto; right: .65rem; }
.input-wrap.pct input { padding-left: .65rem; padding-right: 1.7rem; }

/* Internal guidance for the agent. Deliberately styled unlike anything in the
   email so it never reads as customer copy — a test asserts it cannot leak. */
.note {
  margin: 10px 0 0;
  padding: .55rem .7rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: #fffaea;
  font-size: .75rem;
  line-height: 1.5;
  color: var(--muted);
}

.note strong { color: var(--navy); font-weight: 900; }

/* ---------- destination suggestions ---------- */

/* Replaces <datalist>, whose popup Chrome draws itself: it ignores page CSS,
   renders the option label in a washed-out grey, and cannot be reached by a
   headless test. This one is ordinary DOM, so it is both styleable and testable. */
.combo { position: relative; }

.combo-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 216px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(15, 34, 64, .16);
}

/* Flipped above the input when the form pane would otherwise clip the list. */
.combo-list.up { top: auto; bottom: calc(100% + 4px); }

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

.combo-item {
  padding: .45rem .6rem;
  border-radius: 5px;
  font-size: .9375rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--card);
  cursor: pointer;
}

.combo-item b { font-weight: 900; color: var(--primary-dark); }

.combo-item.active,
.combo-item:hover { background: var(--navy); color: #fff; }
.combo-item.active b, .combo-item:hover b { color: var(--accent); }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: .875rem;
  cursor: pointer;
  margin-bottom: 12px;
}

.toggle input { width: 18px; height: 18px; accent-color: var(--primary-dark); cursor: pointer; flex: none; }

/* The estimate toggle hides three separate elements rather than one wrapper,
   so the discount can share a row with the estimate while still standing on its
   own when no estimate is being given. */
.field[hidden], .note[hidden] { display: none; }

/* .row-2 sets display:grid, which would otherwise beat the hidden attribute. */
.row-2[hidden] { display: none; }

/* Paired ticks: the grid gap owns the spacing, so the labels' own bottom margin
   would double it and leave the row taller than a field row. Below 480px .row-2
   collapses to one column and they stack, which is why the margin comes back. */
.toggle-pair .toggle { margin-bottom: 0; }
@media (max-width: 479px) { .toggle-pair .toggle:first-child { margin-bottom: 12px; } }

/* A revealed sub-panel belongs to the tick above it. */
#customFields { margin-top: -2px; }

/* ---------- preview ---------- */

.preview-shell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--navy);
  color: #fff;
}

.preview-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }

.preview-label {
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.preview-meta {
  margin-left: auto;
  font-size: .8125rem;
  color: rgba(255, 255, 255, .7);
}

/* ---------- subject line ----------
   Deliberately outside #preview: everything inside that node is the clipboard
   payload for the email body, and the subject belongs in Gmail's own subject
   field. It is copied by its own button. */

.subject-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.subject-tag {
  flex: none;
  font-size: .6875rem;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Wraps rather than truncating — an agent checking the subject needs to read
   all of it, and an ellipsis at 320px would hide most of it. */
.subject-text {
  flex: 1 1 240px;
  min-width: 0;
  font-size: .9375rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--navy);
  word-break: break-word;
  overflow-wrap: break-word;
}

.copy-chip {
  flex: none;
  font: inherit;
  font-size: .8125rem;
  font-weight: 700;
  min-height: 44px;
  padding: .5rem 1.1rem;
  border-radius: 6px;
  background: var(--navy);
  color: #fff;
  border: 1px solid var(--navy);
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .2s;
}

.copy-chip:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.copy-chip:active { transform: translateY(1px); }
.copy-chip.done { background: var(--good); border-color: var(--good); }

/* The email caps itself at 680px. On a wide monitor that left it hugging the
   left edge of a much wider pane; centring balances it. This styles the preview
   container only — innerHTML, and therefore the clipboard payload, is untouched. */
#preview > div { margin-left: auto; margin-right: auto; }

.preview-scroll {
  max-height: calc(100vh - var(--header-h) - var(--subject-h) - 84px);
  overflow: auto;
  padding: 20px;
  background: #eef2f6;
}

@media (max-width: 1023px) {
  .preview-scroll { max-height: none; }
}

/* The rendered email is styled entirely by its own inline attributes so that
   what is copied is exactly what is seen. Nothing here may style its internals. */
.email-render {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(15, 34, 64, .12);
  padding: 28px;
}

@media (max-width: 479px) {
  .wrap { padding: 16px; }
  .preview-scroll { padding: 14px; }
  .email-render { padding: 18px; }
  .header-actions { width: 100%; }
  .header-actions .primary-btn { flex: 1; }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 16px);
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  padding: .85rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(15, 34, 64, .3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 50;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }

/* ---------- desktop density ---------- */

@media (min-width: 1024px) {
  /* Denser on desktop, where the form competes with the preview for height and
     everything is driven by a mouse. Mobile keeps the roomier metrics so the
     inputs stay comfortable touch targets. */
  .form-scroll { gap: 8px; }

  .card { padding: 10px 14px; }
  .card-title { margin-bottom: 6px; }

  .field { margin-bottom: 8px; }
  .row-2 { gap: 10px; margin-bottom: 8px; }

  label { margin-bottom: 3px; font-size: .78125rem; }

  input[type="text"] {
    min-height: 34px;
    padding: .3rem .6rem;
    font-size: .90625rem;
  }

  .input-wrap input { padding-left: 1.6rem; }
  .input-wrap.pct input { padding-left: .6rem; padding-right: 1.6rem; }
  .input-wrap .prefix { left: .6rem; font-size: .875rem; }
  .input-wrap.pct .prefix { left: auto; right: .6rem; }

  .toggle { margin-bottom: 9px; gap: 8px; }

  .note { margin-top: 8px; padding: .45rem .6rem; }

  .subject-row { padding: 9px 20px; }
  .copy-chip { min-height: 34px; padding: .3rem .9rem; }
}
