/* BRHDG Zoning Analyzer - Styles */
:root {
    --navy: #0f1c2e;
    --navy-light: #1a2d47;
    --teal: #00b894;
    --teal-dark: #009977;
    --teal-glow: rgba(0, 184, 148, 0.12);
    --white: #ffffff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --red: #ef4444;
    --amber: #f59e0b;
    --green: #10b981;
    --blue: #3b82f6;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-100);
    color: var(--gray-700);
    line-height: 1.6;
    min-height: 100vh;
}

/* Header */
header {
    background: var(--navy);
    border-bottom: 3px solid var(--teal);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.8rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--teal);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--navy);
}
.brand h1 {
    color: var(--white);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.brand-sub {
    color: var(--gray-400);
    font-size: 0.75rem;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.model-badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: var(--gray-700);
    color: var(--gray-300);
    border: 1px solid var(--gray-600);
    white-space: nowrap;
}
.model-badge.badge-haiku  { background: rgba(0, 184, 148, 0.18); color: var(--teal); border-color: var(--teal-dark); }
.model-badge.badge-sonnet { background: rgba(245, 158, 11, 0.18); color: var(--amber); border-color: var(--amber); }
.model-badge.badge-opus   { background: rgba(239, 68, 68, 0.18);  color: var(--red);   border-color: var(--red); }

/* Main */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}
.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--navy);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--gray-100);
}
.card-desc {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-bottom: 1rem;
}
.optional {
    font-weight: 400;
    color: var(--gray-400);
    font-size: 0.85rem;
}
.highlight-card {
    border: 2px solid var(--teal);
    background: linear-gradient(135deg, var(--teal-glow), var(--white));
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}
.form-group {
    display: flex;
    flex-direction: column;
}
.form-group.span-2 {
    grid-column: span 2;
}
label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
input, select, textarea {
    padding: 0.6rem 0.75rem;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--gray-700);
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--teal-glow);
}
input::placeholder, textarea::placeholder {
    color: var(--gray-400);
}
textarea {
    resize: vertical;
    width: 100%;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: inherit;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.85rem;
    padding: 0.6rem 1.2rem;
}
.btn-primary {
    background: var(--teal);
    color: var(--white);
}
.btn-primary:hover {
    background: var(--teal-dark);
}
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--gray-300);
    color: var(--gray-600);
}
.btn-outline:hover {
    border-color: var(--teal);
    color: var(--teal-dark);
}
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-lg { padding: 0.85rem 2rem; font-size: 1rem; }

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--gray-50);
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--teal);
    background: var(--teal-glow);
}
.upload-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}
.upload-zone p {
    color: var(--gray-600);
    font-size: 0.9rem;
}
.upload-hint {
    color: var(--gray-400) !important;
    font-size: 0.8rem !important;
    margin-top: 0.25rem;
}
.upload-status {
    margin-top: 0.75rem;
    font-size: 0.85rem;
}
.upload-status .success {
    color: var(--green);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.upload-status .error {
    color: var(--red);
}
.upload-status .loading {
    color: var(--blue);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Submit Area */
.submit-area {
    text-align: center;
    padding: 2rem 0 1rem;
}
.submit-hint {
    color: var(--gray-400);
    font-size: 0.8rem;
    margin-top: 0.75rem;
}

/* Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results Layout */
.results-layout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 1rem;
    align-items: start;
}
@media (max-width: 1024px) {
    .results-layout {
        grid-template-columns: 1fr;
    }
}

/* Report Pane */
.report-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--gray-100);
}
.report-header .card-title { margin-bottom: 0; padding-bottom: 0; border: none; }
.report-actions { display: flex; gap: 0.5rem; }

.report-body {
    font-size: 0.9rem;
    line-height: 1.7;
    max-height: 80vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}
