/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a3a5c;
  --primary-light: #2a5a8c;
  --accent: #e67e22;
  --accent-dark: #c0651a;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #dde2e8;
  --text: #1e2a38;
  --text-muted: #6b7a8d;
  --success: #27ae60;
  --danger: #c0392b;
  --warning: #f39c12;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08), 0 2px 12px rgba(0,0,0,0.06);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   HEADER
   ============================================================ */
.site-header {
  background: var(--primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand { display: flex; align-items: baseline; gap: 0.75rem; }
.header-brand h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.01em; color: #fff; }
.header-tagline { font-size: 0.8rem; color: rgba(255,255,255,0.65); }
.header-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ============================================================
   DISCLAIMER BANNER
   ============================================================ */
.disclaimer-banner {
  background: #fff8e1;
  border-bottom: 1px solid #ffe082;
  color: #7d5100;
  text-align: center;
  padding: 0.5rem 1.5rem;
  font-size: 0.78rem;
}

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.main-layout {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.5rem;
  flex: 1;
  width: 100%;
}

.estimate-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
  align-items: start;
}

.estimate-main { min-width: 0; display: flex; flex-direction: column; gap: 1rem; }

/* ============================================================
   SCOPING PANEL
   ============================================================ */
.scoping-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.section-title { font-size: 1.25rem; font-weight: 700; color: var(--primary); margin-bottom: 0.4rem; }
.section-desc { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

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

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group.form-group-action { justify-content: flex-end; align-self: end; }

textarea, select, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}

textarea:focus, select:focus, input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(42,90,140,0.12);
}

textarea { resize: vertical; min-height: 110px; }
select { cursor: pointer; }

/* ============================================================
   LOADING & ERROR STATES
   ============================================================ */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  color: var(--text-muted);
}

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

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

.error-state {
  background: #fff0f0;
  border: 1px solid #ffcdd2;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  color: var(--danger);
  font-size: 0.88rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  padding: 0.65rem 1.5rem;
  font-size: 0.9rem;
}
.btn-primary:hover { background: var(--primary-light); }
.btn-primary:active { opacity: 0.9; }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
  padding: 0.6rem 1.25rem;
  font-size: 0.88rem;
}
.btn-secondary:hover { background: rgba(26,58,92,0.06); }

.btn-ghost {
  background: transparent;
  color: var(--primary-light);
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  border: 1.5px dashed var(--border);
}
.btn-ghost:hover { background: rgba(42,90,140,0.06); border-style: solid; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: none;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 400;
}
.btn-danger:hover { background: #fff0f0; }

.btn-lg { padding: 0.8rem 2rem; font-size: 1rem; }
.btn-sm { padding: 0.45rem 1rem; font-size: 0.82rem; }
.full-width { width: 100%; justify-content: center; }
.add-row-btn { margin-top: 0.5rem; }

/* ============================================================
   PROJECT SUMMARY CARD
   ============================================================ */
.summary-card {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow);
}
.summary-card h2 { font-size: 1.05rem; font-weight: 600; line-height: 1.45; }
.notes-text { font-size: 0.82rem; color: rgba(255,255,255,0.7); margin-top: 0.6rem; font-style: italic; line-height: 1.5; }

/* ============================================================
   MODULE CARDS
   ============================================================ */
.module-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1.5px solid transparent;
  transition: border-color 0.2s;
}
.module-card.is-included { border-color: var(--primary); }

.module-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  cursor: pointer;
  user-select: none;
  background: #f7f8fb;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.module-header:hover { background: #eef0f5; }

.module-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.module-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--primary);
}

.module-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
}

.module-total {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.module-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.toggle-included {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
}
.toggle-included input[type="checkbox"] { cursor: pointer; accent-color: var(--primary); width: 14px; height: 14px; }

.chevron {
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  display: inline-block;
}
.chevron.open { transform: rotate(180deg); }

.module-body {
  padding: 1.25rem;
  display: none;
}
.module-body.open { display: block; }

.module-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  margin-top: 1.25rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
.module-section-title:first-of-type { margin-top: 0; }

.module-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}

.price-notice {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #f7f8fb;
  border-left: 3px solid var(--accent);
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  border-radius: 0 4px 4px 0;
}

