/* AVE/CR Calculator */

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg-gradient);
    transition: background 0.3s ease, color 0.3s ease;
}

button, input, textarea, select { font: inherit; }
button { border: 0; }
a { color: inherit; text-decoration: none; }

.app-shell { width: min(1440px, 100%); margin: 0 auto; padding: 24px; }

.hero {
    position: relative;
    overflow: hidden;
    border-radius: 28px;
    padding: 32px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.12);
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 40px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 18px;
    color: var(--primary);
    background: #fff;
    font-weight: 900;
    letter-spacing: -0.03em;
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.18);
}
.brand-title { font-size: 1.35rem; font-weight: 850; }
.brand-subtitle { font-size: 0.92rem; opacity: 0.86; }
.top-actions { display: flex; gap: 12px; align-items: center; }

.theme-selector {
    width: auto;
    min-width: 210px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    padding: 10px 12px;
    outline: none;
    cursor: pointer;
}
.theme-selector option { color: #000; }

.guide-link, .ghost-button, .secondary-button, .primary-button, .sample-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 18px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 750;
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}
.guide-link { color: #fff; border: 1px solid rgba(255, 255, 255, 0.32); background: rgba(255, 255, 255, 0.15); }
.guide-link:hover, .ghost-button:hover, .secondary-button:hover, .primary-button:hover, .sample-button:hover { transform: translateY(-2px); }

.hero-grid { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 24px; align-items: end; }
.eyebrow {
    margin: 0 0 10px;
    color: var(--accent-2);
    font-size: 0.8rem;
    font-weight: 850;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.hero h1 { max-width: 900px; margin: 0; font-size: clamp(2rem, 5vw, 3.8rem); line-height: 1.02; letter-spacing: -0.05em; }
.hero-text { max-width: 900px; margin: 20px 0 0; font-size: 1.15rem; line-height: 1.6; opacity: 0.92; }
.profile-card { padding: 24px; border-radius: 24px; background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.25); }
.profile-label { color: var(--accent-2); font-size: 0.75rem; font-weight: 850; text-transform: uppercase; }
.profile-name { margin-top: 10px; font-size: 1.35rem; font-weight: 850; }

.main-grid { display: grid; grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); gap: 24px; margin-top: 24px; }
.panel { border: 1px solid var(--line); border-radius: 24px; background: var(--card); box-shadow: 0 18px 45px rgba(0, 0, 0, 0.05); padding: 28px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.panel-header h2 { margin: 0; font-size: 1.6rem; color: var(--primary); }
.input-header { align-items: flex-start; }
.input-header p { margin: 8px 0 0; color: var(--muted); line-height: 1.45; }

.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; color: var(--ink); font-weight: 700; }
small { display: block; margin-top: 7px; color: var(--muted); font-size: 0.85rem; line-height: 1.45; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--ink); background: transparent; outline: none; }
textarea { resize: vertical; min-height: 190px; line-height: 1.5; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.05); }
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.primary-button { color: #fff; background: var(--primary); min-width: 220px; }
.secondary-button, .sample-button { color: var(--primary); background: transparent; border: 1px solid var(--primary); }
.sample-button { min-height: 42px; border-radius: 12px; white-space: nowrap; }
.ghost-button { color: var(--primary); background: transparent; border: 1px solid var(--line); }
button:disabled { cursor: not-allowed; opacity: 0.58; transform: none !important; }

.button-spinner { display: none; width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.3); border-top-color: #fff; animation: spin 0.8s linear infinite; }
.primary-button.is-loading .button-spinner { display: inline-block; }
.large-spinner { width: 50px; height: 50px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--primary); animation: spin 0.8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-box { margin-bottom: 20px; padding: 14px 18px; border-radius: 12px; border: 1px solid var(--line); color: var(--primary); font-weight: 600; background: rgba(0, 0, 0, 0.02); }
.status-success-box { border-color: rgba(46, 125, 50, 0.35); background: rgba(46, 125, 50, 0.08); }
.status-error-box { color: #b42318; border-color: rgba(180, 35, 24, 0.35); background: rgba(180, 35, 24, 0.07); }

.result { min-height: 550px; max-height: 78vh; overflow-y: auto; padding: 24px; border-radius: 16px; background: transparent; border: 1px solid var(--line); }
.report-section + .report-section { margin-top: 34px; }
.result h2 { margin: 0 0 14px; color: var(--primary); font-size: 1.4rem; border-bottom: 2px solid var(--line); padding-bottom: 9px; }
.result h3 { margin: 22px 0 10px; color: var(--primary); }
.result p, .result li { line-height: 1.7; font-size: 1rem; }
.result strong { color: var(--primary-2); font-weight: 800; }

.table-wrap { width: 100%; overflow-x: auto; margin: 16px 0; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 0.94rem; background: transparent; box-shadow: 0 0 0 1px var(--line); }
th, td { padding: 11px 13px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th { background: var(--primary); color: #fff; font-weight: 700; white-space: nowrap; }
tbody th { background: rgba(0, 0, 0, 0.035); color: var(--ink); font-weight: 750; }
tbody tr:nth-child(even) td { background: rgba(0, 0, 0, 0.018); }
.matrix-table td, .matrix-table th { text-align: center; }
.matrix-table thead th:first-child, .matrix-table tbody th { text-align: left; }
.diagonal-cell { background: rgba(24, 98, 171, 0.10) !important; }
.correlation-fail { background: rgba(180, 35, 24, 0.14) !important; font-weight: 800; color: #b42318; }
.correlation-pass { background: rgba(46, 125, 50, 0.055); }
.missing-cell { color: var(--muted); font-style: italic; }

.formula-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 18px; }
.formula-card { padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: rgba(0, 0, 0, 0.018); }
.formula-card h3 { margin-top: 0; }
.formula-card p { margin: 8px 0; font-size: 0.94rem; overflow-wrap: anywhere; }

.badge-pass, .badge-fail { display: inline-block; padding: 4px 9px; border-radius: 999px; font-weight: 750; line-height: 1.3; }
.badge-pass { color: #176b2c; background: #e8f5e9; border: 1px solid #c8e6c9; }
.badge-fail { color: #b42318; background: #ffebee; border: 1px solid #ffcdd2; }
.status-success, .status-failure, .status-warning { padding: 14px 16px; border-radius: 10px; }
.status-success { background: rgba(46, 125, 50, 0.08); border: 1px solid rgba(46, 125, 50, 0.25); }
.status-failure { background: rgba(180, 35, 24, 0.08); border: 1px solid rgba(180, 35, 24, 0.25); }
.status-warning, .warning-section { background: rgba(217, 119, 6, 0.075); border: 1px solid rgba(217, 119, 6, 0.25); border-radius: 12px; padding: 16px; }
.warning-section h2 { margin-top: 0; }

.empty-state, .loading-state, .error-state { display: grid; place-items: center; align-content: center; text-align: center; height: 100%; }
.empty-icon { font-size: 3.5rem; margin-bottom: 16px; }
.error-state p { max-width: 680px; }

@media (max-width: 900px) {
    .hero-grid, .main-grid { grid-template-columns: 1fr; }
    .hero h1 { font-size: 2.2rem; }
    .topbar, .panel-header { align-items: stretch; }
    .topbar { flex-direction: column; }
    .top-actions { flex-wrap: wrap; }
    .theme-selector { flex: 1 1 220px; }
}

@media (max-width: 600px) {
    .app-shell { padding: 12px; }
    .hero, .panel { padding: 20px; border-radius: 20px; }
    .input-header { flex-direction: column; }
    .sample-button { width: 100%; }
    .form-actions > button, .output-actions, .ghost-button { width: 100%; }
    .result { padding: 15px; }
    th, td { padding: 9px 10px; }
}
