:root {
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-muted: #f1f5f0;
  --ink: #17211b;
  --muted: #5b6b61;
  --line: #d8e0d8;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --warn-bg: #fff7ed;
  --warn-line: #fed7aa;
  --warn-text: #7c2d12;
  --shadow: 0 10px 25px rgba(23, 33, 27, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.page-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 16px;
}

.back-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

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

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

h1 {
  margin-bottom: 6px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

.subtitle {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
}

.header-actions,
.actions-row,
.preview-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.small-btn {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 800;
}

.primary-btn {
  color: #ffffff;
  background: var(--accent);
}

.primary-btn:hover {
  background: var(--accent-dark);
}

.secondary-btn,
.ghost-btn,
.small-btn {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.secondary-btn:hover,
.ghost-btn:hover,
.small-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  line-height: 1.5;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.85fr) minmax(460px, 1.15fr);
  gap: 18px;
  align-items: start;
}

.editor,
.preview-wrap {
  min-width: 0;
}

.panel,
.preview-wrap {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-title {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.panel-title span {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: var(--accent);
  border-radius: 8px;
  font-weight: 800;
}

.panel-title h2 {
  margin: 0;
  font-size: 18px;
}

.row-title {
  justify-content: space-between;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.two-col,
.three-col,
.template-grid {
  display: grid;
  gap: 12px;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.template-grid {
  grid-template-columns: minmax(220px, 0.8fr) minmax(220px, 1.2fr);
  align-items: end;
}

.helper-note {
  min-height: 44px;
  padding: 11px 12px;
  color: var(--muted);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}

.items {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.4fr) minmax(110px, 0.9fr) 70px 100px 38px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.item-row label {
  margin-bottom: 0;
}

.remove-row-btn {
  width: 38px;
  height: 38px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  background: #fff1f2;
  font-weight: 900;
}

.preview-wrap {
  position: sticky;
  top: 12px;
}

.preview-toolbar {
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.quote-preview {
  min-height: 720px;
  padding: 28px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #111827;
}

.quote-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 2px solid #111827;
}

.quote-head h2 {
  margin: 0 0 8px;
  font-size: 26px;
  text-transform: uppercase;
}

.quote-meta {
  min-width: 170px;
  text-align: right;
}

.quote-blocks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 18px 0;
}

.quote-block {
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
}

.quote-block h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
}

.quote-preview p {
  margin-bottom: 5px;
}

.quote-table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 13px;
}

.quote-table th,
.quote-table td {
  padding: 9px;
  border: 1px solid #d1d5db;
  text-align: left;
  vertical-align: top;
}

.quote-table th {
  background: #f3f4f6;
}

.quote-table td:nth-child(3),
.quote-table td:nth-child(4),
.quote-table td:nth-child(5),
.quote-table th:nth-child(3),
.quote-table th:nth-child(4),
.quote-table th:nth-child(5) {
  text-align: right;
}

.totals {
  width: min(100%, 320px);
  margin-left: auto;
  display: grid;
  gap: 8px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.grand-total {
  padding-top: 8px;
  border-top: 2px solid #111827;
  font-size: 18px;
  font-weight: 900;
}

.quote-notes,
.quote-terms {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid #d1d5db;
}

.signature-line {
  width: 190px;
  margin-top: 44px;
  margin-left: auto;
  padding-top: 8px;
  border-top: 1px solid #111827;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 1100;
  transform: translate(-50%, 80px);
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  color: #ffffff;
  background: #111827;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

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

.access-lock {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(17, 24, 39, 0.72);
  backdrop-filter: blur(8px);
}

.access-lock.show {
  display: flex;
}

.lock-card {
  width: min(100%, 420px);
  padding: 24px;
  text-align: center;
  background: #ffffff;
  border-radius: 8px;
}

.lock-icon {
  width: 54px;
  height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--accent);
  background: var(--surface-muted);
  border-radius: 8px;
  font-weight: 900;
}

.lock-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.lock-actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 800;
}

.lock-login {
  color: #ffffff;
  background: var(--accent);
}

.lock-home {
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

body.access-blocked #app {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

@media (max-width: 980px) {
  .app-header,
  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-wrap {
    position: static;
  }
}

@media (max-width: 680px) {
  .page-shell {
    padding: 12px;
  }

  .two-col,
  .three-col,
  .template-grid,
  .quote-blocks,
  .item-row {
    grid-template-columns: 1fr;
  }

  .quote-preview {
    padding: 16px;
  }

  .quote-head {
    display: block;
  }

  .quote-meta {
    margin-top: 12px;
    text-align: left;
  }
}

@page {
  size: A4;
  margin: 12mm;
}

@media print {
  body {
    background: #ffffff;
  }

  .trial-pill,
  .app-header,
  .notice,
  .editor,
  .preview-toolbar,
  .access-lock,
  .toast {
    display: none !important;
  }

  .page-shell,
  .workspace,
  .preview-wrap {
    display: block;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 0;
    box-shadow: none;
    border: 0;
  }

  .quote-preview {
    width: 186mm;
    min-height: 273mm;
    padding: 0;
    border: 0;
    border-radius: 0;
  }
}

body,
body * {
  letter-spacing: 0;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.25);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
