/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: #1a1a2e; background: #f4f6f9; line-height: 1.5; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navbar ===== */
.navbar { display: flex; align-items: center; gap: 2rem; background: #1e3a5f; color: #fff; padding: 0.75rem 1.5rem; }
.navbar-brand { font-size: 1.1rem; font-weight: 700; color: #fff; }
.navbar-brand:hover { text-decoration: none; color: #93c5fd; }
.nav-links { display: flex; gap: 1rem; list-style: none; }
.nav-links a { color: #cbd5e1; font-size: 0.9rem; }
.nav-links a:hover { color: #fff; text-decoration: none; }
.navbar-toggle { display: none; } /* shown only on mobile via @media below */

/* ===== Layout ===== */
.main-content { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: #1e3a5f; }
.header-actions { display: flex; gap: 0.5rem; }

/* ===== Buttons ===== */
.btn { display: inline-block; padding: 0.4rem 0.9rem; border-radius: 4px; font-size: 0.85rem; font-weight: 500; cursor: pointer; border: none; transition: background 0.15s; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; text-decoration: none; color: #fff; }
.btn-secondary { background: #e2e8f0; color: #374151; }
.btn-secondary:hover { background: #cbd5e1; text-decoration: none; color: #374151; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; text-decoration: none; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

/* ===== Tables ===== */
.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 6px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.data-table th { background: #1e3a5f; color: #fff; padding: 0.6rem 0.75rem; text-align: left; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.data-table td { padding: 0.55rem 0.75rem; border-bottom: 1px solid #e2e8f0; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tfoot td { background: #f1f5f9; font-weight: 600; }
.mini-table { border-collapse: collapse; font-size: 0.85rem; }
.mini-table td { padding: 0.2rem 0.5rem; }

/* ===== Cards ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: #fff; border-radius: 6px; padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); border-top: 3px solid #1e3a5f; }
.stat-card-good { border-top-color: #16a34a; }
.stat-card-fair { border-top-color: #ca8a04; }
.stat-card-poor { border-top-color: #dc2626; }
.stat-label { font-size: 0.75rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: #1e3a5f; margin-top: 0.25rem; }
.benchmark-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.benchmark-card { background: #fff; border-radius: 6px; padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.benchmark-card h3 { font-size: 0.8rem; font-weight: 700; color: #1e3a5f; margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.detail-card { background: #fff; border-radius: 6px; padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.detail-card h3 { font-size: 0.85rem; font-weight: 700; color: #1e3a5f; margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
dl { display: grid; grid-template-columns: 1fr 1.5fr; gap: 0.25rem 0.75rem; }
dt { font-size: 0.8rem; color: #64748b; }
dd { font-size: 0.85rem; color: #1a1a2e; }
.notes-card { background: #fff; border-radius: 6px; padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 1.5rem; }
.notes-card h3 { font-size: 0.85rem; font-weight: 700; color: #1e3a5f; margin-bottom: 0.5rem; text-transform: uppercase; }
.form-card { background: #fff; border-radius: 6px; padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); max-width: 700px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: #374151; margin-bottom: 0.3rem; }
.form-group input[type=text], .form-group input[type=number], .form-group input[type=date],
.form-group input[type=email], .form-group select, .form-group textarea {
  width: 100%; padding: 0.45rem 0.6rem; border: 1px solid #d1d5db; border-radius: 4px; font-size: 0.9rem; background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}
.has-error input, .has-error select, .has-error textarea { border-color: #dc2626; }
.error-msg { display: block; color: #dc2626; font-size: 0.8rem; margin-top: 0.2rem; }
.help-text { font-size: 0.8rem; color: #64748b; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 4px; font-size: 0.75rem; font-weight: 600; }
.badge-good { background: #dcfce7; color: #166534; }
.badge-fair { background: #fef9c3; color: #854d0e; }
.badge-poor { background: #fee2e2; color: #991b1b; }
.badge-secondary { background: #e2e8f0; color: #475569; }
.condition-summary { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; }
.condition-display { display: inline-block; padding: 0.5rem 1rem; border-radius: 6px; font-size: 1.1rem; font-weight: 700; }
.score { font-size: 0.85rem; font-weight: 400; margin-left: 0.5rem; }

/* ===== Estimate Editor ===== */
.estimate-editor input[type=text], .estimate-editor input[type=number] {
  width: 100%; padding: 0.3rem 0.4rem; border: 1px solid #d1d5db; border-radius: 3px; font-size: 0.82rem;
}
.estimate-editor select { width: 100%; padding: 0.3rem; border: 1px solid #d1d5db; border-radius: 3px; font-size: 0.82rem; }
.item-name-input { min-width: 180px; }
.qty-input, .price-input { max-width: 80px; }
.line-total { font-weight: 600; white-space: nowrap; }
.row-actions { white-space: nowrap; }
.editor-actions { margin-top: 1rem; }
.autocomplete-results { position: absolute; z-index: 100; background: #fff; border: 1px solid #d1d5db; border-radius: 4px; max-height: 200px; overflow-y: auto; }
.autocomplete-results div { padding: 0.4rem 0.6rem; cursor: pointer; font-size: 0.85rem; }
.autocomplete-results div:hover { background: #f1f5f9; }

/* ===== Ratings Table ===== */
.ratings-table .notes-field { width: 100%; padding: 0.25rem; border: 1px solid #d1d5db; border-radius: 3px; }

/* ===== Messages ===== */
.messages { margin-bottom: 1rem; }
.message { padding: 0.6rem 1rem; border-radius: 4px; margin-bottom: 0.5rem; font-size: 0.9rem; }
.message-success { background: #dcfce7; color: #166534; }
.message-error { background: #fee2e2; color: #991b1b; }
.message-warning { background: #fef9c3; color: #854d0e; }
.message-info { background: #dbeafe; color: #1e40af; }

/* ===== Resolve screen ===== */
.resolve-intro { color: #475569; margin-bottom: 1.5rem; max-width: 700px; }
.resolve-section { margin-bottom: 2rem; }
.resolve-section h2 { font-size: 1rem; font-weight: 700; color: #1e3a5f; margin-bottom: 0.75rem; border-bottom: 2px solid #e2e8f0; padding-bottom: 0.4rem; }
.resolve-row { background: #fff; border-radius: 6px; padding: 0.9rem 1rem; margin-bottom: 0.75rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.resolve-raw { font-family: monospace; font-size: 0.9rem; font-weight: 700; color: #1e3a5f; margin-bottom: 0.6rem; }
.resolve-context { font-family: sans-serif; font-size: 0.75rem; font-weight: 400; color: #64748b; margin-left: 0.5rem; }
.resolve-options { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.resolve-option { display: flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0.75rem; border: 1px solid #d1d5db; border-radius: 4px; cursor: pointer; background: #f8fafc; font-size: 0.85rem; }
.resolve-option:has(input:checked) { background: #dbeafe; border-color: #2563eb; }
.resolve-option input { cursor: pointer; }
.resolve-skip { color: #64748b; }
.resolve-match { color: #1a1a2e; }
.resolve-type-hint { color: #64748b; font-size: 0.78rem; }
.resolve-score { display: inline-block; background: #dcfce7; color: #166534; font-size: 0.72rem; font-weight: 600; padding: 0.1rem 0.4rem; border-radius: 10px; margin-left: 0.3rem; }
.resolve-no-suggestions { font-size: 0.82rem; color: #94a3b8; font-style: italic; }

/* ===== Preview inline overrides ===== */
.preview-override-type, .preview-override-subtype { font-size: 0.8rem; padding: 0.25rem 0.4rem; border: 1px solid #f97316; border-radius: 3px; background: #fff7ed; width: 100%; }
.alias-checkbox-label { display: block; font-size: 0.75rem; color: #64748b; margin-top: 0.3rem; white-space: nowrap; cursor: pointer; }
.alias-checkbox-label input { margin-right: 0.3rem; }

/* ===== Preview ===== */
.row-error { background: #fff5f5 !important; }
.table-scroll { overflow-x: auto; margin-bottom: 1.5rem; }
.preview-table th, .preview-table td { font-size: 0.8rem; }

/* ===== Column alignment ===== */
.align-left { text-align: left; }
.align-right { text-align: right; white-space: nowrap; }
.data-table th.align-right { text-align: right; }

/* ===== Estimate column widths ===== */
col.col-item { width: 30%; }
col.col-qty  { width: 6%; }
col.col-unit { width: 5%; }
col.col-phase { width: 10%; }
col.col-total { width: 10%; }

/* ===== Estimate Groups ===== */
.estimate-group { margin-bottom: 1.5rem; }
.estimate-group-header { display: flex; justify-content: space-between; align-items: center; background: #1e3a5f; color: #fff; padding: 0.5rem 0.75rem; border-radius: 4px 4px 0 0; }
.estimate-group-title { font-weight: 700; font-size: 0.9rem; }
.estimate-group-total { font-weight: 700; font-size: 0.9rem; }
.estimate-group .data-table { border-radius: 0 0 4px 4px; }
.estimate-group .data-table th { background: #2d5282; }
.estimate-grand-total { display: flex; justify-content: space-between; align-items: center; background: #1e3a5f; color: #fff; padding: 0.6rem 0.75rem; border-radius: 4px; font-weight: 700; font-size: 1rem; margin-top: 0.5rem; }
.location-badge { display: inline-block; background: #dbeafe; color: #1e40af; padding: 0.1rem 0.5rem; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.row-immediate { background: #fff5f5 !important; }
.col-immediate { background: #fff5f5; color: #991b1b; }
.data-table th.col-immediate { background: #b91c1c; color: #fff; }
.subtotal-row td { background: #f1f5f9; border-top: 2px solid #cbd5e1; }
.grand-total-table { margin-top: 0.25rem; }
.grand-total-row td { background: #1e3a5f; color: #fff; font-weight: 700; font-size: 0.9rem; padding: 0.6rem 0.75rem; }

/* ===== Responsive ===== */
/* ===== Checkbox size — apply globally so compare checkboxes are usable ===== */
input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

/* ===== Portfolio mobile cards ===== */
.portfolio-cards { display: none; }
.portfolio-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
  border-left: 4px solid #1e3a5f;
}
.portfolio-card.rr-flag { border-left-color: #dc2626; background: #fff5f5; }
.portfolio-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem; }
.portfolio-card-name { font-weight: 700; font-size: 1rem; color: #1e3a5f; }
.portfolio-card-rank { font-size: 0.75rem; color: #94a3b8; margin-top: 0.15rem; }
.portfolio-card-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem 1rem; font-size: 0.82rem; }
.portfolio-card-metric dt { color: #64748b; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 0.3rem; }
.portfolio-card-metric dd { font-weight: 600; color: #1a1a2e; margin: 0; }
.portfolio-card-footer { margin-top: 0.65rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ===== Ratings card grid (replaces table on all sizes, 2-col on desktop) ===== */
.ratings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.rating-card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); padding: 1rem 1.1rem; }
.rating-card-title { font-weight: 700; font-size: 0.9rem; color: #1e3a5f; margin-bottom: 0.75rem; padding-bottom: 0.4rem; border-bottom: 1px solid #e2e8f0; }
.rating-card label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; margin: 0.6rem 0 0.3rem; }
.rating-card select, .rating-card input[type="text"] { width: 100%; padding: 0.4rem 0.5rem; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 0.9rem; }
.rating-btn-group { display: flex; gap: 0.4rem; }
.rating-btn { flex: 1; min-height: 40px; border: 2px solid #e2e8f0; background: #fff; border-radius: 4px; font-size: 0.82rem; font-weight: 600; cursor: pointer; transition: all 0.1s; color: #374151; }
.rating-btn:hover { border-color: #94a3b8; }
.rating-btn.active-good  { background: #dcfce7; border-color: #16a34a; color: #15803d; }
.rating-btn.active-fair  { background: #fef9c3; border-color: #ca8a04; color: #a16207; }
.rating-btn.active-poor  { background: #fee2e2; border-color: #dc2626; color: #b91c1c; }
.rating-concern-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; font-size: 0.85rem; color: #374151; }
.rating-concern-row input[type="checkbox"] { width: 18px; height: 18px; margin: 0; }

@media (max-width: 768px) {
  /* Navbar */
  .navbar { flex-wrap: wrap; gap: 0.5rem; padding: 0.6rem 1rem; }
  .navbar-brand { flex: 1; }
  .nav-links { display: none; width: 100%; flex-direction: column; gap: 0; padding: 0.5rem 0; }
  .nav-links.open { display: flex; }
  .nav-links li { border-top: 1px solid rgba(255,255,255,0.1); }
  .nav-links a { display: block; padding: 0.6rem 0.25rem; font-size: 1rem; }
  .navbar-toggle { display: flex; align-items: center; background: none; border: 1px solid rgba(255,255,255,0.4); color: #fff; padding: 0.4rem 0.75rem; border-radius: 4px; cursor: pointer; font-size: 1.1rem; min-height: 44px; }
  .navbar form { width: 100%; display: flex; justify-content: flex-end; }

  /* Content */
  .main-content { padding: 1rem 0.75rem; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .page-header .header-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; width: 100%; }
  .page-header .header-actions .btn { flex: 1; min-width: 120px; }

  /* Grids */
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .benchmark-grid, .analytics-grid { grid-template-columns: 1fr; }
  .analytics-card-wide { grid-column: span 1; }
  .detail-grid { grid-template-columns: 1fr; }

  /* Tables: horizontal scroll wrapper */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 6px; }
  .data-table { white-space: nowrap; }

  /* Touch targets */
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-sm { min-height: 36px; }
  select, input[type="text"], input[type="number"], input[type="date"], textarea {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  /* Portfolio: hide table, show cards */
  .portfolio-cards + table.data-table { display: none; }
  .portfolio-cards { display: block; }

  /* Charts: shorter on mobile to avoid burying content */
  .chart-container { height: 200px !important; }

  /* Forms */
  .form-card { max-width: 100%; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }

  /* Compare actions in structure detail */
  #compare-actions { width: 100%; }

  .condition-summary { flex-wrap: wrap; }
}

/* ===== Analytics ===== */
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 0.5rem; }
.analytics-card { background: #fff; border-radius: 6px; padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.analytics-card h3 { font-size: 0.85rem; font-weight: 700; color: #1e3a5f; margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.analytics-card-wide { grid-column: span 2; }

h2 { font-size: 1.1rem; font-weight: 700; color: #1e3a5f; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 0.95rem; }
h4 { font-size: 0.85rem; font-weight: 600; margin: 0.75rem 0 0.4rem; }
