/* ── Top nav ── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--slate-900);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.topnav-brand {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -.3px;
  color: #fff;
  text-decoration: none;
}

.topnav-brand span { color: var(--accent); }

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

/* ── Builder layout ── */
.builder-wrap {
  display: grid;
  grid-template-columns: 420px 1fr;
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ── Form panel ── */
.form-panel {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--slate-100);
  border-right: 1px solid var(--slate-200);
}

/* ── Template picker ── */
.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}

.tpl-card {
  border: 2px solid var(--slate-200);
  border-radius: var(--radius);
  padding: 8px 6px 6px;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, box-shadow .15s;
  background: #fff;
  position: relative;
}

.tpl-card:hover { border-color: var(--accent); }

.tpl-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}

.tpl-card.premium {
  cursor: default;
  opacity: .65;
}

.tpl-thumb {
  width: 100%;
  aspect-ratio: 0.707; /* A4 ratio */
  background: var(--slate-100);
  border-radius: 3px;
  margin-bottom: 5px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .6rem;
  color: var(--slate-400);
}

.tpl-thumb img { width: 100%; height: 100%; object-fit: cover; }

.tpl-name {
  font-size: .7rem;
  font-weight: 600;
  color: var(--slate-600);
}

.lock-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  background: var(--slate-700);
  color: #fff;
  font-size: .55rem;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: .3px;
}

/* ── Line items ── */
.line-items-header {
  display: grid;
  grid-template-columns: 1fr 70px 90px 90px 36px;
  gap: 6px;
  padding: 0 2px 4px;
}

.line-items-header span {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--slate-400);
}

.line-item-row {
  display: grid;
  grid-template-columns: 1fr 70px 90px 90px 36px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.line-item-row input { font-size: .85rem; }

.line-item-amount {
  font-size: .85rem;
  font-weight: 600;
  color: var(--slate-700);
  text-align: right;
  padding: 8px 10px;
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
}

/* ── Totals summary ── */
.totals-summary {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--slate-200);
}

.totals-row {
  display: flex;
  justify-content: space-between;
  width: 220px;
  font-size: .88rem;
  color: var(--slate-600);
}

.totals-row.grand {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  border-top: 1.5px solid var(--accent);
  padding-top: 6px;
  margin-top: 4px;
}

/* ── Preview panel ── */
.preview-panel {
  overflow-y: auto;
  background: var(--slate-200);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  gap: 0;
}

.preview-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--slate-400);
  margin-bottom: 12px;
  align-self: flex-start;
  padding-left: 4px;
}

.preview-page {
  width: 100%;
  max-width: 680px;
  aspect-ratio: 0.707;
  background: #fff;
  box-shadow: var(--shadow-lg);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.preview-page iframe {
  width: 794px;  /* A4 at 96dpi */
  height: 1123px;
  border: none;
  transform-origin: top left;
  display: block;
}

/* ── Mobile tab toggle (hidden on desktop) ── */
.mobile-tabs { display: none; }

/* ── Mobile layout ── */
@media (max-width: 860px) {
  .builder-wrap {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    overflow: visible;
  }

  .mobile-tabs {
    display: flex;
    background: var(--slate-900);
    border-bottom: 1px solid var(--slate-700);
  }

  .mobile-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    font-size: .85rem;
    font-weight: 600;
    color: var(--slate-400);
    cursor: pointer;
    border-bottom: 2px solid transparent;
  }

  .mobile-tab.active {
    color: #fff;
    border-bottom-color: var(--accent);
  }

  .form-panel  { height: auto; }
  .preview-panel { height: 70vw; min-height: 320px; }

  .preview-panel.hidden,
  .form-panel.hidden { display: none; }
}
