/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --brand: #6C22E1;
  --brand-light: #8B5CF6;
  --brand-dark: #4C1D95;
  --bg: #0D0D1A;
  --surface: #13131F;
  --surface2: #1A1A2E;
  --border: #2A2A40;
  --text: #E8E8F0;
  --muted: #7070A0;
  --accent: #A78BFA;
  --success: #10B981;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(108,34,225,0.12);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ===== LAYOUT ===== */
#app {
  display: flex;
  height: 100vh;
}

/* ===== SIDEBAR ===== */
#form-panel {
  width: 380px;
  min-width: 340px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  border-bottom: 1px solid var(--brand);
}
.panel-icon { width: 38px; height: 38px; object-fit: contain; }
.panel-title { font-family: 'Outfit', sans-serif; font-size: 16px; font-weight: 700; color: #fff; }
.panel-subtitle { font-size: 11px; color: rgba(255,255,255,0.6); }

/* ===== TABS ===== */
.form-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  padding: 0 4px;
  scrollbar-width: none;
}
.form-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  padding: 10px 12px;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all .2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--brand); }

/* ===== FORM CONTENT ===== */
.form-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--brand-light);
  margin: 16px 0 10px;
}
.section-label:first-child { margin-top: 0; }

.field-group { margin-bottom: 10px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 4px;
}

input, textarea, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  padding: 8px 10px;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  resize: vertical;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand-light);
  box-shadow: 0 0 0 3px rgba(108,34,225,0.18);
}
select option { background: var(--surface2); }

.add-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 7px;
  color: var(--accent);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  padding: 8px 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all .2s;
  margin-top: 6px;
}
.add-btn:hover { border-color: var(--brand-light); background: rgba(108,34,225,0.08); }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ===== DYNAMIC ITEMS (Scope, Timeline, Payment, Terms) ===== */
.dynamic-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  position: relative;
}
.dynamic-item .remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: #F87171;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: .6;
  transition: opacity .2s;
}
.dynamic-item .remove-btn:hover { opacity: 1; }
.dynamic-item input, .dynamic-item textarea, .dynamic-item select {
  margin-bottom: 6px;
}
.dynamic-item input:last-child,
.dynamic-item textarea:last-child,
.dynamic-item select:last-child { margin-bottom: 0; }
.item-row { display: grid; grid-template-columns: 2fr 1fr; gap: 6px; }

/* ===== PANEL ACTIONS ===== */
.panel-actions {
  display: flex;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.btn-primary, .btn-secondary {
  flex: 1;
  border: none;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 10px;
  transition: all .2s;
}
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-light)); color: #fff; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(108,34,225,0.4); }
.btn-secondary { background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--brand-light); }

/* ===== PREVIEW PANEL ===== */
#preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #1E1E30;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.preview-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.btn-icon {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all .2s;
}
.btn-icon:hover { border-color: var(--brand-light); }

#quote-document-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: #1a1a2e;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ===== QUOTATION DOCUMENT ===== */
#quote-document {
  max-width: 794px;
  margin: 0 auto;
}

.q-page {
  background: #fff;
  color: #1a1a2e;
  width: 794px;
  min-height: 1123px;
  padding: 48px;
  margin-bottom: 24px;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  position: relative;
  font-family: 'Inter', sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---- Q-HEADER ---- */
.q-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.q-logo { height: 72px; object-fit: contain; }
.q-company-info {
  text-align: right;
  font-size: 11px;
  color: #555;
  line-height: 1.7;
}
.q-divider-line {
  height: 3px;
  background: linear-gradient(90deg, #6C22E1, #A78BFA, transparent);
  border-radius: 2px;
  margin-bottom: 20px;
}

/* ---- Q-META ---- */
.q-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}
.q-meta-badge {
  background: linear-gradient(135deg, #6C22E1, #8B5CF6);
  border-radius: 12px;
  padding: 20px;
  color: #fff;
}
.q-meta-badge h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .12em;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.3);
  padding-bottom: 10px;
}
.q-meta-row { display: flex; gap: 8px; font-size: 12px; margin-bottom: 4px; }
.q-meta-label { opacity: .75; min-width: 80px; }
.q-meta-value { font-weight: 600; }

