*{box-sizing:border-box;margin:0;padding:0}
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;background:#f5f6fa;color:#2d3748;font-size:14px}
header{background:#1a202c;color:#fff;padding:18px 32px}
header .header-top{display:flex;justify-content:space-between;align-items:center}
header h1{font-size:20px;font-weight:600}
header .meta{font-size:12px;color:#a0aec0}

/* Tab bar */
.tab-bar{display:flex;gap:0;margin-top:14px}
.tab-bar .tab{padding:8px 20px;font-size:13px;font-weight:500;color:#a0aec0;background:none;border:none;border-bottom:2px solid transparent;cursor:pointer;transition:color .15s,border-color .15s}
.tab-bar .tab:hover{color:#e2e8f0}
.tab-bar .tab.active{color:#fff;border-bottom-color:#4fc3f7}
.page{max-width:1440px;margin:0 auto;padding:24px 32px}

/* Loading overlay */
.loading-overlay{position:fixed;inset:0;background:#f5f6fa;display:flex;align-items:center;justify-content:center;z-index:1000;flex-direction:column;gap:16px}
.loading-overlay h2{font-size:18px;color:#2d3748}
.loading-overlay .progress-bar{width:300px;height:8px;background:#e2e8f0;border-radius:4px;overflow:hidden}
.loading-overlay .progress-fill{height:100%;background:#3182ce;border-radius:4px;transition:width .5s ease}
.loading-overlay .progress-text{font-size:13px;color:#718096}

/* Chart inline stats */
.chart-stats{display:flex;gap:6px 14px;align-items:baseline;font-size:12px;color:#718096;flex-wrap:wrap;justify-content:flex-end;text-align:right}
.chart-stats b{color:#2d3748;font-weight:600}
.chart-stats .stat-up{color:#276749;font-weight:600}
.chart-stats .stat-down{color:#c53030;font-weight:600}
.chart-stats .stat-sep{color:#cbd5e0}

/* Cards */
.card{background:#fff;border-radius:10px;padding:22px 24px;box-shadow:0 1px 4px rgba(0,0,0,.08);margin-bottom:18px}
.card-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:4px;flex-wrap:wrap;gap:8px}
.card-header h2{font-size:15px;font-weight:600;color:#2d3748}
.card-sql-bar{display:flex;align-items:center;gap:8px;margin-bottom:14px}
.chart-notice{font-size:11px;color:#a0aec0;margin-top:8px;font-style:italic}

/* Controls */
.ctrl{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
.ctrl label{font-size:13px;color:#718096}

/* Filter bar layout */
.filter-bar{display:flex;align-items:center;gap:16px;flex-wrap:wrap}
.filter-group{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.filter-group+.filter-group{border-left:1px solid #e2e8f0;padding-left:16px}
.filter-group label{font-size:13px;color:#718096}
.filter-group-label{font-size:12px;color:#a0aec0;font-weight:600;text-transform:uppercase;letter-spacing:.3px}
.filter-group--exclude{gap:12px}
.exclude-cb{display:flex;align-items:center;gap:5px;cursor:pointer;font-size:13px;color:#4a5568}
select{padding:6px 10px;border:1px solid #e2e8f0;border-radius:6px;font-size:13px;background:#fff;cursor:pointer;min-width:180px}
select:focus{outline:none;border-color:#4fc3f7}
input[type=checkbox]{width:15px;height:15px;cursor:pointer;accent-color:#3182ce}

/* Year filter dropdown */
.year-filter{position:relative;display:inline-block}
.year-btn{padding:6px 10px;border:1px solid #e2e8f0;border-radius:6px;font-size:13px;background:#fff;cursor:pointer;white-space:nowrap;color:#2d3748}
.year-btn:hover{background:#f7fafc}
.tableau-btn{padding:6px 12px;border:1px solid #e2e8f0;border-radius:6px;font-size:13px;background:#f7fafc;cursor:pointer;white-space:nowrap;color:#4a5568;transition:border-color .15s,background .15s}
.tableau-btn:hover{background:#edf2f7;border-color:#cbd5e0}
.tableau-btn.active{border-color:#3182ce;background:#ebf8ff;color:#2b6cb0;font-weight:600}
.year-dd{position:absolute;top:110%;right:0;background:#fff;border:1px solid #e2e8f0;border-radius:8px;padding:10px 14px;box-shadow:0 4px 16px rgba(0,0,0,.12);z-index:200;display:none;min-width:110px}
.year-dd.open{display:block}
.year-dd label{display:flex;align-items:center;gap:8px;font-size:13px;padding:5px 0;cursor:pointer;color:#2d3748}

/* Charts */
canvas{max-width:100%;cursor:crosshair}
.chart-legend{display:flex;gap:16px;margin-top:10px;flex-wrap:wrap;justify-content:center}
.chart-legend-grid{margin-top:10px;max-height:200px;overflow-y:auto;display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:3px 10px}
.legend-item{display:flex;align-items:center;gap:5px;font-size:12px;color:#4a5568;padding:2px 4px;cursor:pointer;border-radius:3px;transition:opacity .15s}
.legend-item:hover{background:rgba(0,0,0,.04)}
.legend-item.hidden{opacity:0.3}
.legend-item.hidden .legend-name{text-decoration:line-through}
.legend-dot{width:10px;height:10px;border-radius:2px;flex-shrink:0}
.legend-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.legend-val{margin-left:auto;font-weight:600}
.legend-val .stat-up{color:#276749}
.legend-val .stat-down{color:#c53030}
.click-hint{font-size:11px;color:#a0aec0;margin-top:6px;text-align:center}

.btn-close{background:none;border:1px solid #e2e8f0;border-radius:6px;padding:4px 12px;font-size:12px;cursor:pointer;color:#718096}
.btn-close:hover{background:#f7fafc}
.table-wrap{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:12px}
thead th{background:#edf2f7;padding:9px 12px;text-align:left;font-weight:600;color:#4a5568;white-space:nowrap}
tbody tr:hover{background:#f7fafc}
tbody td{padding:8px 12px;border-bottom:1px solid #edf2f7;vertical-align:top}
.subj-cell{max-width:340px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
td a{color:#3182ce;text-decoration:none}
td a:hover{text-decoration:underline}
.badge{display:inline-block;padding:2px 7px;border-radius:10px;font-size:11px;font-weight:600}
.s-new{background:#bee3f8;color:#2b6cb0}
.s-open{background:#c6f6d5;color:#276749}
.s-hold{background:#fefcbf;color:#744210}
.s-solved{background:#edf2f7;color:#4a5568}
.s-closed{background:#e2e8f0;color:#718096}

/* Context menu */
.ctx-menu{display:none;position:fixed;z-index:500;background:#fff;border:1px solid #e2e8f0;border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,.15);min-width:200px;padding:4px 0}
.ctx-item{padding:8px 16px;font-size:13px;color:#2d3748;cursor:pointer;white-space:nowrap}
.ctx-item:hover{background:#edf2f7}

/* Focus/filter banner */
.focus-banner{display:flex;align-items:center;justify-content:space-between;gap:12px;background:#ebf8ff;border:1px solid #bee3f8;border-radius:8px;padding:8px 16px;margin-bottom:18px;font-size:13px;color:#2b6cb0}
.filter-tag{display:inline-flex;align-items:center;gap:4px;background:#bee3f8;color:#2b6cb0;padding:2px 8px;border-radius:12px;font-size:12px;font-weight:500}
.filter-tag button{background:none;border:none;cursor:pointer;color:#2b6cb0;font-size:13px;padding:0 2px;line-height:1}
.filter-tag button:hover{color:#1a365d}

/* Filter dropdown component */
.filter-dd{position:relative;display:inline-block}
.filter-dd-btn{padding:6px 12px;border:1px solid #e2e8f0;border-radius:6px;font-size:13px;background:#fff;cursor:pointer;white-space:nowrap;color:#2d3748;transition:border-color .15s}
.filter-dd-btn:hover{background:#f7fafc}
.filter-dd-btn.has-filter{border-color:#3182ce;background:#ebf8ff;color:#2b6cb0}
.dd-count{font-weight:600;color:#3182ce}
.filter-dd-panel{position:absolute;top:110%;left:0;background:#fff;border:1px solid #e2e8f0;border-radius:8px;padding:8px 0;box-shadow:0 4px 16px rgba(0,0,0,.12);z-index:200;display:none;min-width:180px;max-width:280px}
.filter-dd-panel.open{display:block}
.filter-dd-search{width:calc(100% - 16px);margin:0 8px 6px;padding:5px 8px;border:1px solid #e2e8f0;border-radius:5px;font-size:12px;outline:none}
.filter-dd-search:focus{border-color:#4fc3f7}
.filter-dd-presets{display:flex;gap:4px;padding:0 8px 6px;flex-wrap:wrap}
.filter-dd-presets button{padding:2px 8px;border:1px solid #e2e8f0;border-radius:12px;font-size:11px;background:#f7fafc;cursor:pointer;color:#4a5568}
.filter-dd-presets button:hover{background:#edf2f7}
.filter-dd-actions{padding:0 12px 4px;font-size:12px;color:#718096;border-bottom:1px solid #f0f0f0;margin-bottom:4px}
.filter-dd-actions a{color:#3182ce;text-decoration:none;cursor:pointer}
.filter-dd-actions a:hover{text-decoration:underline}
.filter-dd-list{max-height:260px;overflow-y:auto;padding:0 4px}
.filter-dd-list label{display:flex;align-items:center;gap:6px;font-size:12px;padding:3px 8px;cursor:pointer;color:#2d3748;border-radius:4px}
.filter-dd-list label:hover{background:#f7fafc}
.filter-dd-list input[type=checkbox]{width:14px;height:14px;cursor:pointer;accent-color:#3182ce;flex-shrink:0}

/* Filter indicator badges on chart cards */
.filter-indicator{font-size:11px;padding:2px 0;margin-bottom:4px}
.fi-all-applied{color:#718096}
.fi-has-excluded{color:#c05621}

/* Backlog filter note */
.backlog-filter-note{font-size:11px;color:#a0aec0;margin-left:8px;font-style:italic}

/* Card loading spinner */
.card-spinner{position:absolute;inset:0;background:rgba(255,255,255,.6);display:flex;align-items:center;justify-content:center;border-radius:10px;z-index:10}
.spinner-ring{width:28px;height:28px;border:3px solid #e2e8f0;border-top-color:#3182ce;border-radius:50%;animation:spin .6s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* Modal overlay */
.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:600;display:flex;align-items:center;justify-content:center}
.modal{background:#fff;border-radius:12px;box-shadow:0 8px 32px rgba(0,0,0,.2);width:90vw;max-width:1200px;max-height:80vh;display:flex;flex-direction:column}
.modal-header{display:flex;justify-content:space-between;align-items:center;padding:16px 20px;border-bottom:1px solid #e2e8f0;flex-shrink:0}
.modal-header h2{font-size:15px;font-weight:600;color:#2d3748}
.modal-body{overflow-y:auto;padding:0 20px 16px;flex:1}
.modal-pagination{display:flex;justify-content:center;align-items:center;gap:4px;padding:12px 0 4px;flex-shrink:0}
.pg-btn{padding:4px 10px;border:1px solid #e2e8f0;border-radius:6px;background:#fff;color:#4a5568;cursor:pointer;font-size:13px}
.pg-btn:hover:not(:disabled){background:#edf2f7}
.pg-btn:disabled{opacity:.4;cursor:default}
.pg-btn.pg-active{background:#3182ce;color:#fff;border-color:#3182ce}
.pg-ellipsis{color:#a0aec0;font-size:13px;padding:0 2px}

/* Modal filter bar */
.modal-filter-bar{display:flex;gap:10px;padding:12px 20px;border-bottom:1px solid #e2e8f0;align-items:flex-start;flex-shrink:0;background:#f7fafc}
.modal-filter-bar select{padding:5px 8px;border:1px solid #e2e8f0;border-radius:5px;font-size:12px;background:#fff;cursor:pointer;min-width:0;width:100%}
.modal-filter-bar .btn-close{align-self:flex-start;margin-top:1px;white-space:nowrap}
.mf-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:6px;flex:1}
.modal-applied-filters{padding:8px 20px;background:#f7fafc;border-bottom:1px solid #e2e8f0;font-size:12px;color:#4a5568;flex-shrink:0}
.modal-applied-filters .filter-tag{margin-right:6px}

/* Chart scope filters in modal */
.chart-filters{padding:8px 20px;background:#fffbeb;border-bottom:1px solid #f6e05e;font-size:12px;flex-shrink:0;display:flex;align-items:center;gap:14px;flex-wrap:wrap}
.cf-label{font-weight:600;color:#744210;white-space:nowrap}
.cf-group{display:flex;align-items:center;gap:8px;padding:0 4px}
.cf-group-label{color:#92400e;font-weight:500;white-space:nowrap}
.cf-checks{display:flex;gap:8px;flex-wrap:wrap}
.cf-checks label{display:flex;align-items:center;gap:4px;cursor:pointer;color:#4a5568;white-space:nowrap}
.cf-checks input[type=checkbox]{width:13px;height:13px;accent-color:#d69e2e;cursor:pointer}
.cf-badge{display:inline-block;padding:1px 8px;border-radius:10px;font-size:11px;background:#fefcbf;color:#744210}
.cf-sep{width:1px;height:16px;background:#f6e05e}

/* Export button */
.btn-export{background:#3182ce;color:#fff;border:none;border-radius:6px;padding:5px 14px;font-size:12px;cursor:pointer;font-weight:500}
.btn-export:hover{background:#2b6cb0}

/* SQL query toggle */
.db-label{font-size:10px;color:#a0aec0;font-family:'SF Mono',SFMono-Regular,Menlo,Consolas,monospace;white-space:nowrap}
.btn-sql{background:none;border:1px solid #e2e8f0;border-radius:6px;padding:3px 10px;font-size:11px;cursor:pointer;color:#718096;font-family:monospace}
.btn-sql:hover{background:#f7fafc;color:#4a5568}
.btn-sql.active{background:#edf2f7;color:#2d3748;border-color:#cbd5e0}
.sql-block{display:none;margin-top:12px;background:#1a202c;color:#e2e8f0;border-radius:8px;padding:14px 18px;overflow-x:auto;font-size:12px;line-height:1.5;font-family:'SF Mono',SFMono-Regular,Menlo,Consolas,monospace;white-space:pre;max-height:400px;overflow-y:auto}
.sql-block.open{display:block}
.sql-block .sql-label{display:block;color:#718096;font-size:11px;margin-bottom:8px;font-style:italic}
.sql-toolbar{display:flex;gap:6px;margin-bottom:10px;position:sticky;top:0;background:#1a202c;padding-bottom:6px;z-index:1}
.sql-toolbar .sql-action{background:#2d3748;border:1px solid #4a5568;border-radius:4px;padding:2px 10px;font-size:11px;cursor:pointer;color:#a0aec0;font-family:inherit}
.sql-toolbar .sql-action:hover{background:#4a5568;color:#e2e8f0}
.sql-toolbar .sql-action.loading{opacity:0.5;pointer-events:none}

/* Rebuild banner */
.rebuild-banner{position:fixed;top:0;left:0;right:0;z-index:1100;display:flex;align-items:center;gap:10px;padding:10px 20px;background:#fffbeb;border-bottom:2px solid #f59e0b;color:#92400e;font-size:13px;font-weight:500;box-shadow:0 2px 8px rgba(0,0,0,.1);animation:slideDown .3s ease}
@keyframes slideDown{from{transform:translateY(-100%)}to{transform:translateY(0)}}
.rebuild-icon{font-size:18px}
.rebuild-btn{background:#f59e0b;color:#fff;border:none;border-radius:6px;padding:5px 16px;font-size:12px;font-weight:600;cursor:pointer;transition:background .15s}
.rebuild-btn:hover{background:#d97706}
.rebuild-btn:disabled{opacity:.5;cursor:default}
.rebuild-dismiss{background:none;border:none;font-size:18px;color:#92400e;cursor:pointer;margin-left:auto;padding:0 4px;opacity:.6}
.rebuild-dismiss:hover{opacity:1}
.rebuild-banner.success{background:#ecfdf5;border-color:#10b981;color:#065f46}
.rebuild-banner.error{background:#fef2f2;border-color:#ef4444;color:#991b1b}

/* Load error banner */
.load-error-banner{position:fixed;top:0;left:0;right:0;z-index:1050;display:flex;align-items:center;gap:8px;padding:10px 20px;background:#fef2f2;border-bottom:2px solid #ef4444;color:#991b1b;font-size:13px;font-weight:500;box-shadow:0 2px 8px rgba(0,0,0,.1);animation:slideDown .3s ease}

/* Reference check banner */
.ref-check-banner{position:fixed;top:0;left:0;right:0;z-index:1049;display:flex;align-items:center;gap:8px;padding:10px 20px;background:#fffbeb;border-bottom:2px solid #f59e0b;color:#92400e;font-size:13px;font-weight:500;box-shadow:0 2px 8px rgba(0,0,0,.1)}

/* Rebuild data button & modal */
.rebuild-data-btn{background:transparent;border:1px solid #4a5568;color:#a0aec0;border-radius:6px;padding:4px 12px;font-size:12px;cursor:pointer;transition:all .15s}
.rebuild-data-btn:hover{background:#2d3748;color:#e2e8f0;border-color:#718096}
.rebuild-sources{display:flex;flex-direction:column;gap:8px}
.rebuild-cb{display:flex;align-items:center;gap:8px;font-size:13px;color:#2d3748;cursor:pointer}
.rebuild-cb input[type="checkbox"]{cursor:pointer;width:16px;height:16px}
.rebuild-cb input[type="checkbox"]:disabled{cursor:default;opacity:.5}
.rebuild-indent{padding-left:24px}
.rebuild-src-tag{font-size:10px;color:#718096;background:#edf2f7;padding:1px 6px;border-radius:3px;font-weight:500}
.rebuild-warning{margin-top:12px;padding:8px 12px;background:#fffbeb;border:1px solid #f59e0b;border-radius:6px;font-size:12px;color:#92400e}
.btn-cancel{background:#edf2f7;color:#4a5568;border:none;border-radius:6px;padding:6px 16px;font-size:13px;cursor:pointer}
.btn-cancel:hover{background:#e2e8f0}
.btn-primary{background:#3182ce;color:#fff;border:none;border-radius:6px;padding:6px 16px;font-size:13px;font-weight:600;cursor:pointer}
.btn-primary:hover{background:#2b6cb0}
.btn-primary:disabled{opacity:.5;cursor:default}

/* Tableau tab */
.tableau-section{margin-bottom:8px}
.tableau-section-title{font-size:14px;font-weight:600;color:#4a5568;margin:16px 0 8px;padding-left:4px}
.tableau-match{font-size:11px;padding:2px 8px;border-radius:10px;font-weight:500;white-space:nowrap}
.tableau-match.ok{background:#c6f6d5;color:#276749}
.tableau-match.diff{background:#fefcbf;color:#975a16}
.tableau-match.err{background:#fed7d7;color:#9b2c2c}
.tableau-match.na{background:#edf2f7;color:#718096}