.report-body h1 { font-size: 1.3rem; color: var(--navy); margin: 1.5rem 0 0.75rem; }
.report-body h2 { font-size: 1.1rem; color: var(--navy); margin: 1.25rem 0 0.5rem; }
.report-body h3 { font-size: 0.95rem; color: var(--navy-light); margin: 1rem 0 0.5rem; }
.report-body p { margin-bottom: 0.5rem; }
.report-body ul, .report-body ol { margin: 0.5rem 0 0.5rem 1.5rem; }
.report-body li { margin-bottom: 0.25rem; }
.report-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.85rem;
}
.report-body th, .report-body td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-200);
    text-align: left;
}
.report-body th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--navy);
}
.report-body code {
    background: var(--gray-100);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.85em;
}
.report-body strong { color: var(--navy); }
.report-body hr {
    border: none;
    border-top: 1px solid var(--gray-200);
    margin: 1rem 0;
}

/* Compliance indicators & Report Styling */
.report-body .badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.report-body .badge-pass { background: rgba(16,185,129,0.1); color: var(--green); }
.report-body .badge-fail { background: rgba(239,68,68,0.1); color: var(--red); }
.report-body .badge-deemed { background: rgba(59,130,246,0.1); color: var(--blue); }
.report-body .badge-verify { background: rgba(245,158,11,0.1); color: var(--amber); }
.report-body .badge-info { background: var(--gray-100); color: var(--gray-600); }
.report-body .badge-nc { background: rgba(239,68,68,0.1); color: var(--red); }

.report-body .status-pass { color: var(--green); font-weight: 600; }
.report-body .status-fail { color: var(--red); font-weight: 600; }
.report-body .status-deemed { color: var(--blue); font-weight: 600; }
.report-body .status-verify { color: var(--amber); font-weight: 600; }

.report-body .section-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin: 1rem 0;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
}
.report-body .section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--navy);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--gray-100);
}
.report-body .sub-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--navy-light);
    margin: 0.75rem 0 0.5rem;
}
.report-body .highlight-section {
    border: 2px solid var(--teal);
    background: linear-gradient(135deg, var(--teal-glow), var(--white));
}
.report-body .report-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 2rem;
    font-size: 0.85rem;
}
.report-body .report-meta dt {
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.75rem;
}
.report-body .report-meta dd {
    margin-bottom: 0.4rem;
    color: var(--gray-700);
}
.report-body .summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
    margin: 0.75rem 0;
}
.report-body .summary-stat {
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    text-align: center;
}
.report-body .summary-stat .stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--navy);
}
.report-body .summary-stat .stat-label {
    font-size: 0.7rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.1rem;
}
.report-body .terminology-box {
    background: var(--gray-50);
    border-left: 3px solid var(--teal);
    padding: 0.85rem 1rem;
    margin: 0.75rem 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.85rem;
}
.report-body .terminology-box strong { color: var(--navy); }
.report-body .bylaw-quote {
    background: var(--gray-50);
    border-left: 3px solid var(--gray-300);
    padding: 0.65rem 0.85rem;
    margin: 0.65rem 0;
    font-size: 0.83rem;
    font-style: italic;
    color: var(--gray-600);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.report-body .bylaw-quote cite {
    display: block;
    font-style: normal;
    font-weight: 600;
    color: var(--navy);
    margin-top: 0.35rem;
    font-size: 0.8rem;
}
.report-body .verdict-box {
    border: 2px solid var(--green);
    background: rgba(16,185,129,0.05);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 0.75rem 0;
    text-align: center;
}
.report-body .verdict-box.verdict-fail {
    border-color: var(--red);
    background: rgba(239,68,68,0.05);
}
.report-body .verdict-box.verdict-warning {
    border-color: var(--amber);
    background: rgba(245,158,11,0.05);
}
.report-body .verdict-box h3 {
    color: var(--green);
    font-size: 1.05rem;
    margin-bottom: 0.3rem;
}
.report-body .verdict-box.verdict-fail h3 { color: var(--red); }
.report-body .verdict-box.verdict-warning h3 { color: var(--amber); }
.report-body .verdict-box p {
    font-size: 0.85rem;
    color: var(--gray-600);
}
.report-body .info-box {
    background: rgba(59,130,246,0.06);
    border-left: 3px solid var(--blue);
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.85rem;
}
.report-body .warning-box {
    background: rgba(245,158,11,0.08);
    border-left: 3px solid var(--amber);
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.85rem;
}
.report-body .notes-block {
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    margin: 0.5rem 0;
}
@media (max-width: 640px) {
    .report-body .report-meta { grid-template-columns: 1fr; }
    .report-body .summary-grid { grid-template-columns: 1fr 1fr; }
}

/* Chat Pane */
.chat-card {
    position: sticky;
    top: 70px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 90px);
}
.chat-card .card-title {
    flex-shrink: 0;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
    min-height: 200px;
    max-height: calc(100vh - 260px);
}
.chat-msg {
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.5;
    word-wrap: break-word;
}
.chat-msg.system {
    background: var(--gray-100);
    color: var(--gray-500);
    font-style: italic;
    text-align: center;
}
.chat-msg.user {
    background: var(--navy);
    color: var(--white);
    margin-left: 2rem;
    border-bottom-right-radius: 2px;
}
.chat-msg.assistant {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    margin-right: 1rem;
    border-bottom-left-radius: 2px;
}
.chat-msg.assistant p { margin-bottom: 0.4rem; }
.chat-msg.assistant p:last-child { margin-bottom: 0; }
.chat-msg.assistant ul, .chat-msg.assistant ol { margin: 0.3rem 0 0.3rem 1.2rem; font-size: 0.85rem; }
.chat-msg.assistant strong { color: var(--navy); }
.chat-msg.assistant table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; font-size: 0.8rem; }
.chat-msg.assistant th, .chat-msg.assistant td { padding: 0.3rem 0.5rem; border: 1px solid var(--gray-200); }
.chat-msg.assistant th { background: var(--gray-100); }

