:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface2: #334155;
    --border: #475569;
    --text: #f1f5f9;
    --text-dim: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #22c55e;
    --yellow: #eab308;
    --red: #ef4444;
    --radius: 12px;
}

* { 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;
    min-height: 100vh;
}

header {
    background: linear-gradient(135deg, #1e3a5f, #0f172a);
    padding: 2rem 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

header .subtitle {
    color: var(--text-dim);
    font-size: 1.05rem;
}

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

fieldset {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

legend {
    font-weight: 600;
    font-size: 1.1rem;
    padding: 0 0.5rem;
    color: var(--accent);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.field.full { grid-column: 1 / -1; }

.field label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 0.3rem;
    font-weight: 500;
}

.field input,
.field select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--accent);
}

.actions {
    text-align: center;
    margin: 2rem 0;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.9rem 3rem;
    font-size: 1.15rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }

/* Loading overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,23,42,0.85);
    z-index: 100;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}
.loading-overlay.active { display: flex; }
.loading-overlay .spinner {
    width: 48px; height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { margin-top: 1rem; color: var(--text-dim); }

/* Results */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.results-header h2 { font-size: 1.5rem; }
#results-timestamp { color: var(--text-dim); font-size: 0.9rem; }

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}

.card-label {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

.card-value {
    font-size: 2.2rem;
    font-weight: 700;
}

.card-value.green { color: var(--green); }
.card-value.yellow { color: var(--yellow); }
.card-value.red { color: var(--red); }

.card-bar {
    background: var(--bg);
    border-radius: 10px;
    height: 10px;
    margin-top: 0.75rem;
    overflow: hidden;
}

.card-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.8s ease;
}

.chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.chart-container h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--text);
}

.chart-container canvas {
    width: 100% !important;
    max-height: 400px;
}

.table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
}

.data-table th {
    background: var(--surface2);
    color: var(--text-dim);
    font-weight: 600;
    position: sticky;
    top: 0;
}

.data-table tr:hover td {
    background: var(--surface2);
}

.data-table td:first-child { text-align: left; }

/* Error */
.error-msg {
    background: rgba(239,68,68,0.15);
    border: 1px solid var(--red);
    border-radius: var(--radius);
    padding: 1rem;
    color: var(--red);
    text-align: center;
    margin: 1rem 0;
    display: none;
}

footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
    padding: 2rem 1rem;
    border-top: 1px solid var(--border);
}

@media (max-width: 600px) {
    header h1 { font-size: 1.5rem; }
    .grid { grid-template-columns: 1fr; }
    .summary-cards { grid-template-columns: 1fr; }
    .card-value { font-size: 1.8rem; }
}
