:root {
    --primary: #1a365d;
    --secondary: #2c5282;
    --accent: #e53e3e;
    --success: #38a169;
    --warning: #d69e2e;
    --orange: #ed8936;
    --purple: #805ad5;
    --bg: #f7fafc;
    --card-bg: #ffffff;
    --text: #2d3748;
    --text-light: #718096;
    --border: #e2e8f0;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

header {
    background: var(--primary);
    color: white;
    padding: 32px 0 20px;
    text-align: center;
}

header h1 { font-size: 2rem; margin-bottom: 6px; }
header p { font-size: 1rem; opacity: 0.9; max-width: 700px; margin: 0 auto; }
header .subtitle { font-size: 0.85rem; opacity: 0.7; margin-top: 8px; }

nav {
    background: var(--secondary);
    padding: 10px 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

nav .container { display: flex; align-items: center; justify-content: center; }
nav ul { list-style: none; display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
nav a {
    color: white;
    text-decoration: none;
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: 4px;
    transition: background 0.2s;
    font-weight: 500;
}
nav a:hover, nav a.active { background: rgba(255,255,255,0.2); }

section { padding: 48px 0; }
section h2 { font-size: 1.6rem; color: var(--primary); margin-bottom: 24px; border-bottom: 2px solid var(--border); padding-bottom: 8px; }
section h3 { font-size: 1.2rem; color: var(--secondary); margin: 16px 0 8px; }

.page-intro {
    font-size: 1.05rem;
    color: var(--text-light);
    margin-bottom: 32px;
    max-width: 800px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    text-align: center;
}

.stat-card .number {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-card .label {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stat-card.highlight { border-left: 4px solid var(--accent); }
.stat-card.highlight .number { color: var(--accent); }
.stat-card.success { border-left: 4px solid var(--success); }
.stat-card.success .number { color: var(--success); }
.stat-card.warning { border-left: 4px solid var(--warning); }
.stat-card.warning .number { color: var(--warning); }
.stat-card.orange { border-left: 4px solid var(--orange); }
.stat-card.orange .number { color: var(--orange); }

.chart-container {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 24px;
    position: relative;
}

.chart-container h3 { margin-top: 0; margin-bottom: 12px; }
.chart-container .js-plotly-plot { width: 100% !important; }

@media print {
    nav, footer, .memo-link, .map-controls, .map-sidebar { display: none !important; }
    header { background: none !important; color: black !important; padding: 12px 0; }
    header h1 { font-size: 1.3rem; }
    .container { max-width: 100%; padding: 0; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    .stat-card { box-shadow: none; border: 1px solid #ccc; padding: 12px; }
    .chart-container { break-inside: avoid; }
    .two-col { grid-template-columns: 1fr; }
    body { font-size: 10pt; }
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; }
@media (max-width: 768px) {
    .two-col, .three-col { grid-template-columns: 1fr; }
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--primary); color: white; font-weight: 600; position: sticky; top: 0; z-index: 10; }
tr:hover { background: #f0f4f8; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.table-wrapper { max-height: 500px; overflow-y: auto; border-radius: 8px; margin-bottom: 24px; position: relative; }
.table-wrapper table { border-radius: 0; }
.table-wrapper th { position: sticky; top: 0; z-index: 10; }

.callout {
    background: #ebf8ff;
    border-left: 4px solid #3182ce;
    padding: 16px 20px;
    border-radius: 0 8px 8px 0;
    margin: 24px 0;
}

.callout.warning { background: #fffbeb; border-color: var(--warning); }
.callout.danger { background: #fff5f5; border-color: var(--accent); }
.callout.success { background: #f0fff4; border-color: var(--success); }
.callout h4 { margin-bottom: 4px; }
.callout p { margin-bottom: 0; }

.formula-box {
    background: #f0fff4;
    border: 2px solid var(--success);
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    font-family: 'Courier New', monospace;
}

.formula-box .old { color: var(--text-light); text-decoration: line-through; }
.formula-box .new { color: var(--success); font-weight: bold; }
.formula-box .label { font-family: -apple-system, sans-serif; font-size: 0.8rem; color: var(--text-light); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }

footer {
    background: var(--primary);
    color: white;
    padding: 24px 0;
    text-align: center;
    font-size: 0.85rem;
    opacity: 0.9;
    margin-top: 48px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-eligible { background: #c6f6d5; color: #22543d; }
.badge-criteria1 { background: #bee3f8; color: #2a4365; }
.badge-moe { background: #fefcbf; color: #744210; }
.badge-ineligible { background: #fed7d7; color: #742a2a; }
.badge-planning { background: #bee3f8; color: #2a4365; }
.badge-partnership { background: #c6f6d5; color: #22543d; }
.badge-implementation { background: #e9d8fd; color: #44337a; }

.memo-link {
    display: inline-block;
    background: var(--primary);
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    margin: 8px;
    transition: background 0.2s;
}

.memo-link:hover { background: var(--secondary); }

/* Map */
#map, .map-container {
    width: 100%;
    height: 500px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 24px;
}

.map-legend {
    background: white;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    font-size: 0.8rem;
    line-height: 1.8;
}

.map-legend i {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    margin-right: 6px;
    vertical-align: middle;
}

/* Password Gate */
.password-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(26, 54, 93, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-modal {
    background: white;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.password-modal h2 {
    color: var(--primary);
    margin-bottom: 8px;
    border: none;
    padding: 0;
}

.password-modal p {
    color: var(--text-light);
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.password-modal input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
}

.password-modal input:focus { border-color: var(--secondary); }

.password-modal button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.password-modal button:hover { background: var(--secondary); }

.password-modal .error {
    color: var(--accent);
    font-size: 0.85rem;
    margin-top: 8px;
    display: none;
}

/* Back link */
.back-link { display: inline-block; margin: 20px; color: var(--primary); text-decoration: none; font-weight: 600; }

/* Memo styles */
.memo { max-width: 800px; margin: 40px auto; padding: 40px; background: white; box-shadow: 0 2px 8px rgba(0,0,0,0.1); border-radius: 8px; }
.memo h1 { font-size: 1.6rem; color: var(--primary); border-bottom: 2px solid var(--primary); padding-bottom: 12px; margin-bottom: 24px; }
.memo h2 { font-size: 1.2rem; color: var(--secondary); margin: 24px 0 8px; }
.memo h3 { font-size: 1.05rem; margin: 16px 0 8px; }
.memo p, .memo li { margin-bottom: 12px; }
.memo ul, .memo ol { padding-left: 20px; }
.memo .header-info { font-size: 0.85rem; color: var(--text-light); margin-bottom: 24px; }

table.data-table { width: 100%; margin: 16px 0; font-size: 0.85rem; border-collapse: collapse; }
table.data-table th, table.data-table td { padding: 8px 10px; border: 1px solid var(--border); text-align: left; }
table.data-table th { background: var(--primary); color: white; }
table.data-table tr:nth-child(even) { background: #f7fafc; }

.toc { background: #f7fafc; padding: 20px; border-radius: 6px; margin-bottom: 24px; }
.toc ul { list-style: none; padding-left: 0; }
.toc li { margin-bottom: 4px; }
.toc a { color: var(--secondary); text-decoration: none; }

/* Responsive */
@media (max-width: 600px) {
    header h1 { font-size: 1.5rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-card .number { font-size: 1.6rem; }
    nav a { font-size: 0.75rem; padding: 4px 8px; }
    #map, .map-container { height: 350px; }
}
