/* Smart Electrical RAB System v2.0 — Custom Styles */

:root {
    --blue-600: #2563eb;
    --blue-700: #1d4ed8;
    --blue-50: #eff6ff;
    --green-50: #f0fdf4;
    --green-600: #16a34a;
    --green-700: #15803d;
    --red-50: #fef2f2;
    --red-600: #dc2626;
    --amber-50: #fffbeb;
    --amber-600: #d97706;
    --purple-50: #faf5ff;
    --purple-600: #9333ea;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    min-height: 100vh;
}

/* Header */
.header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 50;
}
.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.header-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--blue-600), var(--purple-600));
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 18px;
}
.header-title { font-size: 1.1rem; font-weight: 700; color: var(--gray-900); }
.header-subtitle { font-size: 0.7rem; color: var(--gray-500); margin-top: -2px; }
.header-badge { font-size: 0.7rem; color: var(--gray-400); }

/* Tab Buttons */
.tab-btn {
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 500;
    padding: 0.4rem 0.85rem;
    border-radius: 0.5rem;
    border: 1px solid var(--gray-200);
    background: white;
    color: var(--gray-500);
    cursor: pointer;
    transition: all 0.2s;
}
.tab-btn:hover { background: var(--gray-50); color: var(--gray-700); }
.tab-btn.active { background: var(--blue-600); color: white; border-color: var(--blue-600); }

/* Main Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Hero */
.hero { text-align: center; margin-bottom: 2rem; }
.hero h1 {
    font-size: 1.75rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--blue-600), var(--purple-600));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}
.hero p { color: var(--gray-500); max-width: 640px; margin: 0 auto; font-size: 0.9rem; line-height: 1.6; }

/* Cards */
.card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    border: 1px solid var(--gray-100);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.card-icon {
    width: 40px; height: 40px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

/* Info Banner */
.info-banner {
    background: var(--blue-50);
    border: 1px solid #bfdbfe;
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    color: #1e40af;
}
.info-banner .icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 1px; }

/* Success / Error Banners */
.success-banner {
    background: var(--green-50);
    border: 1px solid #bbf7d0;
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    color: #166534;
}
.error-banner {
    background: var(--red-50);
    border: 1px solid #fecaca;
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    color: #991b1b;
    display: none;
}

/* Textarea */
.input-textarea {
    width: 100%;
    height: 120px;
    padding: 0.75rem 1rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.75rem;
    resize: none;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--gray-800);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-textarea:focus {
    outline: none;
    border-color: var(--blue-600);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.input-textarea::placeholder { color: var(--gray-400); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: 0.75rem;
    font-weight: 500;
    font-size: 0.875rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--blue-600); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--blue-700); }
.btn-red { background: var(--red-600); color: white; }
.btn-red:hover:not(:disabled) { background: #b91c1c; }
.btn-green { background: var(--green-600); color: white; }
.btn-green:hover:not(:disabled) { background: var(--green-700); }
.btn-outline {
    background: white;
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
}
.btn-outline:hover:not(:disabled) { background: var(--gray-50); border-color: var(--gray-300); }

.btn-row {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

/* Quick examples */
.examples { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--gray-100); }
.examples-label { font-size: 0.75rem; font-weight: 500; color: var(--gray-500); margin-bottom: 0.5rem; }
.examples-list { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.example-btn {
    font-size: 0.75rem;
    background: var(--gray-50);
    color: var(--gray-600);
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--gray-200);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.example-btn:hover { background: var(--blue-50); color: var(--blue-700); border-color: #bfdbfe; }

/* Parsed Data Grid */
.parsed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}
.parsed-item {
    text-align: center;
    padding: 0.75rem;
    border-radius: 0.75rem;
    background: var(--gray-50);
    transition: transform 0.15s, box-shadow 0.15s;
}
.parsed-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.parsed-item .value { font-size: 1.25rem; font-weight: 700; color: var(--gray-900); }
.parsed-item .label { font-size: 0.7rem; color: var(--gray-500); margin-top: 2px; }
.parsed-item .icon { font-size: 1.5rem; margin-bottom: 4px; }

/* RAB Table */
.rab-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.rab-header h2 { font-size: 1.1rem; font-weight: 600; }

.rab-table-wrap { overflow-x: auto; border-radius: 0.75rem; border: 1px solid var(--gray-200); }
.rab-table { width: 100%; border-collapse: collapse; min-width: 700px; }
.rab-table thead th {
    background: var(--blue-600);
    color: white;
    padding: 0.75rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}
.rab-table thead th:nth-child(2) { text-align: left; }
.rab-table tbody td {
    padding: 0.625rem 0.75rem;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--gray-100);
}
.rab-table tbody tr:hover { background: var(--gray-50); }
.rab-table tbody tr { cursor: pointer; transition: background 0.15s; }
.rab-table td.num { text-align: right; font-family: 'JetBrains Mono', monospace; }
.rab-table td.center { text-align: center; }

/* Category group row */
.rab-table .group-row td {
    background: var(--blue-50);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--blue-700);
    padding: 0.5rem 0.75rem;
    cursor: default;
}
.rab-table .group-row:hover td { background: var(--blue-50); }

