/* ==========================================================================
   Responsible Business Scorecard — Test Version
   ========================================================================== */

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

:root {
    --gold: #d4a843;
    --gold-light: #e8c96a;
    --gold-dark: #b8912e;
    --navy: #0a1628;
    --navy-mid: #142240;
    --navy-light: #1e3260;
    --text: #1a1a2e;
    --text-light: #6b7280;
    --text-lighter: #9ca3af;
    --bg: #f4f5f7;
    --card: #ffffff;
    --border: #e5e7eb;
    --red: #ef4444;
    --green: #22c55e;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Splash Screen ─────────────────────────────────────────────────────── */
.splash-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--navy), var(--navy-mid));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    color: #fff;
    text-align: center;
    padding: 2rem;
}
.splash-content h1 {
    font-size: 2.4rem;
    margin-bottom: 1rem;
    font-weight: 800;
}
.splash-content p {
    margin-bottom: 1.2rem;
    font-size: 1rem;
    line-height: 1.5;
}
/* Pyramid visualization */
.pyramid {
    width: 200px;
    margin: 0 auto 1rem;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
}
.pyramid .layer {
    width: 100%;
    background: var(--gold);
    border-top: 2px solid #fff;
}
.layer-survival { background: var(--gold-light); }
.layer-stability { background: var(--gold-dark); }
.layer-self { background: var(--gold); }
.layer-security { background: var(--navy); }
.layer-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    margin-top: 0.4rem;
}
.layer-labels span { width: 25%; text-align: center; }
/* Pie chart container */
#metricChart {
    margin: 1rem auto;
    display: block;
    background: #fff;
    border-radius: 50%;
    padding: 4px;
}
.btn-start {
    background: var(--gold);
    color: var(--navy);
    border: none;
    padding: 0.8rem 1.6rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-start:hover {
    background: var(--gold-light);
}
.rung-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0 1.5rem;
    text-align: left;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}
.rung-list li {
    margin-bottom: 0.6rem;
    font-size: 0.95rem;
}
.rung-list li strong {
    color: var(--gold-light);
}
.btn-start {
    background: var(--gold);
    color: var(--navy);
    border: none;
    padding: 0.8rem 1.6rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-start:hover {
    background: var(--gold-light);
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--navy);
    border-bottom: 3px solid var(--gold);
}
.top-bar-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}
.top-brand { display: flex; align-items: center; gap: 12px; }
.top-brand-icon {
    background: var(--gold);
    color: var(--navy);
    font-weight: 900;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 6px;
    letter-spacing: 0.5px;
}
.top-brand-text {
    color: #fff;
    font-weight: 700;
    font-size: 15px;
}
.top-tabs { display: flex; gap: 4px; }
.top-tab {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.top-tab:hover:not(:disabled) { color: #fff; background: rgba(255,255,255,0.08); }
.top-tab.active { color: var(--navy); background: var(--gold); }
.top-tab:disabled { opacity: 0.3; cursor: default; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
main { max-width: 960px; margin: 0 auto; padding: 32px 24px 80px; }

.tab-panel { display: none; animation: fadeIn 0.3s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Upload Hero ────────────────────────────────────────────────────────── */
.upload-hero { text-align: center; margin-bottom: 32px; }
.upload-hero h1 { font-size: 28px; font-weight: 800; color: var(--navy); margin-bottom: 8px; }
.upload-hero p { font-size: 15px; color: var(--text-light); max-width: 500px; margin: 0 auto; }

/* ── Upload Card ────────────────────────────────────────────────────────── */
.upload-card {
    background: var(--card);
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.04);
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}
.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--gold);
    background: rgba(212,168,67,0.04);
}
.drop-zone.drag-over { animation: dropPulse 1s ease infinite; }
@keyframes dropPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(212,168,67,0.2); }
    50% { box-shadow: 0 0 0 12px rgba(212,168,67,0); }
}
.drop-icon { color: var(--gold); margin-bottom: 12px; }
.drop-icon svg { width: 40px; height: 40px; }
.drop-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.drop-sub { font-size: 13px; color: var(--text-lighter); }