.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.chat-input-area textarea {
    flex: 1;
    min-height: 40px;
    max-height: 100px;
    resize: none;
}
.chat-input-area .btn {
    align-self: flex-end;
}
.chat-input-area .btn-icon {
    background: none;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    padding: 0.4rem;
    cursor: pointer;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, color 0.15s;
}
.chat-input-area .btn-icon:hover {
    border-color: var(--teal);
    color: var(--teal);
}

/* Chat Attachments */
.chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.5rem 0;
}
.chat-att-pill {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: 16px;
    padding: 0.25rem 0.6rem;
    font-size: 0.78rem;
    max-width: 220px;
}
.chat-att-pill .att-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 130px;
}
.chat-att-pill .att-status {
    color: var(--teal);
    font-size: 0.72rem;
}
.chat-att-pill .att-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-500);
    font-size: 1rem;
    line-height: 1;
    padding: 0 0.15rem;
}
.chat-att-pill .att-remove:hover {
    color: var(--red, #e53e3e);
}
.chat-att-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.3rem;
}
.att-badge {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    padding: 0.1rem 0.5rem;
    font-size: 0.72rem;
    border: 1px solid rgba(255,255,255,0.3);
}

/* Accessory Building Mini Card */
.accessory-card {
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
    position: relative;
}
.accessory-card .remove-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem;
    line-height: 1;
}
.accessory-card .remove-btn:hover { opacity: 0.7; }
.accessory-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 0.75rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: var(--gray-400);
    font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 640px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .form-group.span-2 {
        grid-column: span 1;
    }
    .header-inner {
        padding: 0.6rem 1rem;
    }
    main {
        padding: 1rem;
    }
    .card {
        padding: 1rem;
    }
}

/* Print */
@media print {
    header, footer, .chat-pane, .report-actions, #newReportBtn { display: none !important; }
    .results-layout { grid-template-columns: 1fr !important; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    .report-body { max-height: none; overflow: visible; }
    .report-body .cad-summary-section { page-break-before: always; break-before: page; }

    /* Keep each section on one page when it fits; only split sections that are
       genuinely longer than a page. */
    .report-body .section-card,
    .report-body .highlight-section,
    .report-body .verdict-box,
    .report-body .bylaw-quote,
    .report-body table { page-break-inside: avoid; break-inside: avoid; }

    /* Don't strand a heading at the bottom of a page. */
    .report-body h1, .report-body h2, .report-body h3,
    .report-body .section-title, .report-body .sub-title {
        page-break-after: avoid; break-after: avoid;
        page-break-inside: avoid; break-inside: avoid;
    }
}