.q-client-block {
  background: #F5F3FF;
  border: 1px solid #DDD6FE;
  border-radius: 12px;
  padding: 18px;
}
.q-to-label { font-size: 10px; font-weight: 700; letter-spacing: .1em; color: #7C3AED; margin-bottom: 6px; }
.q-client-block h3 { font-size: 16px; font-weight: 700; color: #1a1a2e; margin-bottom: 2px; }
.q-client-company { font-size: 13px; font-weight: 600; color: #4C1D95; margin-bottom: 6px; }
.q-client-detail { font-size: 11.5px; color: #555; line-height: 1.6; }

/* ---- Q-SECTIONS ---- */
.q-section { margin-bottom: 24px; }
.q-section-header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #EDE9FE;
}
.q-section-icon { display: none; }
.q-section-header h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: #4C1D95;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.q-project-box {
  background: #F5F3FF;
  border-left: 4px solid #6C22E1;
  border-radius: 0 8px 8px 0;
  padding: 14px 16px;
}
.q-project-box h4 { font-size: 14px; font-weight: 700; color: #1a1a2e; margin-bottom: 4px; }
.q-project-box p { font-size: 12.5px; color: #444; line-height: 1.6; }

/* Scope Grid */
.q-scope-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.q-scope-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #FAFAFA;
  border: 1px solid #EDE9FE;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: #333;
}
.q-scope-item::before {
  content: '✓';
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  min-width: 18px;
  background: #6C22E1;
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  margin-top: 1px;
}

/* ---- PRICING TABLE ---- */
.q-pricing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.q-pricing-table thead tr {
  background: linear-gradient(135deg, #4C1D95, #6C22E1);
  color: #fff;
}
.q-pricing-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  letter-spacing: .04em;
  font-size: 11px;
  text-transform: uppercase;
}
.q-pricing-table th:last-child { text-align: right; }
.q-pricing-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #F0EDF9;
  color: #333;
}
.q-pricing-table td:last-child { text-align: right; font-weight: 600; }
.q-pricing-table tbody tr:nth-child(even) { background: #FAFAFA; }
.q-pricing-table tbody tr:hover { background: #F5F3FF; }

/* tfoot */
.q-pricing-table tfoot tr td {
  padding: 8px 14px;
  border-bottom: none;
  font-weight: 600;
}
.q-pricing-table .subtotal-row td { border-top: 1px solid #DDD6FE; color: #555; }
.q-pricing-table .discount-row td { color: #059669; }
.q-pricing-table .total-row {
  background: linear-gradient(135deg, #4C1D95, #6C22E1);
}
.q-pricing-table .total-row td { color: #fff; font-size: 14px; font-weight: 700; }

/* Maintenance */
.q-maintenance-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.q-maintenance-card {
  background: #F5F3FF;
  border: 1px solid #DDD6FE;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}
.q-maintenance-card h4 { font-size: 13px; font-weight: 700; color: #4C1D95; margin-bottom: 4px; }
.q-maintenance-card .plan-price { font-size: 18px; font-weight: 800; color: #6C22E1; }
.q-maintenance-card .plan-period { font-size: 10px; color: #888; }
.q-maintenance-card p { font-size: 11px; color: #555; margin-top: 6px; line-height: 1.5; }

/* ---- TIMELINE ---- */
.q-timeline { position: relative; padding-left: 20px; }
.q-timeline::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: linear-gradient(to bottom, #6C22E1, #A78BFA);
}
.q-timeline-item {
  position: relative;
  margin-bottom: 14px;
  padding-left: 18px;
}
.q-timeline-item::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 5px;
  width: 10px;
  height: 10px;
  background: #6C22E1;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px #6C22E1;
}
.q-timeline-item h4 { font-size: 13px; font-weight: 700; color: #1a1a2e; margin-bottom: 2px; }
.q-timeline-item .tl-duration { font-size: 11px; color: #6C22E1; font-weight: 600; margin-bottom: 2px; }
.q-timeline-item p { font-size: 11.5px; color: #555; line-height: 1.5; }

/* ---- PAYMENT GRID ---- */
.q-payment-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.q-payment-card {
  background: #F5F3FF;
  border: 1px solid #DDD6FE;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.q-payment-card .pay-percent { font-size: 22px; font-weight: 800; color: #6C22E1; }
.q-payment-card .pay-label { font-size: 11px; font-weight: 600; color: #333; margin: 2px 0; }
.q-payment-card .pay-when { font-size: 10px; color: #888; }
.q-payment-methods { font-size: 12px; color: #555; margin-top: 8px; }

/* ---- TERMS ---- */
.q-terms {
  padding-left: 18px;
}
.q-terms li {
  font-size: 12px;
  color: #333;
  margin-bottom: 8px;
  line-height: 1.6;
  padding-left: 4px;
}
.q-terms li::marker { color: #6C22E1; font-weight: 700; }

/* ---- SIGNATURE ---- */
.q-signature-section {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 20px;
  margin: 28px 0 20px;
  padding: 20px 0;
  border-top: 1px solid #EDE9FE;
  border-bottom: 1px solid #EDE9FE;
}
.q-sig-block { text-align: center; }
.q-sig-block.q-sig-right { text-align: center; }
.q-sig-line {
  height: 1px;
  background: #999;
  margin-bottom: 6px;
}
.q-sig-name { font-size: 13px; font-weight: 700; color: #1a1a2e; }
.q-sig-title { font-size: 11px; color: #6C22E1; }
.q-seal-center { display: flex; justify-content: center; align-items: center; }
.q-seal { width: 90px; height: 90px; object-fit: contain; opacity: .85; }

/* Footer note */
.q-footer-note {
  background: #F5F3FF;
  border-left: 3px solid #A78BFA;
  border-radius: 0 6px 6px 0;
  padding: 12px 16px;
  margin-bottom: 16px;
}
.q-footer-note p { font-size: 12px; color: #555; line-height: 1.6; font-style: italic; }

/* ---- PAGE TOPBAR (pages 2-4) ---- */
.q-page-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 2px solid #EDE9FE;
  font-size: 12px;
  font-weight: 600;
  color: #6C22E1;
}
.q-topbar-icon { width: 22px; height: 22px; object-fit: contain; }

/* ---- PAGE FOOTER ---- */
.q-page-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 14px;
  border-top: 1px solid #EDE9FE;
  font-size: 10px;
  color: #999;
}

/* ---- FINAL FOOTER ---- */
.q-final-footer {
  margin-top: auto;
  border-top: 2px solid #EDE9FE;
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.q-final-footer-inner { display: flex; align-items: center; gap: 16px; }
.q-footer-logo { height: 36px; object-fit: contain; }
.q-footer-links { display: flex; gap: 16px; font-size: 10px; color: #888; }
.q-page-number { font-size: 10px; color: #bbb; }

/* ===== PRINT ===== */
@media print {
  body { background: #fff; overflow: auto; }
  #form-panel, .preview-toolbar { display: none !important; }
  #preview-panel { overflow: visible; }
  #quote-document-wrap { padding: 0; background: #fff; overflow: visible; }
  #quote-document { max-width: 100%; }
  .q-page {
    box-shadow: none;
    border-radius: 0;
    margin-bottom: 0;
    page-break-after: always;
    padding: 36px;
    width: 100%;
    min-height: auto;
  }
}