/* ============================================================
   DATA TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; margin: 0 -0.25rem; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table th {
  background: #f0f2f5;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid #f0f2f5;
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f9fafc; }

.data-table input[type="text"],
.data-table input[type="number"] {
  width: 100%;
  padding: 0.3rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 0.84rem;
  background: transparent;
}
.data-table input:hover { border-color: var(--border); }
.data-table input:focus { border-color: var(--primary-light); background: #fff; box-shadow: 0 0 0 2px rgba(42,90,140,0.1); }

.data-table input[type="number"] { text-align: right; }

.col-name { min-width: 150px; }
.col-unit { width: 70px; }
.col-qty { width: 80px; }
.col-price { width: 95px; }
.col-supplier { width: 130px; }
.col-total { width: 95px; text-align: right !important; }
.col-actions { width: 40px; text-align: center !important; }
.col-trade { min-width: 150px; }
.col-rate { width: 100px; }
.col-hours { width: 90px; }
.col-labour { width: 110px; text-align: right !important; }
.col-value { width: 110px; }

.supplier-link {
  color: var(--primary-light);
  text-decoration: none;
  font-size: 0.82rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.supplier-link:hover { text-decoration: underline; }

.line-total, .labour-total, .service-total {
  font-weight: 600;
  color: var(--text);
  text-align: right;
  white-space: nowrap;
}

.tooltip-rate { position: relative; }
.tooltip-rate .tooltip-text {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 0.72rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  width: 220px;
  text-align: center;
  z-index: 10;
  line-height: 1.4;
}
.tooltip-rate:hover .tooltip-text { display: block; }

/* Services table */
.services-table .col-type { width: 140px; }
.services-table .col-toggle { width: 70px; text-align: center; }

.type-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  width: fit-content;
}
.type-toggle button {
  padding: 0.25rem 0.55rem;
  border: none;
  background: transparent;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  transition: background 0.15s;
}
.type-toggle button.active { background: var(--primary); color: #fff; }

.service-enable { cursor: pointer; accent-color: var(--primary); width: 15px; height: 15px; }
.service-row.disabled td { opacity: 0.45; }
.service-row.disabled .service-enable { opacity: 1; }

/* ============================================================
   COST SUMMARY SIDEBAR
   ============================================================ */
.cost-summary {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.summary-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}

.summary-rows { display: flex; flex-direction: column; gap: 0.5rem; }

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  gap: 0.5rem;
}

.summary-row span:first-child { color: var(--text-muted); }
.summary-row span:last-child { font-weight: 600; color: var(--text); white-space: nowrap; }

.summary-subtotal {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}
.summary-subtotal span { font-weight: 700 !important; color: var(--text) !important; }

.summary-total {
  border-top: 2px solid var(--primary);
  padding-top: 0.6rem;
  margin-top: 0.25rem;
}
.summary-total span { font-size: 1rem; font-weight: 700 !important; color: var(--primary) !important; }

.contingency-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
}

.contingency-input {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  padding: 0.15rem 0.4rem;
  justify-content: center;
}
.contingency-input input {
  width: 42px;
  border: none;
  padding: 0;
  text-align: center;
  font-size: 0.82rem;
  background: transparent;
  box-shadow: none;
}
.contingency-input span { font-size: 0.82rem; color: var(--text-muted); }

.summary-disclaimer {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.5;
  font-style: italic;
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  background: var(--primary);
  color: rgba(255,255,255,0.5);
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  margin-top: 2rem;
}

/* ============================================================
   PDF PRINT STYLES
   ============================================================ */
.pdf-print {
  font-family: Arial, sans-serif;
  font-size: 11px;
  color: #1e2a38;
  padding: 20px;
}
.pdf-print h1 { font-size: 18px; color: #1a3a5c; margin-bottom: 4px; }
.pdf-print h2 { font-size: 13px; color: #1a3a5c; margin: 16px 0 6px; border-bottom: 1px solid #dde2e8; padding-bottom: 4px; }
.pdf-print h3 { font-size: 11px; color: #6b7a8d; text-transform: uppercase; letter-spacing: 0.04em; margin: 12px 0 4px; }
.pdf-print .summary { background: #1a3a5c; color: #fff; padding: 10px 14px; border-radius: 6px; margin: 10px 0; font-size: 10px; }
.pdf-print table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.pdf-print th { background: #f0f2f5; font-size: 9px; text-transform: uppercase; letter-spacing: 0.04em; padding: 4px 6px; text-align: left; border: 1px solid #dde2e8; }
.pdf-print td { padding: 3px 6px; border: 1px solid #dde2e8; font-size: 10px; }
.pdf-print .total-row td { font-weight: 700; background: #f7f8fb; }
.pdf-print .grand-total td { font-weight: 700; background: #1a3a5c; color: #fff; }
.pdf-print .disclaimer { font-size: 8px; color: #888; margin-top: 20px; border-top: 1px solid #dde2e8; padding-top: 8px; line-height: 1.5; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .estimate-layout {
    grid-template-columns: 1fr;
  }

  .cost-summary {
    position: static;
    order: -1;
  }

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

  .form-group.form-group-action { align-self: stretch; }
  .form-group.form-group-action .btn { width: 100%; justify-content: center; }
}

@media (max-width: 600px) {
  .main-layout { padding: 1rem; }
  .scoping-panel { padding: 1.25rem; }
  .module-body { padding: 0.75rem; }
  .header-brand h1 { font-size: 1.1rem; }
  .header-tagline { display: none; }

  .col-supplier, .col-total.mat { display: none; }
}
