/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --change-new: #dcfce7;
    --change-modified: #fef9c3;
    --change-removed: #fee2e2;
    --sidebar-width: 340px;
    --header-height: 60px;
    --tab-height: 44px;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* === Header === */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-left h1 { font-size: 18px; font-weight: 700; }
.header-left .subtitle { font-size: 12px; color: var(--text-muted); margin-left: 8px; }
.header-right { display: flex; align-items: center; gap: 8px; }
.global-search {
    width: 260px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}
.global-search:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }

/* === Buttons === */
.btn {
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 4px 8px; font-size: 16px; line-height: 1; }

/* === Tab Bar === */
.tab-bar {
    display: flex;
    align-items: center;
    height: var(--tab-height);
    background: var(--surface);
    border-bottom: 2px solid var(--border);
    padding: 0 12px;
    overflow-x: auto;
    gap: 2px;
}
.tab-bar::-webkit-scrollbar { height: 3px; }
.tab-bar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }
.tab {
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all .15s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tab:hover { color: var(--text); background: #f8fafc; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab .flag { font-size: 16px; }
.tab-add {
    padding: 6px 14px;
    font-size: 18px;
    font-weight: 300;
    color: var(--text-muted);
    cursor: pointer;
    border: 1px dashed var(--border);
    background: none;
    border-radius: 6px;
    margin-left: 4px;
}
.tab-add:hover { background: #f1f5f9; color: var(--primary); border-color: var(--primary); }

/* === Content Area === */
.content-area {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* === Sections === */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}
.section-header:hover { background: #f1f5f9; }
.section-header h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.section-header .chevron { transition: transform .2s; font-size: 12px; color: var(--text-muted); }
.section-header .chevron.collapsed { transform: rotate(-90deg); }
.section-header-actions { display: flex; gap: 6px; align-items: center; }
.section-body { padding: 16px; }
.section-body.collapsed { display: none; }
.section-count { font-size: 11px; background: #e2e8f0; color: var(--text-muted); padding: 1px 8px; border-radius: 10px; font-weight: 500; }

/* === Data Tables === */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left;
    padding: 8px 10px;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background: #fafbfc;
    position: sticky;
    top: 0;
}
.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
}
.data-table tr:hover td { background: #f8fafc; }
.data-table td.editable { cursor: pointer; position: relative; }
.data-table td.editable:hover { background: #eff6ff; }
.data-table td.editable:hover::after {
    content: '\270E';
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--primary);
    opacity: .5;
}
.data-table .cell-edit {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--primary);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #eff6ff;
}

/* === Change Highlighting === */
.change-new { background: var(--change-new) !important; }
.change-modified { background: var(--change-modified) !important; }
.change-removed { background: var(--change-removed) !important; text-decoration: line-through; }
.verify-flag { color: #d97706; font-weight: 600; font-size: 11px; }
.verify-flag::before { content: '\26A0 '; }

/* === Cards / Info blocks === */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
}
.info-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    background: #fafbfc;
}
.info-card-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--primary-dark); }
.info-card-value { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.info-card-desc { font-size: 12px; color: var(--text-muted); }
.info-card-format { font-family: 'Courier New', monospace; font-size: 13px; background: #e2e8f0; padding: 2px 6px; border-radius: 3px; }
.info-card .mandatory-badge { font-size: 10px; color: var(--danger); font-weight: 600; text-transform: uppercase; }
.info-card .optional-badge { font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }

/* === Sub-sections (within Payroll) === */
.sub-section { margin-bottom: 16px; }
.sub-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* === Tags / Badges === */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}
.tag-active { background: #dcfce7; color: #15803d; }
.tag-upcoming { background: #fef9c3; color: #a16207; }
.tag-proposed { background: #e0e7ff; color: #4338ca; }
.tag-enacted { background: #dcfce7; color: #15803d; }
.tag-under_review { background: #fef3c7; color: #92400e; }
.tag-not_required { background: #f1f5f9; color: #64748b; }

/* === Reference Links === */
.ref-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ref-link {
    font-size: 12px;
    color: var(--primary);
    text-decoration: none;
    padding: 2px 8px;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    background: #eff6ff;
}
.ref-link:hover { background: #dbeafe; }

/* === Notes === */
.notes-area {
    width: 100%;
    min-height: 60px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    outline: none;
}
.notes-area:focus { border-color: var(--primary); }

/* === Change Log Sidebar === */
.change-log-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 12px rgba(0,0,0,.08);
    z-index: 200;
    display: flex;
    flex-direction: column;
}
.change-log-sidebar[hidden] { display: none; }
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 15px; }
.sidebar-close { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.sidebar-body { flex: 1; overflow-y: auto; padding: 12px; }
.change-item {
    padding: 8px 10px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 12px;
}
.change-item-header { display: flex; justify-content: space-between; margin-bottom: 4px; }
.change-item-table { font-weight: 600; color: var(--primary); }
.change-item-time { color: var(--text-muted); font-size: 11px; }
.change-item-field { color: var(--text-muted); }
.change-item-values { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.change-old { text-decoration: line-through; color: var(--danger); font-size: 11px; }
.change-new-val { color: var(--success); font-weight: 500; font-size: 11px; }
.change-arrow { color: var(--text-muted); }

/* === FAB === */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37,99,235,.3);
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
}
.fab:hover { background: var(--primary-dark); transform: scale(1.05); }
.change-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--surface);
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* === Forms === */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .3px; }
.form-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.1); }
select.form-input { cursor: pointer; }

/* === Loading === */
.loading { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Empty state === */
.empty-state { text-align: center; padding: 30px; color: var(--text-muted); font-size: 13px; }

/* === Search Highlight === */
.search-highlight { background: #fbbf24; padding: 0 2px; border-radius: 2px; }

/* === Jurisdiction header info === */
.jurisdiction-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.jurisdiction-header-left { display: flex; align-items: center; gap: 12px; }
.jurisdiction-header-left .jur-flag { font-size: 28px; }
.jurisdiction-header-left .jur-name { font-size: 20px; font-weight: 700; }
.jurisdiction-header-left .jur-code { font-size: 13px; color: var(--text-muted); background: #e2e8f0; padding: 2px 8px; border-radius: 4px; }

/* === Auth === */
#authOverlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 32px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.1);
}
.auth-card h2 { font-size: 20px; margin-bottom: 4px; }
.auth-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.auth-error { color: var(--danger); font-size: 12px; margin-bottom: 8px; display: none; }
.auth-user-info {
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px 10px;
    background: #f1f5f9;
    border-radius: 4px;
    white-space: nowrap;
}
.auth-role-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: 4px;
}
.auth-role-admin { background: #fef3c7; color: #92400e; }
.auth-role-viewer { background: #e0e7ff; color: #4338ca; }
.header-separator { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

/* === Responsive === */
@media (max-width: 768px) {
    .app-header { flex-direction: column; height: auto; padding: 10px; gap: 8px; }
    .header-right { flex-wrap: wrap; }
    .global-search { width: 100%; }
    .info-grid { grid-template-columns: 1fr; }
    .change-log-sidebar { width: 100%; }
}
