:root {
  --bg: #eef2f4;
  --bg-deep: #d9e2e8;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #5c6b7a;
  --line: #d3dde6;
  --primary: #1a365d;
  --primary-dark: #122844;
  --accent: #c98516;
  --accent-soft: #fff4e0;
  --danger: #b42318;
  --success: #0f7a4c;
  --shadow: 0 18px 40px rgba(26, 35, 50, 0.08);
  --radius: 14px;
  --font: "DM Sans", sans-serif;
  --display: "Libre Baskerville", Georgia, "Times New Roman", serif;
  --quote-navy: #1a365d;
  --quote-border: #cfd6de;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(15, 76, 129, 0.18), transparent 60%),
    radial-gradient(900px 420px at 100% 0%, rgba(201, 133, 22, 0.16), transparent 55%),
    linear-gradient(180deg, #f7fafc 0%, var(--bg) 45%, var(--bg-deep) 100%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background:
    linear-gradient(145deg, var(--primary) 0%, #1f6fad 55%, var(--accent) 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.brand-name {
  margin: 0;
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-tag {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.topbar-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.layout {
  width: min(1100px, calc(100% - 2rem));
  margin: 1.5rem auto 3rem;
  display: grid;
  gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem 1.4rem 1.5rem;
  animation: rise 0.45s ease both;
}

.panel:nth-child(2) { animation-delay: 0.05s; }
.panel:nth-child(3) { animation-delay: 0.1s; }
.panel:nth-child(4) { animation-delay: 0.15s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-head h2 {
  margin: 0 0 0.25rem;
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.panel-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head:not(.panel-head-row) {
  margin-bottom: 1rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1.05rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px rgba(15, 76, 129, 0.25);
}

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

.btn-secondary {
  background: var(--accent-soft);
  color: #7a4d00;
  border: 1px solid #efd5a0;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-danger {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #f3c1bc;
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
}

.btn-icon {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.45rem;
}

.upload-zone {
  border: 2px dashed #b7c7d6;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbfd, #f1f6fa);
  padding: 1.75rem 1.25rem;
  display: grid;
  justify-items: center;
  gap: 0.85rem;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.upload-zone.is-dragover {
  border-color: var(--primary);
  background: #eaf3fb;
}

.upload-copy {
  display: grid;
  gap: 0.2rem;
}

.upload-copy strong {
  font-size: 1.05rem;
}

.upload-copy span {
  color: var(--muted);
  font-size: 0.88rem;
}

.upload-status {
  margin-top: 1rem;
  display: none;
}

.upload-status.is-visible {
  display: block;
}

.file-chip {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: #f3f8fc;
  border: 1px solid #c9dceb;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.file-name {
  margin: 0;
  font-weight: 600;
}

.file-meta {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.field span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.field-full {
  grid-column: 1 / -1;
}

input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #7eaccf;
  box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.12);
}

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

.section-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.1rem 1.15rem 1.2rem;
  margin-bottom: 1.15rem;
  background: #fff;
}

.section-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.section-toolbar .field {
  flex: 1;
}

.quote-preview-frame {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.1rem;
  padding: 0.85rem 0.2rem 1rem;
  border-bottom: 1px solid #dde3ea;
}

.quote-preview-title {
  font-family: var(--display);
  font-size: 1.55rem;
  color: var(--quote-navy);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.quote-preview-meta {
  display: grid;
  gap: 0.15rem;
  text-align: right;
  color: var(--quote-navy);
  font-size: 0.92rem;
  font-weight: 500;
}

.quote-section-heading {
  margin: 0.35rem 0 0.65rem;
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--quote-navy);
}

.table-wrap {
  overflow-x: auto;
}

.quote-table-wrap {
  border: none;
  border-radius: 0;
}

.pricing-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.quote-table {
  min-width: 760px;
}

.quote-table th {
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: #fff;
  background: var(--quote-navy);
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--quote-navy);
}

.quote-table td {
  padding: 0.55rem 0.45rem;
  border: 1px solid var(--quote-border);
  vertical-align: middle;
  background: #fff;
}

.quote-table tr:last-child td {
  border-bottom: 1px solid var(--quote-border);
}

.quote-table input {
  padding: 0.55rem 0.65rem;
  border-radius: 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.quote-table input:focus {
  border-color: #9db4cc;
  background: #f7fafc;
  box-shadow: none;
}

.quote-table .col-item {
  width: auto;
  min-width: 180px;
}

.quote-table .col-qty {
  width: 100px;
}

.quote-table .col-cost,
.quote-table .col-vat,
.quote-table .col-total {
  width: 140px;
}

.quote-table .col-actions {
  width: 52px;
  text-align: center;
  background: #fff;
}

.quote-table th.col-actions {
  background: var(--quote-navy);
  border-color: var(--quote-navy);
}

.quote-table .btn-remove-row {
  min-width: 34px;
  padding: 0.35rem 0.55rem;
  font-size: 1.1rem;
  line-height: 1;
}

.row-total {
  display: block;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  padding: 0.35rem 0.65rem;
  color: #222;
}

.section-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}

.section-subtotal {
  font-weight: 600;
  color: var(--ink);
}

.section-subtotal span {
  color: var(--quote-navy);
  font-variant-numeric: tabular-nums;
}

.empty-sections {
  margin: 0 0 1rem;
  padding: 1.25rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  text-align: center;
  color: var(--muted);
  background: #f8fafb;
}

.empty-sections[hidden] {
  display: none !important;
}

.grand-total-bar {
  margin-top: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.95rem 1.1rem;
  border-radius: 12px;
  background: var(--quote-navy);
  color: #fff;
  font-size: 1rem;
}

.grand-total-bar strong {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.preview-stack {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.preview-stack li {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  padding: 0.95rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f8fafb;
}

.preview-stack strong {
  display: block;
}

.preview-stack p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.badge {
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  min-width: 64px;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.badge-mid {
  background: #1f6fad;
}

.badge-bottom {
  background: var(--accent);
  color: #2a1c00;
}

.result-box {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 12px;
  background: #ecf8f1;
  border: 1px solid #b7e0c8;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.result-box.is-visible {
  display: flex;
}

.result-box p {
  margin: 0;
  color: var(--success);
  font-weight: 600;
}

[hidden] {
  display: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 0.8rem 1.1rem;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: min(480px, calc(100% - 2rem));
  text-align: center;
}

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

.toast.error {
  background: var(--danger);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 34, 0.45);
  display: none;
  place-items: center;
  z-index: 60;
}

.overlay.is-open {
  display: grid;
}

.overlay[hidden] {
  display: none !important;
}

.spinner {
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem 1.75rem;
  display: grid;
  justify-items: center;
  gap: 0.85rem;
  min-width: 180px;
  box-shadow: var(--shadow);
}

.spinner-ring {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #d7e4ef;
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner p {
  margin: 0;
  font-weight: 600;
}

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

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions .btn {
    flex: 1;
  }

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

  .panel-head-row {
    flex-direction: column;
  }

  .section-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}