.rab-table tfoot td {
    padding: 0.75rem 0.75rem;
    background: var(--gray-800);
    color: white;
    font-weight: 700;
    font-size: 0.9rem;
}
.rab-table tfoot td.num { font-family: 'JetBrains Mono', monospace; }

/* AHSP Breakdown */
.ahsp-row { display: none; }
.ahsp-row.expanded { display: table-row; }
.ahsp-row td { background: var(--gray-50); padding: 0.75rem 1.5rem; cursor: default; }
.ahsp-row:hover td { background: var(--gray-50); }
.ahsp-table { width: 100%; font-size: 0.75rem; border-collapse: collapse; }
.ahsp-table th { text-align: left; color: var(--gray-500); padding-bottom: 0.25rem; font-weight: 500; }
.ahsp-table td { padding: 0.25rem 0; border-top: 1px solid var(--gray-200); }
.ahsp-table .num { text-align: right; }
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
}
.badge-material { background: #dcfce7; color: #166534; }
.badge-labor { background: #dbeafe; color: #1e40af; }
.badge-cat {
    background: var(--amber-50);
    color: var(--amber-600);
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
}

/* Summary Section */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.summary-stat {
    text-align: center;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--gray-100);
}
.summary-stat .stat-label { font-size: 0.7rem; font-weight: 500; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.05em; }
.summary-stat .stat-value { font-size: 1.1rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; margin-top: 0.25rem; }
.summary-stat.material { background: #f0fdf4; }
.summary-stat.material .stat-value { color: #166534; }
.summary-stat.labor { background: #eff6ff; }
.summary-stat.labor .stat-value { color: #1e40af; }
.summary-stat.tax { background: #fff7ed; }
.summary-stat.tax .stat-value { color: #c2410c; }
.summary-stat.total { background: linear-gradient(135deg, var(--blue-600), var(--purple-600)); }
.summary-stat.total .stat-label { color: rgba(255,255,255,0.8); }
.summary-stat.total .stat-value { color: white; font-size: 1.3rem; }

.summary-table { width: 100%; font-size: 0.85rem; border-collapse: collapse; }
.summary-table td { padding: 0.5rem 0; border-bottom: 1px solid var(--gray-100); }
.summary-table td:last-child { text-align: right; font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.summary-table tr.total-row td { border-bottom: none; border-top: 2px solid var(--gray-300); font-weight: 700; font-size: 1rem; padding-top: 0.75rem; }
.summary-table tr.total-row td:last-child { color: var(--blue-600); font-size: 1.1rem; }

/* History Items */
.history-item {
    padding: 1rem;
    border: 1px solid var(--gray-100);
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}
.history-item:hover { border-color: var(--blue-600); background: var(--blue-50); }
.history-item .hist-title { font-weight: 600; font-size: 0.85rem; color: var(--gray-800); }
.history-item .hist-meta { font-size: 0.75rem; color: var(--gray-500); margin-top: 0.25rem; }
.history-item .hist-total { font-size: 0.9rem; font-weight: 700; color: var(--blue-600); font-family: 'JetBrains Mono', monospace; margin-top: 0.25rem; }

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Hidden utility */
.hidden { display: none !important; }

/* ========================================
   AGENT REPORT SECTIONS
   ======================================== */

/* Section headers with icon + title + badge */
.report-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.report-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.report-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
}
.report-badge.pass { background: #dcfce7; color: #166534; }
.report-badge.fail { background: #fef2f2; color: #991b1b; }
.report-badge.warning { background: #fffbeb; color: #92400e; }
.report-badge.info { background: #eff6ff; color: #1e40af; }

/* Validation / Audit check list */
.check-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.check-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
    border-radius: 0.5rem;
    margin-bottom: 0.375rem;
    font-size: 0.8rem;
    transition: background 0.15s;
}
.check-item:hover { background: var(--gray-50); }
.check-item .check-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    margin-top: 1px;
}
.check-item .check-icon.pass { background: #dcfce7; color: #166534; }
.check-item .check-icon.fail { background: #fef2f2; color: #991b1b; }
.check-item .check-icon.warning { background: #fffbeb; color: #92400e; }
.check-item .check-icon.info { background: #eff6ff; color: #1e40af; }
.check-item .check-icon.critical { background: #fef2f2; color: #991b1b; }

.check-item .check-body { flex: 1; min-width: 0; }
.check-item .check-name { font-weight: 500; color: var(--gray-800); }
.check-item .check-detail { font-size: 0.75rem; color: var(--gray-500); margin-top: 1px; }
.check-item .check-code { font-size: 0.65rem; color: var(--gray-400); font-family: 'JetBrains Mono', monospace; }

/* Finding / suggestion cards */
.finding-card {
    border: 1px solid var(--gray-200);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    transition: border-color 0.15s;
}
.finding-card:hover { border-color: var(--gray-300); }
.finding-card.critical { border-left: 3px solid #dc2626; }
.finding-card.warning { border-left: 3px solid #f59e0b; }
.finding-card.info { border-left: 3px solid #3b82f6; }
.finding-card.high { border-left: 3px solid #dc2626; }
.finding-card.medium { border-left: 3px solid #f59e0b; }
.finding-card.low { border-left: 3px solid #6b7280; }

.finding-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}
.finding-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-800);
}
.finding-severity {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
}
.finding-severity.critical { background: #fef2f2; color: #991b1b; }
.finding-severity.warning { background: #fffbeb; color: #92400e; }
.finding-severity.info { background: #eff6ff; color: #1e40af; }
.finding-severity.high { background: #fef2f2; color: #991b1b; }
.finding-severity.medium { background: #fffbeb; color: #92400e; }
.finding-severity.low { background: var(--gray-100); color: var(--gray-600); }

.finding-message {
    font-size: 0.8rem;
    color: var(--gray-600);
    line-height: 1.4;
}
.finding-detail {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}
.finding-savings {
    font-size: 0.75rem;
    font-weight: 600;
    color: #16a34a;
    margin-top: 0.25rem;
    font-family: 'JetBrains Mono', monospace;
}

/* Score meter */
.score-meter {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.score-bar-wrap {
    flex: 1;
    height: 8px;
    background: var(--gray-200);
    border-radius: 999px;
    overflow: hidden;
}
.score-bar {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease;
}
.score-bar.good { background: linear-gradient(90deg, #22c55e, #16a34a); }
.score-bar.ok { background: linear-gradient(90deg, #f59e0b, #d97706); }
.score-bar.bad { background: linear-gradient(90deg, #ef4444, #dc2626); }
.score-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    min-width: 48px;
    text-align: right;
}
.score-value.good { color: #16a34a; }
.score-value.ok { color: #d97706; }
.score-value.bad { color: #dc2626; }

/* Engineering notes */
.eng-note {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 0.375rem;
    font-size: 0.8rem;
}
.eng-note.info { background: #eff6ff; }
.eng-note.warning { background: #fffbeb; }
.eng-note.recommendation { background: #f0fdf4; }
.eng-note .note-icon { flex-shrink: 0; font-size: 1rem; margin-top: 1px; }
.eng-note .note-body { flex: 1; }
.eng-note .note-msg { color: var(--gray-800); }
.eng-note .note-std { font-size: 0.7rem; color: var(--gray-400); font-style: italic; margin-top: 2px; }

/* Warning list */
.warning-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.375rem 0;
    font-size: 0.8rem;
    color: var(--gray-700);
}
.warning-item .warn-icon { flex-shrink: 0; }

/* Agent Logs (collapsible) */
.logs-toggle {
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--gray-500);
    background: none;
    border: 1px solid var(--gray-200);
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}
.logs-toggle:hover { background: var(--gray-50); color: var(--gray-700); }
.logs-pre {
    max-height: 300px;
    overflow-y: auto;
    background: var(--gray-900);
    color: #a3e635;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    line-height: 1.5;
    padding: 1rem;
    border-radius: 0.75rem;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Optimization total savings banner */
.savings-banner {
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    border: 1px solid #bbf7d0;
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.savings-banner .savings-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #166534;
}
.savings-banner .savings-amount {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: #16a34a;
}

/* Processing time badge */
.time-badge {
    font-size: 0.65rem;
    color: var(--gray-400);
    font-family: 'JetBrains Mono', monospace;
    padding: 0.1rem 0.4rem;
    background: var(--gray-100);
    border-radius: 3px;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.loading-overlay.active { display: flex; }
.loading-card {
    background: white;
    padding: 2rem 3rem;
    border-radius: 1rem;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}
.loading-spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--blue-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .header-inner { flex-direction: column; height: auto; padding: 0.75rem 1rem; gap: 0.5rem; }
    .header-badge { display: none; }
    .tab-btn { font-size: 0.75rem; padding: 0.3rem 0.6rem; }
    .hero h1 { font-size: 1.35rem; }
    .btn-row { flex-direction: column; }
    .btn { width: 100%; justify-content: center; }
    .parsed-grid { grid-template-columns: repeat(2, 1fr); }
    .summary-grid { grid-template-columns: 1fr 1fr; }
    .rab-header { flex-direction: column; align-items: flex-start; }
    .examples-list { flex-direction: column; }
    .example-btn { text-align: left; }
}

@media print {
    .header, .info-banner, .btn, .btn-row, .examples, .loading-overlay, .tab-btn, .error-banner { display: none !important; }
    .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
    body { background: white; }
    .rab-table { min-width: auto; }
}
