/* =====================================================
   FIRE & BUILDING COMPLIANCE SUITE - Dashboard (app) styles
   Builds on css/styles.css (variables, .btn, modal, the global
   [hidden]{display:none!important} rule, etc.)
   ===================================================== */

:root {
    --sidebar-w: 264px;
    --topbar-h: 64px;
    --side-bg: #0f2744;
    --side-bg-2: #14304f;
    --side-text: #cbd5e1;
    --side-text-dim: #7e93ad;
    --side-active: rgba(220,38,38,.16);
}

.dashboard-body { background: var(--bg-alt); color: var(--text); }

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    background: var(--side-bg);
    color: var(--side-text);
    display: flex;
    flex-direction: column;
    padding: 18px 16px;
    gap: 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 60;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; }
.sidebar .logo { color: #fff; font-size: 1.05rem; display: inline-flex; align-items: center; gap: 9px; font-weight: 800; min-width: 0; }
.sidebar .logo-img { height: 28px; width: auto; flex-shrink: 0; }
.sidebar .logo-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .logo-icon { background: var(--gradient); }
.sidebar .logo-text .accent { color: #fb923c; }
.sidebar-close { display: none; background: none; border: none; color: var(--side-text); font-size: 1.6rem; cursor: pointer; }

.new-project-btn { margin-top: 2px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 3px; }
.sidebar-label { font-size: .72rem; text-transform: uppercase; letter-spacing: 1.2px; color: var(--side-text-dim); font-weight: 700; margin: 8px 8px 4px; }
.sidebar-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 9px;
    color: var(--side-text); font-weight: 500; font-size: .94rem;
    cursor: pointer; border: none; background: none; width: 100%; text-align: left;
    font-family: inherit;
}
.sidebar-link svg { width: 19px; height: 19px; flex-shrink: 0; opacity: .9; }
.sidebar-link:hover { background: var(--side-bg-2); color: #fff; }
.sidebar-link.active { background: var(--side-active); color: #fff; }
.sidebar-link.active svg { color: #fb923c; opacity: 1; }
.sidebar-count { margin-left: auto; background: rgba(255,255,255,.12); color: #fff; font-size: .76rem; font-weight: 700; padding: 1px 8px; border-radius: var(--radius-full); }
.tool-link .tool-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.install-sidebar { color: #fb923c; }
.install-sidebar:hover { background: var(--side-bg-2); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--side-bg-2); border-radius: 11px; }
.user-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--gradient); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-meta strong { color: #fff; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { color: var(--side-text-dim); font-size: .78rem; }
.user-logout { margin-left: auto; background: none; border: none; color: var(--side-text-dim); cursor: pointer; padding: 4px; }
.user-logout:hover { color: #fff; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 55; }
.sidebar-backdrop.show { display: block; }

/* ---------- Main ---------- */
.app-main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 16px;
    padding: 0 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
}
.topbar-menu { display: none; flex-direction: column; gap: 4px; background: none; border: none; cursor: pointer; padding: 6px; }
.topbar-menu span { width: 22px; height: 2px; background: var(--secondary-dark); border-radius: 2px; }
.topbar-search { position: relative; flex: 1; max-width: 420px; }
.topbar-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-muted); }
.topbar-search input { width: 100%; padding: 9px 14px 9px 38px; border: 1.5px solid var(--border); border-radius: var(--radius-full); font-size: .92rem; font-family: inherit; background: var(--bg-alt); }
.topbar-search input:focus { outline: none; border-color: var(--primary); background: #fff; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }

.save-status { display: flex; align-items: center; gap: 7px; font-size: .85rem; color: var(--text-light); }
.save-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); transition: background var(--transition); }
.save-status.saving .save-dot { background: var(--warning); animation: pulse 1s infinite; }
.save-status.unsaved .save-dot { background: var(--warning); }
.save-status.offline .save-dot { background: var(--text-muted); }
.save-status.error .save-dot { background: var(--error); }
@keyframes pulse { 0%,100%{ opacity: 1; } 50%{ opacity: .35; } }

.sync-status { display: flex; align-items: center; gap: 7px; font-size: .85rem; color: var(--text-light); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; }
.sync-dot.online { background: var(--success); }
.sync-dot.offline { background: var(--text-muted); }

/* ---------- Banner ---------- */
.app-banner { display: flex; align-items: center; gap: 14px; padding: 11px 24px; background: linear-gradient(90deg, var(--accent-light), #fff); border-bottom: 1px solid var(--border); font-size: .9rem; color: var(--secondary-dark); }
.app-banner-cta { margin-left: auto; font-weight: 700; color: var(--primary); }
.app-banner-close { background: none; border: none; font-size: 1.3rem; color: var(--text-muted); cursor: pointer; line-height: 1; }

/* ---------- Content / panels ---------- */
.content { padding: 28px 24px 60px; max-width: 1180px; width: 100%; margin: 0 auto; flex: 1; }
.panel { animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.panel-head h1 { font-size: 1.7rem; }
.panel-sub { color: var(--text-light); margin-top: 4px; }

/* Stat cards */
.stat-cards { display: grid; grid-template-columns: repeat(4,1fr); gap: 18px; margin-bottom: 34px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.stat-card .stat-icon { width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.stat-card .stat-icon svg { width: 20px; height: 20px; color: #fff; }
.stat-card .stat-num { font-size: 1.9rem; font-weight: 800; color: var(--secondary-dark); line-height: 1; }
.stat-card .stat-name { color: var(--text-light); font-size: .88rem; margin-top: 5px; }

/* Overview sections */
.overview-section { margin-bottom: 36px; }
.overview-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.overview-head h2 { font-size: 1.2rem; }
.link-more { color: var(--primary); font-weight: 600; font-size: .9rem; cursor: pointer; }

/* Project cards */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.project-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; cursor: pointer; transition: all var(--transition); position: relative; }
.project-card:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); border-color: var(--primary-light); }
.project-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.project-tool { display: inline-flex; align-items: center; gap: 7px; font-size: .78rem; font-weight: 700; padding: 4px 10px; border-radius: var(--radius-full); }
.project-menu-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.project-menu-btn:hover { background: var(--bg-alt); color: var(--text); }
.project-card h3 { font-size: 1.05rem; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-card-meta { display: flex; align-items: center; gap: 10px; font-size: .82rem; color: var(--text-muted); margin-top: 12px; }
.status-pill { font-size: .74rem; font-weight: 700; padding: 2px 9px; border-radius: var(--radius-full); }
.status-pill.draft { background: #f1f5f9; color: #64748b; }
.status-pill.in_progress { background: var(--accent-light); color: #c2410c; }
.status-pill.complete { background: #dcfce7; color: #15803d; }
.project-progress { height: 5px; background: var(--bg-alt); border-radius: 4px; margin-top: 12px; overflow: hidden; }
.project-progress span { display: block; height: 100%; background: var(--gradient); border-radius: 4px; transition: width .4s ease; }

/* Card dropdown menu */
.card-menu { position: absolute; top: 44px; right: 16px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 30; min-width: 150px; }
.card-menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 11px; background: none; border: none; border-radius: 7px; font-size: .88rem; color: var(--text); cursor: pointer; text-align: left; font-family: inherit; }
.card-menu button:hover { background: var(--bg-alt); }
.card-menu button.danger { color: var(--error); }
.card-menu button svg { width: 16px; height: 16px; }

/* Filter bar */
.filter-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.filter-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-tab { padding: 7px 14px; border-radius: var(--radius-full); border: 1.5px solid var(--border); background: #fff; font-size: .85rem; font-weight: 600; color: var(--text-light); cursor: pointer; font-family: inherit; }
.filter-tab:hover { border-color: var(--primary-light); }
.filter-tab.active { background: var(--secondary-dark); color: #fff; border-color: var(--secondary-dark); }
.filter-select { margin-left: auto; padding: 8px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); background: #fff; font-size: .88rem; font-family: inherit; cursor: pointer; }

/* Templates */
.template-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); gap: 16px; }
.template-groups { display: flex; flex-direction: column; gap: 30px; }
.template-group h2 { font-size: 1.15rem; margin-bottom: 14px; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px,1fr)); gap: 16px; }
.template-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; transition: all var(--transition); display: flex; flex-direction: column; }
.template-card:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); }
.template-card .project-tool { align-self: flex-start; margin-bottom: 12px; }
.template-card h3 { font-size: 1rem; margin-bottom: 6px; }
.template-card p { font-size: .86rem; color: var(--text-light); margin-bottom: 16px; flex: 1; }
.template-card .btn { margin-top: auto; }
.btn-sm { padding: 8px 16px; font-size: .85rem; }

/* Empty states */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 3rem; margin-bottom: 14px; }
.empty-state h3 { margin-bottom: 8px; }
.empty-state p { color: var(--text-light); margin-bottom: 20px; }

/* Timeline / history */
.timeline { position: relative; padding-left: 8px; }
.timeline-day { margin-bottom: 26px; }
.timeline-date { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 14px; }
.timeline-item { display: flex; gap: 14px; padding-bottom: 16px; position: relative; }
.timeline-item::before { content: ''; position: absolute; left: 15px; top: 32px; bottom: 0; width: 2px; background: var(--border); }
.timeline-item:last-child::before { display: none; }
.timeline-icon { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; z-index: 1; }
.timeline-icon svg { width: 16px; height: 16px; color: #fff; }
.timeline-icon.created { background: var(--success); }
.timeline-icon.edited { background: var(--accent); }
.timeline-icon.exported { background: var(--secondary); }
.timeline-icon.deleted { background: var(--text-muted); }
.timeline-icon.status { background: var(--primary); }
.timeline-content { padding-top: 5px; }
.timeline-content strong { color: var(--secondary-dark); }
.timeline-content .timeline-time { display: block; font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

/* ---------- Editor ---------- */
.panel-editor { animation: fade .3s ease; }
.editor-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.editor-back { background: #fff; border: 1px solid var(--border); border-radius: 9px; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text); flex-shrink: 0; }
.editor-back:hover { border-color: var(--primary); color: var(--primary); }
.editor-tool-badge { font-size: .76rem; font-weight: 700; padding: 5px 11px; border-radius: var(--radius-full); white-space: nowrap; }
.editor-title { flex: 1; min-width: 160px; border: none; font-size: 1.35rem; font-weight: 800; color: var(--secondary-dark); padding: 6px 8px; border-radius: 8px; font-family: inherit; }
.editor-title:focus { outline: none; background: var(--bg-alt); }
.editor-bar-right { display: flex; align-items: center; gap: 12px; }
.status-select { padding: 8px 12px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: .85rem; font-family: inherit; cursor: pointer; background: #fff; }

.editor-body { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
/* min-width:0 stops wide item tables from stretching the grid track (overflow) */
.editor-body > * { min-width: 0; }
.editor-form { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; min-width: 0; }
.editor-form .form-section-title { font-size: 1rem; font-weight: 700; color: var(--secondary-dark); margin: 22px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.editor-form .form-section-title:first-child { margin-top: 0; }
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 7px; color: var(--text); }
.field input, .field select, .field textarea {
    width: 100%; padding: 11px 13px; border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: .95rem; font-family: inherit; background: #fff;
    transition: all var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.field textarea { min-height: 90px; resize: vertical; }
.field-hint { font-size: .8rem; color: var(--text-muted); margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.editor-aside { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px; position: sticky; top: calc(var(--topbar-h) + 16px); }
.editor-aside h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 14px; }
.summary-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.summary-row:last-child { border-bottom: none; }
.summary-row span:first-child { color: var(--text-light); }
.summary-row span:last-child { font-weight: 600; color: var(--secondary-dark); text-align: right; }
.completion-ring { text-align: center; margin-bottom: 18px; }
.completion-ring .ring-num { font-size: 2rem; font-weight: 800; color: var(--primary); }
.completion-ring .ring-label { font-size: .8rem; color: var(--text-muted); }

/* ---------- Engine results (compliance + cost) ---------- */
/* ---------- Scenario comparison ---------- */
#editorResults .editor-results-head { position: relative; }
#compareBtn { margin-left: auto; }
#editorCompareBody:not(:empty) { margin-top: 4px; }
.cmp-table { width: 100%; border-collapse: collapse; }
.cmp-table th, .cmp-table td { text-align: left; padding: 9px 10px; font-size: .88rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.cmp-table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .3px; color: var(--text-muted); font-weight: 700; border-bottom: 2px solid var(--border); }
.cmp-table tbody th { color: var(--text-light); font-weight: 600; width: 34%; }
.cmp-table tbody td { color: var(--secondary-dark); font-weight: 600; }
.cmp-table tr.cmp-changed td:last-child { background: #f0fdf4; }
.cmp-table tr.cmp-sub th { color: var(--secondary-dark); }
.cmp-tag { display: inline-block; font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: var(--radius-full);
    margin-left: 6px; text-transform: uppercase; letter-spacing: .3px; vertical-align: middle; }
.cmp-tag.good { background: #dcfce7; color: #15803d; }
.cmp-tag.up { background: #fee2e2; color: #b91c1c; }

/* ---------- Compliance AI chat ---------- */
.editor-ai { margin-top: 22px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.editor-ai-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary), var(--accent)); }
.editor-ai-head h2 { font-size: 1.05rem; color: #fff; }
.ai-badge { font-size: .66rem; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: #fff;
    background: rgba(255,255,255,.22); padding: 3px 9px; border-radius: var(--radius-full); }
.ai-chat { max-height: 420px; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.ai-welcome { font-size: .9rem; color: var(--text-light); }
.ai-examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ai-example { font-size: .82rem; color: var(--primary-dark); background: var(--primary-light); border: 1px solid transparent;
    padding: 6px 12px; border-radius: var(--radius-full); cursor: pointer; font-family: inherit; text-align: left; }
.ai-example:hover { border-color: var(--primary); }
.ai-msg { max-width: 88%; padding: 11px 15px; border-radius: 14px; font-size: .9rem; line-height: 1.5; }
.ai-msg.ai-user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.ai-msg.ai-bot { align-self: flex-start; background: var(--bg-alt); border: 1px solid var(--border); color: var(--secondary-dark); border-bottom-left-radius: 4px; }
.ai-msg.ai-bot p { margin: 0 0 8px; color: var(--text-light); }
.ai-msg.ai-bot p:last-child { margin-bottom: 0; }
.ai-msg.ai-bot strong { color: var(--secondary-dark); }
.ai-list { margin: 4px 0 8px; padding-left: 18px; list-style: disc; }
.ai-list li { font-size: .88rem; color: var(--text-light); margin-bottom: 4px; }
.ai-table { width: 100%; border-collapse: collapse; margin: 6px 0 8px; }
.ai-table th, .ai-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: .85rem; }
.ai-table th { color: var(--text-muted); font-weight: 700; }
.ai-conf { margin-top: 8px; font-size: .76rem; color: var(--text-muted); font-style: italic; }
.ai-input { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--bg-alt); }
.ai-input input { flex: 1; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); font-family: inherit; font-size: .92rem; }
.ai-input input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.ai-input .btn { padding: 10px 22px; }

.editor-results { margin-top: 22px; }
.editor-results-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.editor-results-head h2 { font-size: 1.2rem; }
.results-engine-badge {
    font-size: .72rem; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
    color: #15803d; background: #dcfce7; padding: 3px 10px; border-radius: var(--radius-full);
}
.res-hint { color: var(--text-muted); font-size: .92rem; padding: 18px; background: #fff;
    border: 1px dashed var(--border); border-radius: var(--radius-lg); }

.res-block { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 22px 24px; margin-bottom: 18px; }
.res-block h4 { font-size: 1rem; color: var(--secondary-dark); margin-bottom: 14px;
    display: flex; align-items: center; gap: 10px; }
.res-rom { font-size: .7rem; font-weight: 700; color: var(--text-muted); background: var(--bg-alt);
    padding: 2px 8px; border-radius: var(--radius-full); letter-spacing: .3px; }

/* required systems */
.res-systems { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.res-sys { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--bg-alt); }
.res-sys.req { border-left: 4px solid var(--primary); background: #fff; }
.res-sys.noreq { opacity: .72; }
.res-sys-badge { flex-shrink: 0; align-self: flex-start; font-size: .68rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .3px; padding: 3px 9px; border-radius: var(--radius-full);
    background: #e2e8f0; color: #64748b; }
.res-sys.req .res-sys-badge { background: var(--primary-light); color: var(--primary-dark); }
.res-sys-body strong { display: block; color: var(--secondary-dark); font-size: .95rem; }
.res-clause { display: block; font-size: .78rem; color: var(--primary); font-weight: 600; margin-top: 3px; }
.res-logic { display: block; font-size: .8rem; color: var(--text-light); margin-top: 5px; white-space: pre-line; }

/* cost table */
.res-cost { width: 100%; border-collapse: collapse; }
.res-cost td { padding: 11px 8px; border-bottom: 1px solid var(--border); font-size: .92rem; vertical-align: top; }
.res-cost-bd { display: block; font-size: .78rem; color: var(--text-muted); margin-top: 3px; }
.res-cost-amt { text-align: right; font-weight: 700; color: var(--secondary-dark); white-space: nowrap; }
.res-cost tfoot td { border-bottom: none; border-top: 2px solid var(--secondary-dark); padding-top: 12px;
    font-weight: 800; font-size: 1.05rem; color: var(--secondary-dark); }
.res-cost tfoot tr.res-cost-sub td { border-top: none; padding-top: 2px; font-weight: 600;
    font-size: .85rem; color: var(--text-muted); }
.res-disclaimer { font-size: .78rem; color: var(--text-muted); font-style: italic; margin-top: 12px; }

/* calc table */
.res-calc { width: 100%; border-collapse: collapse; }
.res-calc th { text-align: left; width: 42%; padding: 9px 8px; color: var(--text-light);
    font-weight: 600; font-size: .9rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.res-calc td { padding: 9px 8px; font-size: .9rem; color: var(--secondary-dark); font-weight: 600;
    border-bottom: 1px solid var(--border); }
.res-list { padding-left: 18px; }
.res-list li { font-size: .88rem; color: var(--text-light); margin-bottom: 7px; }

/* aside engine summary */
.aside-engine { background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; margin-bottom: 18px; }
.aside-engine-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: .9rem; }
.aside-engine-row span { color: var(--text-light); }
.aside-engine-row strong { color: var(--secondary-dark); }

/* requirement / comparison table (Section J, BAL setbacks, egress) */
.res-jtable { width: 100%; border-collapse: collapse; }
.res-jtable th { text-align: left; padding: 8px; font-size: .76rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .3px; color: var(--text-muted); border-bottom: 2px solid var(--border); }
.res-jtable td { padding: 9px 8px; font-size: .88rem; color: var(--secondary-dark);
    border-bottom: 1px solid var(--border); vertical-align: top; }
.res-jreq strong { color: var(--secondary-dark); }
.res-jnotes { color: var(--text-light); font-size: .82rem; }
.res-jrow.warn td { background: #fef2f2; }
.res-jrow.warn .res-jreq strong { color: #b91c1c; }
.res-subhead { font-size: .82rem; font-weight: 700; color: var(--secondary-dark); margin: 14px 0 6px; }
.res-mandatory { border-left: 4px solid var(--primary); }

/* metric tiles (egress) */
.res-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 6px; }
.res-metric { text-align: center; padding: 14px 10px; background: var(--bg-alt); border: 1px solid var(--border);
    border-radius: var(--radius); }
.res-metric-val { display: block; font-size: 1.35rem; font-weight: 800; color: var(--secondary-dark); }
.res-metric-lbl { display: block; font-size: .72rem; color: var(--text-muted); margin-top: 4px;
    text-transform: uppercase; letter-spacing: .3px; }

/* status badges (ESM, passive) */
.res-badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: 2px 9px; border-radius: var(--radius-full);
    text-transform: uppercase; letter-spacing: .3px; vertical-align: middle; }
.res-badge.ok { background: #dcfce7; color: #15803d; }
.res-badge.warn { background: #fee2e2; color: #b91c1c; }
.res-badge.info { background: var(--primary-light); color: var(--primary-dark); }
.res-defect { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: .85rem; }
.res-defect span { color: var(--text-light); }

/* multi-item sections (ESM measures/defects, Passive elements) */
.editor-items { margin-top: 8px; }
.items-section { margin-top: 22px; }
.items-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.items-head h3 { font-size: 1rem; color: var(--secondary-dark); display: flex; align-items: center; gap: 8px; }
.items-count { font-size: .72rem; font-weight: 700; color: var(--text-muted); background: var(--bg-alt);
    padding: 2px 9px; border-radius: var(--radius-full); }
.items-empty { font-size: .88rem; color: var(--text-muted); padding: 14px 16px; background: var(--bg-alt);
    border: 1px dashed var(--border); border-radius: var(--radius); }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { text-align: left; padding: 7px 8px; font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .3px; color: var(--text-muted); border-bottom: 2px solid var(--border); }
.items-table td { padding: 9px 8px; font-size: .88rem; color: var(--secondary-dark); border-bottom: 1px solid var(--border); vertical-align: middle; }
.items-table .item-actions { text-align: right; white-space: nowrap; width: 1%; }
.item-edit, .item-del { border: 1px solid var(--border); background: #fff; border-radius: var(--radius);
    cursor: pointer; font-size: .78rem; padding: 4px 9px; color: var(--text-light); font-family: inherit; }
.item-edit:hover { border-color: var(--primary); color: var(--primary); }
.item-del { margin-left: 6px; font-size: .95rem; line-height: 1; padding: 3px 9px; }
.item-del:hover { border-color: #dc2626; color: #dc2626; }
.item-form .field { margin-bottom: 14px; }

/* evac diagram legend */
.res-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 14px; }
.res-legend-item { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--secondary-dark); }
.res-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }

/* FRL tested-system meta lines */
.res-frl-meta { display: block; font-size: .8rem; color: var(--text-light); margin-top: 3px; }
.res-frl-meta em { color: var(--text-muted); font-style: normal; font-weight: 600; }

/* progress bar (passive compliance stage) */
.res-progress { height: 10px; background: var(--bg-alt); border-radius: var(--radius-full); overflow: hidden; margin: 6px 0 2px; }
.res-progress span { display: block; height: 100%; background: var(--primary); border-radius: var(--radius-full); transition: width var(--transition); }

/* BAL rating card */
.res-bal { padding: 16px 18px; background: var(--bg-alt); border-radius: var(--radius); }
.res-bal-level { font-size: 1.5rem; font-weight: 800; }
.res-bal-heat { font-size: .9rem; font-weight: 700; color: var(--text-light); margin-top: 2px; }
.res-bal-summary { font-size: .88rem; color: var(--text-light); margin-top: 8px; }
.res-jtable tr.res-bal-cur td { background: var(--primary-light); font-weight: 700; }

/* ---------- Tool picker (modal) ---------- */
.tool-picker { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; margin-top: 8px; }
.tool-pick { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1.5px solid var(--border); border-radius: var(--radius); background: #fff; cursor: pointer; text-align: left; font-family: inherit; transition: all var(--transition); }
.tool-pick:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-2px); }
.tool-pick .tp-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; font-weight: 700; }
.tool-pick strong { display: block; font-size: .92rem; color: var(--secondary-dark); }
.tool-pick span { font-size: .78rem; color: var(--text-muted); }

/* ---------- Modal extras ---------- */
.modal-sub { text-align: center; color: var(--text-light); margin-top: -12px; margin-bottom: 22px; }
.modal-sm { max-width: 400px; }
.modal-actions { display: flex; gap: 12px; margin-top: 24px; }
.modal-actions .btn { flex: 1; }

/* ---------- Access gate ---------- */
.access-gate {
    position: fixed; inset: 0; z-index: 4000;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--side-bg), #1e3a5f);
    overflow-y: auto;
}
.gate-card {
    background: #fff;
    border-radius: 20px;
    padding: 40px 36px;
    max-width: 440px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-xl);
    animation: modalIn .35s ease;
}
.gate-icon {
    width: 64px; height: 64px; margin: 0 auto 20px;
    border-radius: 18px;
    background: var(--gradient); color: #fff;
    display: flex; align-items: center; justify-content: center;
}
.gate-icon svg { width: 30px; height: 30px; }
.gate-card h1 { font-size: 1.6rem; margin-bottom: 10px; }
.gate-card > p { color: var(--text-light); margin-bottom: 22px; }
.gate-price { font-size: 3rem; font-weight: 800; color: var(--secondary-dark); line-height: 1; margin-bottom: 24px; }
.gate-cur { font-size: 1.4rem; vertical-align: super; margin-right: 2px; }
.gate-per { font-size: 1rem; font-weight: 500; color: var(--text-muted); }
.gate-features { text-align: left; margin: 0 auto 26px; max-width: 300px; }
.gate-features li { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: .92rem; color: var(--text); }
.gate-features svg { color: var(--success); flex-shrink: 0; }
.gate-note { font-size: .82rem; color: var(--text-muted); margin-top: 14px; }
.gate-logout { background: none; border: none; color: var(--primary); font-weight: 600; font-size: .88rem; cursor: pointer; margin-top: 16px; font-family: inherit; }
.gate-logout:hover { text-decoration: underline; }

/* ---------- Toast ---------- */
.toast {
    position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 140%);
    background: var(--secondary-dark); color: #fff; padding: 13px 22px;
    border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 3000;
    font-size: .92rem; transition: transform .35s ease; max-width: 90vw;
}
.toast.show { transform: translate(-50%, 0); }
.toast.success { background: #15803d; }
.toast.error { background: var(--error); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; width: 280px;
        transform: translateX(-100%); transition: transform var(--transition);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .topbar-menu { display: flex; }
    .editor-body { grid-template-columns: 1fr; }
    .editor-aside { position: static; order: -1; }
    .stat-cards { grid-template-columns: repeat(2,1fr); }
}

/* Phones / large phones: keep wide result tables inside their cards (scroll
   horizontally rather than pushing the page) and tighten spacing. */
@media (max-width: 640px) {
    .res-block { padding: 18px 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .items-section { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .ai-msg.ai-bot { overflow-x: auto; }
    .res-cost, .res-calc, .res-jtable, .cmp-table, .items-table, .ai-table { min-width: 100%; }
    #compareBtn { margin-left: 0; }
}

@media (max-width: 560px) {
    .content { padding: 20px 16px 50px; }
    .topbar { padding: 0 16px; }
    .topbar-search { max-width: none; }
    .panel-head { flex-direction: column; align-items: stretch; }
    .stat-cards { grid-template-columns: repeat(2,1fr); gap: 12px; }
    .tool-picker { grid-template-columns: 1fr; }
    .field-row { grid-template-columns: 1fr; }
    .editor-bar-right { width: 100%; justify-content: space-between; }
    .editor-title { width: 100%; flex-basis: 100%; order: 3; }
    .save-status .save-text { display: none; }
    .res-metrics { grid-template-columns: repeat(2,1fr); }
    .ai-chat { max-height: 340px; }
    .ai-msg { max-width: 94%; }
}