.file-preview {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
}
.file-preview-icon { color: var(--gold); flex-shrink: 0; }
.file-preview-icon svg { width: 28px; height: 28px; }
.file-preview-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.file-name { font-weight: 600; font-size: 14px; word-break: break-all; }
.file-size { font-size: 12px; color: var(--text-lighter); }
.file-remove {
    background: none; border: none; font-size: 22px; color: var(--text-lighter);
    cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: all 0.2s;
}
.file-remove:hover { background: #fee2e2; color: var(--red); }

.form-group { margin-bottom: 20px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600; color: var(--text-light);
    margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input {
    width: 100%; padding: 12px 16px; border: 1.5px solid var(--border); border-radius: 10px;
    font-family: var(--font); font-size: 15px; color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s; background: var(--bg);
}
.form-group input:focus {
    outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,168,67,0.15);
}

.btn-analyse {
    width: 100%; padding: 14px; border: none; border-radius: 10px;
    background: var(--gold); color: var(--navy);
    font-family: var(--font); font-size: 16px; font-weight: 700;
    cursor: pointer; transition: all 0.2s;
}
.btn-analyse:hover:not(:disabled) { background: var(--gold-light); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(212,168,67,0.3); }
.btn-analyse:disabled { opacity: 0.4; cursor: default; }

.btn-secondary {
    padding: 10px 24px; border: 1.5px solid var(--border); border-radius: 10px;
    background: #fff; color: var(--text); font-family: var(--font);
    font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--gold); color: var(--gold-dark); }

/* ── Loading ────────────────────────────────────────────────────────────── */
.loading-card {
    background: var(--card); border-radius: 16px; padding: 64px 32px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.04);
}
.loading-spinner {
    width: 48px; height: 48px; border: 4px solid var(--border);
    border-top-color: var(--gold); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.loading-card p { font-size: 14px; color: var(--text-light); margin-bottom: 24px; }
.loading-bar-track {
    width: 100%; max-width: 400px; height: 6px; background: var(--border);
    border-radius: 3px; margin: 0 auto; overflow: hidden;
}
.loading-bar-fill {
    height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), var(--gold-light));
    border-radius: 3px; transition: width 0.5s ease;
}

/* ── Activity Log ────────────────────────────────────────────────────────── */
.activity-log {
    max-width: 500px;
    margin: 28px auto 0;
    background: var(--navy);
    border-radius: 12px;
    overflow: hidden;
    text-align: left;
    animation: fadeIn 0.4s ease;
}
.activity-log-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255,255,255,0.05);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
}
.activity-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    animation: activityPulse 1.5s infinite;
}
@keyframes activityPulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
    50% { opacity: 0.6; box-shadow: 0 0 0 4px rgba(34,197,94,0); }
}
.activity-log-body {
    padding: 12px 16px;
    max-height: 180px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    line-height: 1.7;
}
.activity-log-body::-webkit-scrollbar { width: 4px; }
.activity-log-body::-webkit-scrollbar-track { background: transparent; }
.activity-log-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.activity-entry {
    display: flex;
    gap: 10px;
    opacity: 0;
    transform: translateX(-8px);
    animation: logSlideIn 0.3s ease forwards;
}
@keyframes logSlideIn {
    to { opacity: 1; transform: translateX(0); }
}
.activity-time {
    color: rgba(255,255,255,0.25);
    flex-shrink: 0;
    font-size: 11px;
}
.activity-msg { color: rgba(255,255,255,0.65); }
.activity-msg.highlight { color: var(--gold-light); }
.activity-msg.success { color: var(--green); }
.activity-msg.warn { color: #f59e0b; }

/* ── Error ──────────────────────────────────────────────────────────────── */
.error-card {
    background: var(--card); border-radius: 16px; padding: 48px 32px; text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); border-top: 4px solid var(--red);
}
.error-card h3 { color: var(--red); font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.error-card p { font-size: 14px; color: var(--text-light); margin-bottom: 20px; }

/* ── Results ────────────────────────────────────────────────────────────── */
.result-header {
    background: var(--navy);
    border-radius: 16px;
    padding: 36px 32px;
    margin-bottom: 24px;
    color: #fff;
    position: relative;
    overflow: hidden;
    animation: fadeIn 0.4s ease;
}
.result-header::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--gold), var(--gold-light), var(--gold));
}
.result-company { font-size: 26px; font-weight: 800; margin-bottom: 4px; }
.result-meta { font-size: 13px; color: rgba(255,255,255,0.5); margin-bottom: 20px; }

