:root {
    --primary: #1a365d;
    --primary-light: #2d5a8e;
    --accent: #c0392b;
    --accent-light: #fff5f5;
    --bg: #f7fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --success: #38a169;
    --warning: #d69e2e;
    --danger: #e53e3e;
    --info: #3182ce;
    --purple: #6b46c1;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 14px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; font-size: 14px; }

/* Header */
.header { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%); color: #fff; padding: 24px 32px; }
.header-inner { max-width: 1400px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; }
.header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.header .subtitle { font-size: 0.85rem; opacity: 0.85; margin-top: 2px; }
.header .prepared { font-size: 0.75rem; opacity: 0.6; margin-top: 4px; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.header-actions button { padding: 8px 16px; border: 1px solid rgba(255,255,255,0.3); border-radius: var(--radius); background: rgba(255,255,255,0.1); color: #fff; cursor: pointer; font-size: 0.8rem; font-weight: 600; transition: all 0.15s; }
.header-actions button:hover { background: rgba(255,255,255,0.25); }
.header-actions a { color: rgba(255,255,255,0.9); text-decoration: none; font-size: 0.82rem; font-weight: 600; }
.header-actions a:hover { color: #fff; }

/* Tier indicator */
.tier-bar { background: #fff; border-bottom: 1px solid var(--border); padding: 8px 32px; }
.tier-bar-inner { max-width: 1400px; margin: 0 auto; display: flex; gap: 16px; align-items: center; }
.tier-bar .tier-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.04em; }
.tier-badge { padding: 4px 12px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; }
.tier-badge.t1 { background: #ebf8ff; color: var(--info); border: 1px solid #bee3f8; }
.tier-badge.t2 { background: #faf5ff; color: var(--purple); border: 1px solid #e9d8fd; }

/* Navigation */
.nav { background: #fff; border-bottom: 2px solid var(--border); position: sticky; top: 0; z-index: 100; }
.nav-inner { max-width: 1400px; margin: 0 auto; display: flex; gap: 0; overflow-x: auto; }
.nav-tab { padding: 14px 20px; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 3px solid transparent; transition: all 0.15s; white-space: nowrap; background: none; border-top: none; border-left: none; border-right: none; text-decoration: none; display: inline-flex; align-items: center; }
.nav-tab:hover { color: var(--primary); background: #f8faff; }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-tab .tier-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; }
.nav-tab .tier-dot.t2 { background: var(--purple); }

/* Main */
.main { max-width: 1400px; margin: 0 auto; padding: 24px 32px; }

/* Stats Bar */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border-left: 4px solid var(--primary); }
.stat .value { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.stat .label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.stat.danger { border-left-color: var(--danger); }
.stat.danger .value { color: var(--danger); }
.stat.warning { border-left-color: var(--warning); }
.stat.warning .value { color: var(--warning); }
.stat.success { border-left-color: var(--success); }
.stat.success .value { color: var(--success); }
.stat.info { border-left-color: var(--info); }
.stat.info .value { color: var(--info); }
.stat.purple { border-left-color: var(--purple); }
.stat.purple .value { color: var(--purple); }

/* Section */
.section-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 16px; color: var(--primary); }
.section-desc { color: var(--text-secondary); margin-bottom: 20px; font-size: 0.9rem; }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.card-header { padding: 14px 20px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; transition: background 0.15s; }
.card-header:hover { background: #f8fafc; }
.card-header h3 { font-size: 0.92rem; font-weight: 700; }
.card-header .badge { font-size: 0.68rem; padding: 3px 10px; border-radius: 20px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.badge { font-size: 0.68rem; padding: 3px 10px; border-radius: 20px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-critical { background: #fff5f5; color: var(--danger); }
.badge-high { background: #fffaf0; color: #c05621; }
.badge-medium { background: #fffff0; color: #975a16; }
.badge-low { background: #f0fff4; color: var(--success); }
.badge-mandatory { background: #fff5f5; color: var(--danger); }
.badge-optional { background: #f0fff4; color: var(--success); }
.badge-conditional { background: #ebf8ff; color: var(--info); }
.badge-error { background: var(--danger); color: #fff; }
.badge-stable { background: #f0fff4; color: var(--success); }
.badge-changing { background: #fff5f5; color: var(--danger); }
.badge-review { background: #fffbeb; color: var(--warning); }
.badge-warning { background: #fffbeb; color: var(--warning); }
.badge-uk { background: #ebf8ff; color: #2b6cb0; }
.badge-eu { background: #faf5ff; color: #6b46c1; }
.badge-both { background: #f0fff4; color: var(--success); }
.badge-go-live { background: #fff5f5; color: var(--danger); }
.badge-post.go-live { background: #f0fff4; color: var(--success); }
.card-body { padding: 0 20px 20px; display: none; }
.card.open .card-body { display: block; }
.card.open .card-header .chevron { transform: rotate(180deg); }
.chevron { transition: transform 0.2s; font-size: 0.8rem; color: var(--text-muted); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 12px 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { background: #f7fafc; padding: 10px 14px; text-align: left; font-weight: 700; color: var(--text-secondary); border-bottom: 2px solid var(--border); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: #fafbfd; }

/* Rule blocks */
.rule-block { background: #f7fafc; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.rule-block .question { font-weight: 700; font-size: 0.95rem; color: var(--primary); margin-bottom: 8px; }
.rule-block .trigger { margin: 6px 0 6px 16px; font-size: 0.85rem; }
.rule-block .trigger .arrow { color: var(--accent); font-weight: 700; margin-right: 6px; }
.rule-block .regulation-ref { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }
.rule-block .regulation-ref a { color: var(--info); text-decoration: none; }

/* Filters */
.filters { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.04em; }
.filter-group select, .filter-group input { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.85rem; background: #fff; min-width: 160px; }
.filter-group input { min-width: 240px; }

/* Error list */
.error-item { background: var(--accent-light); border: 1px solid #fed7d7; border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.error-item .error-title { font-weight: 700; color: var(--danger); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.error-item .error-detail { font-size: 0.85rem; color: var(--text-secondary); }
.error-item .error-action { margin-top: 8px; font-weight: 600; color: var(--text); }

/* Regulation detail */
.reg-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 12px 0; }
.reg-meta-item { font-size: 0.85rem; }
.reg-meta-item .meta-label { font-weight: 700; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; }

/* Library views */
.lib-view-toggle { display: flex; gap: 0; margin-bottom: 16px; }
.lib-view-btn { padding: 8px 18px; border: 2px solid var(--border); background: #fff; cursor: pointer; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); transition: all 0.15s; }
.lib-view-btn:first-child { border-radius: 8px 0 0 8px; }
.lib-view-btn:last-child { border-radius: 0 8px 8px 0; }
.lib-view-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.lib-view-btn:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.category-card { background: #fff; border-radius: 12px; border: 1px solid var(--border); overflow: hidden; transition: box-shadow 0.2s; }
.category-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
.category-card-header { padding: 14px 18px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.category-card-header h3 { font-size: 0.9rem; font-weight: 700; }
.category-card-header .count { background: rgba(255,255,255,0.25); padding: 2px 10px; border-radius: 12px; font-size: 0.72rem; font-weight: 600; }
.category-card-body { padding: 12px 18px; max-height: 300px; overflow-y: auto; }
.category-leg-item { padding: 8px 0; border-bottom: 1px solid #f1f5f9; display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.category-leg-item:last-child { border-bottom: none; }
.category-leg-item:hover { background: #f8fafc; margin: 0 -18px; padding-left: 26px; padding-right: 26px; }
.category-leg-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.category-leg-dot.stable { background: var(--success); }
.category-leg-dot.change_coming { background: var(--danger); }
.category-leg-dot.under_review { background: var(--warning); }
.category-leg-name { font-size: 0.82rem; font-weight: 600; }
.category-leg-scope { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* Legislation entries */
.leg-entry { background: #fff; border-radius: 10px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); overflow: hidden; border-left: 4px solid var(--accent); }
.leg-entry-header { padding: 14px 18px; cursor: pointer; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; user-select: none; }
.leg-entry-header:hover { background: #f8fafc; }
.leg-entry-title { font-weight: 700; font-size: 0.9rem; }
.leg-entry-ref { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.leg-entry-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tag { padding: 2px 8px; border-radius: 10px; font-size: 0.68rem; font-weight: 600; }
.tag.region { background: #fef3c7; color: #92400e; }
.tag.category { background: #e0e7ff; color: #4338ca; }
.tag.body { background: #f3e8ff; color: #7c3aed; }
.tag.change { background: #fee2e2; color: #991b1b; }
.tag.stable-tag { background: #dcfce7; color: #166534; }
.tag.type-leg { background: #dbeafe; color: #1e40af; }
.tag.unclear { background: #fef3c7; color: #92400e; border: 1px dashed #f59e0b; }
.leg-entry-toggle { font-size: 0.7rem; color: var(--text-muted); transition: transform 0.2s; flex-shrink: 0; margin-top: 4px; }
.leg-entry.expanded .leg-entry-toggle { transform: rotate(180deg); }
.leg-entry-body { display: none; padding: 0 18px 16px; border-top: 1px solid var(--border); }
.leg-entry.expanded .leg-entry-body { display: block; }

.leg-detail-section { margin-top: 12px; }
.leg-detail-section h4 { font-size: 0.8rem; font-weight: 700; color: var(--accent); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.3px; }
.leg-detail-section p { font-size: 0.82rem; line-height: 1.7; }
.leg-detail-section ul { font-size: 0.82rem; line-height: 1.7; padding-left: 18px; }
.leg-detail-section .source-link { font-size: 0.78rem; color: var(--accent); text-decoration: none; font-weight: 600; }
.leg-detail-section .source-link:hover { text-decoration: underline; }
.unclear-note { background: #fffbeb; border: 1px dashed #f59e0b; border-radius: 6px; padding: 8px 12px; font-size: 0.78rem; color: #92400e; margin-top: 8px; }

.article-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f8fafc; font-size: 0.8rem; }
.article-row:last-child { border-bottom: none; }
.article-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.article-dot.stable { background: var(--success); }
.article-dot.change_coming { background: var(--danger); }
.article-dot.under_review { background: var(--warning); }
.article-ref { font-weight: 700; min-width: 200px; flex-shrink: 0; }
.article-desc { flex: 1; }
.article-change-note { font-size: 0.72rem; color: #991b1b; font-style: italic; margin-top: 2px; }

.legend-bar { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 18px; margin-top: 16px; }
.legend-bar h4 { font-size: 0.78rem; margin-bottom: 6px; color: var(--text-muted); }
.legend-items { display: flex; flex-wrap: wrap; gap: 16px; font-size: 0.75rem; align-items: center; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

/* Modal */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 200; }
.modal-overlay.visible { display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 12px; max-width: 900px; width: 92%; max-height: 85vh; overflow-y: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-close { float: right; cursor: pointer; font-size: 1.3rem; color: var(--text-muted); padding: 4px 10px; border-radius: 4px; background: none; border: none; }
.modal-close:hover { background: #f3f4f6; }

/* Print */
@media print {
    .nav, .header-actions, .filters, .tier-bar, .lib-view-toggle { display: none !important; }
    .header { padding: 12px 20px; }
    .card-body { display: block !important; }
    .leg-entry-body { display: block !important; }
}

.error-banner {
    background: var(--accent-light);
    border: 1px solid var(--danger);
    border-left: 4px solid var(--danger);
    border-radius: var(--radius);
    padding: 20px;
    margin: 24px 0;
}
.error-banner h3 { color: var(--danger); margin: 0 0 8px 0; }
.error-banner p { margin: 4px 0; color: var(--text-secondary); font-size: 0.9rem; }
.retry-btn {
    margin-top: 12px;
    padding: 8px 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
}
.retry-btn:hover { background: var(--primary-light); }

/* Manage Legislation link */
.manage-link-btn {
    padding: 8px 18px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    transition: background 0.15s;
    white-space: nowrap;
}
.manage-link-btn:hover { background: var(--primary-light); color: #fff; }

/* Legislation Management page */
.mgmt-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.mgmt-header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.back-link { font-size: 0.82rem; color: var(--primary); text-decoration: none; font-weight: 600; }
.back-link:hover { text-decoration: underline; }
.mgmt-add-btn { padding: 8px 18px; background: var(--success); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; font-size: 0.82rem; font-weight: 600; transition: background 0.15s; }
.mgmt-add-btn:hover { background: #2f855a; }
.mgmt-actions-cell { white-space: nowrap; }
.mgmt-edit-btn { padding: 4px 12px; background: var(--info); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 0.78rem; font-weight: 600; margin-right: 4px; transition: background 0.15s; }
.mgmt-edit-btn:hover { background: #2b6cb0; }
.mgmt-delete-btn { padding: 4px 12px; background: var(--danger); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 0.78rem; font-weight: 600; transition: background 0.15s; }
.mgmt-delete-btn:hover { background: #c53030; }

.mgmt-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.mgmt-form-full { grid-column: 1 / -1; }
.mgmt-form-group { display: flex; flex-direction: column; gap: 4px; }
.mgmt-form-group label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.04em; }
.mgmt-form-input { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.85rem; background: #fff; width: 100%; }
.mgmt-form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(26,54,93,0.1); }
.mgmt-form-textarea { min-height: 80px; resize: vertical; }
.mgmt-checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--text); text-transform: none; letter-spacing: normal; cursor: pointer; }
.mgmt-form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.mgmt-cancel-btn { padding: 8px 20px; background: #fff; color: var(--text-secondary); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: all 0.15s; }
.mgmt-cancel-btn:hover { background: #f7fafc; border-color: var(--text-muted); }
.mgmt-submit-btn { padding: 8px 20px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: background 0.15s; }
.mgmt-submit-btn:hover { background: var(--primary-light); }
.mgmt-submit-btn:disabled, .mgmt-delete-confirm-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.mgmt-delete-confirm-btn { padding: 8px 20px; background: var(--danger); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: background 0.15s; }
.mgmt-delete-confirm-btn:hover { background: #c53030; }

@media (max-width: 768px) {
    .header { padding: 16px; }
    .main { padding: 16px; }
    .nav-tab { padding: 12px 14px; font-size: 0.78rem; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .category-grid { grid-template-columns: 1fr; }
    .article-row { flex-direction: column; }
    .article-ref { min-width: unset; }
    .mgmt-form-grid { grid-template-columns: 1fr; }
    .mgmt-header { flex-direction: column; }
}
