/**
 * Invoice & Quote Builder — split-pane live preview layout.
 * Scoped under .iv-* so it never fights the global design system in style.css.
 * Tokens match :root in style.css (--navy, --teal, --gold, --grey-*, --radius).
 */

.iv-builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
  gap: 1.25rem;
  align-items: start;
}

.iv-editor { min-width: 0; }

.iv-preview-pane {
  position: sticky;
  top: 1rem;
  background: var(--grey-100);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 100px);
  box-shadow: var(--shadow);
}

.iv-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .65rem 1rem;
  background: var(--navy);
  color: var(--white);
  font-size: .8rem;
  font-weight: 600;
}

.iv-preview-toolbar .iv-live-total {
  color: var(--teal-bright);
}

.iv-preview-scroll {
  overflow: auto;
  padding: 1rem;
  flex: 1;
}

.iv-preview-paper {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.25rem 1.1rem;
  min-height: 420px;
}

.iv-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--grey-500);
  margin: 0 0 .55rem;
}

.iv-pro-link {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--teal);
  text-decoration: none;
}

.iv-pro-link:hover,
.iv-pro-link:focus-visible {
  text-decoration: underline;
}

.iv-pro-link:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.iv-theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem;
}

.iv-theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: .35rem;
  padding: .45rem;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  background: var(--white);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.iv-theme-swatch:hover {
  border-color: var(--teal);
}

.iv-theme-swatch:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.iv-theme-swatch.is-active {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(15, 110, 86, 0.18);
}

.iv-theme-swatch.is-locked {
  opacity: .72;
}

.iv-theme-swatch__chip {
  display: block;
  height: 28px;
  border-radius: calc(var(--radius) - 1px);
  background: linear-gradient(110deg, var(--swatch) 0 55%, var(--swatch2) 55% 100%);
}

.iv-theme-swatch__name {
  font-size: .72rem;
  font-weight: 600;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-wrap: wrap;
}

.iv-font-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}

.iv-font-chip {
  border: 1.5px solid var(--grey-200);
  background: var(--white);
  border-radius: var(--radius);
  padding: .4rem .75rem;
  font-size: .8rem;
  cursor: pointer;
  color: var(--navy);
  transition: border-color var(--transition), background var(--transition);
}

.iv-font-chip:hover {
  border-color: var(--teal);
}

.iv-font-chip:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.iv-font-chip.is-active {
  border-color: var(--teal);
  background: #f0fdf9;
  font-weight: 600;
}

.iv-font-chip.is-locked { opacity: .7; }

.iv-pro-pill {
  display: inline-flex;
  align-items: center;
  gap: .15rem;
  font-size: .65rem;
  font-weight: 700;
  color: var(--gold);
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: .05rem .35rem;
  letter-spacing: 0;
  text-transform: none;
}

.iv-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.iv-items-table th {
  text-align: left;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--grey-500);
  padding: .35rem .35rem .45rem;
  border-bottom: 1px solid var(--grey-200);
}

.iv-items-table td {
  padding: .3rem .25rem;
  vertical-align: middle;
}

.iv-items-table .form-input {
  width: 100%;
  font-size: .85rem;
  padding: .45rem .55rem;
}

.iv-row-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  color: var(--red);
  cursor: pointer;
  padding: .35rem;
  border-radius: var(--radius);
  line-height: 0;
}

.iv-row-del svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
}

.iv-row-del:hover {
  background: #fef2f2;
}

.iv-row-del:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* Status labels — colour + word (never colour alone). */
.iv-status {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: .15rem .45rem;
  border-radius: var(--radius);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.iv-status--draft { background: var(--grey-100); color: var(--grey-600); }
.iv-status--sent { background: #e0f2fe; color: #0369a1; }
.iv-status--paid,
.iv-status--accepted { background: #dcfce7; color: #166534; }
.iv-status--overdue,
.iv-status--declined { background: #fee2e2; color: #991b1b; }
.iv-status--closed { background: var(--grey-200); color: var(--grey-600); }

/* Logo crop modal */
.iv-crop-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 43, 79, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.iv-crop-modal[hidden] { display: none !important; }

.iv-crop-dialog {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.iv-crop-dialog h3 {
  margin: 0 0 .35rem;
  color: var(--navy);
  font-size: 1.05rem;
}

.iv-crop-dialog p {
  margin: 0 0 .85rem;
  font-size: .85rem;
  color: var(--grey-500);
}

.iv-crop-canvas {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  border-radius: var(--radius);
  cursor: grab;
  touch-action: none;
  background: var(--grey-800);
}

.iv-crop-canvas:active { cursor: grabbing; }

.iv-crop-zoom {
  width: 100%;
  margin: .85rem 0 1rem;
}

.iv-crop-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}

.iv-logo-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.iv-logo-preview {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
}

.iv-share {
  display: inline-block;
  position: relative;
}

.iv-share > summary {
  list-style: none;
  cursor: pointer;
}

.iv-share > summary::-webkit-details-marker { display: none; }

.iv-share-menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 5;
  margin-top: .25rem;
  min-width: 8.5rem;
  padding: .45rem .55rem;
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md, 0 8px 24px rgba(15, 43, 79, 0.12));
  display: flex;
  flex-direction: column;
  gap: .35rem;
  align-items: stretch;
}

.iv-share-menu a,
.iv-share-menu button {
  text-align: left;
  font-size: .8rem;
  font-weight: 600;
  color: var(--teal);
  background: none;
  border: 0;
  padding: .15rem 0;
  cursor: pointer;
  text-decoration: none;
}

.iv-status-form { margin: 0; }

.iv-status-select {
  font-size: .78rem;
  padding: .25rem .4rem;
  border-radius: var(--radius);
  border: 1px solid var(--grey-200);
  background: var(--white);
  color: var(--navy);
  max-width: 9rem;
}

.iv-doc-link {
  color: var(--teal);
  font-weight: 600;
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  font-size: .85rem;
  cursor: pointer;
  font-family: inherit;
}

.iv-doc-link:hover { text-decoration: underline; }

.iv-doc-link:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.iv-doc-link--danger { color: var(--red); }

.iv-doc-sep { color: var(--grey-200); }

@media (max-width: 959px) {
  .iv-builder {
    grid-template-columns: 1fr;
  }
  .iv-preview-pane {
    position: relative;
    top: 0;
    max-height: none;
    order: -1;
  }
  .iv-preview-scroll {
    max-height: 420px;
  }
  .iv-theme-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