.result-top { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }

.grade-badge {
    width: 90px; height: 90px; border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-weight: 900; flex-shrink: 0;
    animation: gradePop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    animation-delay: 0.3s;
}
@keyframes gradePop {
    0% { opacity: 0; transform: scale(0.3); }
    100% { opacity: 1; transform: scale(1); }
}
.grade-badge .grade-letter { font-size: 28px; line-height: 1; }
.grade-badge .grade-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }
.grade-platinum { background: linear-gradient(135deg, #e5e7eb, #9ca3af); color: #1a1a2e; }
.grade-gold     { background: linear-gradient(135deg, var(--gold-light), var(--gold-dark)); color: #1a1a2e; }
.grade-silver   { background: linear-gradient(135deg, #d1d5db, #9ca3af); color: #1a1a2e; }
.grade-bronze   { background: linear-gradient(135deg, #d97706, #92400e); color: #fff; }
.grade-none     { background: #374151; color: #9ca3af; }

.overall-score { flex: 1; }
.overall-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,0.5); margin-bottom: 6px; }
.overall-number { font-size: 44px; font-weight: 900; color: var(--gold); line-height: 1; }
.overall-number span { font-size: 20px; color: rgba(255,255,255,0.4); font-weight: 600; }

.overall-bar-track {
    width: 100%; height: 8px; background: rgba(255,255,255,0.1);
    border-radius: 4px; margin-top: 12px; overflow: hidden;
}
.overall-bar-fill {
    height: 100%; width: 0%; border-radius: 4px;
    background: linear-gradient(90deg, var(--gold), var(--gold-light));
    transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
    transition-delay: 0.5s;
}

/* ── Rung Cards ─────────────────────────────────────────────────────────── */
.rungs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}
@media (max-width: 640px) { .rungs-grid { grid-template-columns: 1fr; } }

.rung-card {
    background: var(--card);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.03);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: rungSlideIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.rung-card:nth-child(1) { animation-delay: 0.1s; }
.rung-card:nth-child(2) { animation-delay: 0.2s; }
.rung-card:nth-child(3) { animation-delay: 0.3s; }
.rung-card:nth-child(4) { animation-delay: 0.4s; }
@keyframes rungSlideIn {
    0% { opacity: 0; transform: translateY(20px) scale(0.97); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
.rung-card:hover { transform: translateY(-2px); box-shadow: 0 4px 24px rgba(0,0,0,0.08); }

.rung-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.rung-name { font-size: 17px; font-weight: 700; }
.rung-weight {
    font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
    background: rgba(212,168,67,0.12); color: var(--gold-dark);
}

.rung-score-row { display: flex; align-items: baseline; gap: 6px; margin-bottom: 10px; }
.rung-score-num { font-size: 32px; font-weight: 900; }
.rung-score-max { font-size: 16px; color: var(--text-lighter); font-weight: 600; }

.rung-bar-track {
    width: 100%; height: 8px; background: var(--bg); border-radius: 4px;
    overflow: hidden; margin-bottom: 8px;
}
.rung-bar-fill {
    height: 100%; width: 0%; border-radius: 4px;
    transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
    transition-delay: 0.6s;
}
.bar-survival     { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.bar-stability    { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.bar-selfreliance { background: linear-gradient(90deg, #22c55e, #4ade80); }
.bar-security     { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }

.rung-pct { font-size: 12px; color: var(--text-lighter); margin-bottom: 12px; }

.rung-toggle {
    font-size: 12px; font-weight: 600; color: var(--gold-dark);
    display: flex; align-items: center; gap: 4px;
    transition: transform 0.2s;
}
.rung-toggle svg { width: 14px; height: 14px; transition: transform 0.3s; }
.rung-card.expanded .rung-toggle svg { transform: rotate(180deg); }

.rung-criteria {
    max-height: 0; overflow: hidden; transition: max-height 0.4s ease;
    margin-top: 0;
}
.rung-card.expanded .rung-criteria { max-height: 600px; margin-top: 14px; }

.criterion-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 10px 0; border-top: 1px solid var(--border);
}
.criterion-score {
    min-width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 800; flex-shrink: 0;
}
.criterion-score.hit { background: rgba(34,197,94,0.1); color: var(--green); }
.criterion-score.miss { background: #f3f4f6; color: var(--text-lighter); }
.criterion-info { flex: 1; }
.criterion-name { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.criterion-evidence { font-size: 12px; color: var(--text-light); line-height: 1.4; }

/* ── Summary Card ───────────────────────────────────────────────────────── */
.summary-card {
    background: var(--card); border-radius: 16px; padding: 28px 32px;
    margin-bottom: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    animation: fadeIn 0.5s ease both;
    animation-delay: 0.5s;
}
.summary-card h3 { font-size: 16px; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.summary-card h3 svg { width: 20px; height: 20px; color: var(--gold); }
.summary-text { font-size: 14px; color: var(--text-light); line-height: 1.7; }

/* ── Action Buttons ─────────────────────────────────────────────────────── */
.result-actions {
    display: flex; gap: 12px; flex-wrap: wrap;
    animation: fadeIn 0.5s ease both;
    animation-delay: 0.6s;
}
.btn-print {
    padding: 12px 28px; border: none; border-radius: 10px;
    background: var(--navy); color: #fff;
    font-family: var(--font); font-size: 14px; font-weight: 700;
    cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; gap: 8px;
}
.btn-print:hover { background: var(--navy-mid); transform: translateY(-1px); }
.btn-new {
    padding: 12px 28px; border: 1.5px solid var(--border); border-radius: 10px;
    background: #fff; color: var(--text);
    font-family: var(--font); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: all 0.2s;
}
.btn-new:hover { border-color: var(--gold); color: var(--gold-dark); }

/* ── History ────────────────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
    background: var(--card); border-radius: 12px; padding: 18px 22px;
    display: flex; align-items: center; gap: 16px;
    cursor: pointer; transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    animation: fadeIn 0.3s ease both;
}
.history-item:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
.history-grade {
    width: 48px; height: 48px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 900; flex-shrink: 0;
}
.history-info { flex: 1; }
.history-company { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.history-date { font-size: 12px; color: var(--text-lighter); }
.history-score { font-size: 24px; font-weight: 900; color: var(--gold-dark); }
.history-delete {
    background: none; border: none; color: var(--text-lighter); font-size: 18px;
    cursor: pointer; padding: 6px 8px; border-radius: 6px; transition: all 0.2s;
}
.history-delete:hover { background: #fee2e2; color: var(--red); }

.history-empty {
    text-align: center; padding: 64px 24px; color: var(--text-lighter); font-size: 14px;
}

/* ── Print Styles ───────────────────────────────────────────────────────── */
@media print {
    .top-bar, .result-actions, .rung-toggle { display: none !important; }
    body { background: #fff; }
    .result-header { background: var(--navy) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .rung-card { break-inside: avoid; box-shadow: none; border: 1px solid #e5e7eb; }
    .rung-criteria { max-height: none !important; }
    main { padding: 0; }
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .top-brand-text { display: none; }
    .top-tab { padding: 8px 12px; font-size: 13px; }
    .upload-card { padding: 20px; }
    .result-header { padding: 24px 20px; }
    .result-top { gap: 16px; }
    .overall-number { font-size: 36px; }
}
