/* ══════════════════════════════════════════════════════
   FLAMBAGE EC2 — Design System
   Ultra-modern, dark-first, glass-morphism UI
   ══════════════════════════════════════════════════════ */

/* ─── Theme Variables ─── */
:root {
    --bg-primary:    #0a0b12;
    --bg-secondary:  #0f1019;
    --bg-card:       #14151f;
    --bg-card-hover: #191a26;
    --bg-input:      #1a1b28;
    --bg-input-focus:#1e1f2e;
    --border:        rgba(255,255,255,0.06);
    --border-focus:  rgba(129,140,248,0.4);
    --text-primary:  #e8e9f0;
    --text-secondary:#8b8ca4;
    --text-muted:    #555670;
    --accent:        #818cf8;
    --accent-hover:  #6366f1;
    --accent-dim:    rgba(129,140,248,0.12);
    --accent-glow:   rgba(129,140,248,0.25);
    --success:       #34d399;
    --success-dim:   rgba(52,211,153,0.12);
    --danger:        #f87171;
    --danger-dim:    rgba(248,113,113,0.12);
    --warning:       #fbbf24;
    --warning-dim:   rgba(251,191,36,0.12);
    --purple:        #a78bfa;
    --purple-dim:    rgba(167,139,250,0.12);
    --orange:        #fb923c;
    --orange-dim:    rgba(251,146,60,0.12);
    --radius-sm:     8px;
    --radius-md:     12px;
    --radius-lg:     16px;
    --radius-xl:     20px;
    --shadow-sm:     0 1px 3px rgba(0,0,0,0.3);
    --shadow-md:     0 4px 16px rgba(0,0,0,0.3);
    --shadow-lg:     0 8px 32px rgba(0,0,0,0.4);
    --transition:    0.2s cubic-bezier(.4,0,.2,1);
    --sidebar-w:     380px;
    --header-h:      64px;
}

[data-theme="light"] {
    --bg-primary:    #f3f4f8;
    --bg-secondary:  #e9eaf0;
    --bg-card:       #ffffff;
    --bg-card-hover: #f7f7fb;
    --bg-input:      #f0f1f6;
    --bg-input-focus:#e8e9f2;
    --border:        rgba(0,0,0,0.07);
    --border-focus:  rgba(99,102,241,0.45);
    --text-primary:  #1a1b2e;
    --text-secondary:#6b6c84;
    --text-muted:    #9d9eb4;
    --shadow-sm:     0 1px 3px rgba(0,0,0,0.06);
    --shadow-md:     0 4px 16px rgba(0,0,0,0.06);
    --shadow-lg:     0 8px 32px rgba(0,0,0,0.08);
}

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ═══════════ HEADER ═══════════ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--accent-dim);
    color: var(--accent);
}

.header-title {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

[data-theme="dark"] .icon-sun   { display: none; }
[data-theme="dark"] .icon-moon  { display: block; }
[data-theme="light"] .icon-sun  { display: block; }
[data-theme="light"] .icon-moon { display: none; }

/* ═══════════ APP LAYOUT ═══════════ */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: calc(100vh - var(--header-h));
}

/* ═══════════ SIDEBAR ═══════════ */
.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 20px;
}

/* Form Sections */
.form-section {
    margin-bottom: 6px;
}

.form-section-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--transition);
}
.form-section-toggle:hover { background: var(--bg-card); }
.form-section-toggle svg:first-child { color: var(--accent); flex-shrink: 0; }
.form-section-toggle span { flex: 1; text-align: left; }
.form-section-toggle .chevron {
    color: var(--text-muted);
    transition: transform var(--transition);
}
.form-section-toggle.active .chevron { transform: rotate(180deg); }

.form-section-body {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.3s ease;
    padding: 0 4px;
}
.form-section-body.open {
    max-height: 500px;
    opacity: 1;
    padding: 8px 4px 16px;
}

/* Form Groups */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 5px;
}
.form-group label em {
    font-style: normal;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrap input,
.input-wrap select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    font-weight: 500;
    outline: none;
    transition: all var(--transition);
    -moz-appearance: textfield;
}
.input-wrap input::-webkit-inner-spin-button,
.input-wrap input::-webkit-outer-spin-button {
    opacity: 0.3;
}
.input-wrap select {
    padding-right: 30px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b8ca4' fill='none' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.input-wrap input:focus,
.input-wrap select:focus {
    border-color: var(--border-focus);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.unit {
    position: absolute;
    right: 10px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    pointer-events: none;
    font-family: 'JetBrains Mono', monospace;
}
.input-wrap:has(> .unit) input { padding-right: 40px; }

.form-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding-left: 2px;
}

/* Calculate Button */
.btn-calculate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px;
    margin-top: 12px;
    border: none;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(129, 140, 248, 0.25);
}
.btn-calculate:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 25px rgba(129, 140, 248, 0.35);
}
.btn-calculate:active {
    transform: translateY(0);
}

/* ═══════════ CONTENT ═══════════ */
.content {
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-primary);
}

/* Placeholder */
.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
    gap: 12px;
}
.placeholder h2 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.placeholder p { font-size: 0.9rem; }

/* Results Container */
.results-container {
    display: none;
    animation: fadeSlideUp 0.45s ease;
}
.results-container.visible { display: block; }

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════ VERDICT ═══════════ */
.verdict {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 20px 24px;
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    transition: all var(--transition);
}

.verdict.safe {
    border-color: rgba(52,211,153,0.2);
    background: linear-gradient(135deg, var(--success-dim), transparent 60%);
}
.verdict.unsafe {
    border-color: rgba(248,113,113,0.2);
    background: linear-gradient(135deg, var(--danger-dim), transparent 60%);
}

.verdict-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    flex-shrink: 0;
}
.verdict.safe .verdict-icon  { background: var(--success-dim); color: var(--success); }
.verdict.unsafe .verdict-icon { background: var(--danger-dim); color: var(--danger); }

.verdict.safe .icon-check  { display: block; }
.verdict.safe .icon-x      { display: none; }
.verdict.unsafe .icon-check { display: none; }
.verdict.unsafe .icon-x     { display: block; }

.verdict-text { flex: 1; }
.verdict-text h2 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.verdict.safe .verdict-text h2  { color: var(--success); }
.verdict.unsafe .verdict-text h2 { color: var(--danger); }
.verdict-text p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Gauge */
.verdict-gauge { flex-shrink: 0; }
.gauge-ring {
    position: relative;
    width: 72px;
    height: 72px;
}
.gauge-ring svg { width: 100%; height: 100%; }
.gauge-bg   { stroke: var(--border); }
.gauge-fill { transition: stroke-dashoffset 0.8s ease, stroke 0.3s ease; }
.verdict.safe .gauge-fill   { stroke: var(--success); }
.verdict.unsafe .gauge-fill { stroke: var(--danger); }
.gauge-value {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}
.verdict.safe .gauge-value   { color: var(--success); }
.verdict.unsafe .gauge-value { color: var(--danger); }

/* ═══════════ METRICS ═══════════ */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.metric-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: all var(--transition);
}
.metric-card:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255,255,255,0.1);
}

.metric-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}
.metric-icon.blue   { background: var(--accent-dim); color: var(--accent); }
.metric-icon.purple { background: var(--purple-dim); color: var(--purple); }
.metric-icon.orange { background: var(--orange-dim); color: var(--orange); }
.metric-icon.green  { background: var(--success-dim); color: var(--success); }

.metric-body { display: flex; flex-direction: column; min-width: 0; }
.metric-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}
.metric-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

/* ═══════════ CHARTS ═══════════ */
.charts-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 16px;
    margin-bottom: 16px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.chart-card.full-width { margin-bottom: 16px; }
.mk-metrics { margin-bottom: 16px; }

.chart-header {
    padding: 16px 20px 0;
}
.chart-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.chart-body {
    padding: 12px 16px 16px;
    position: relative;
}
.chart-body canvas {
    width: 100% !important;
    max-height: 320px;
}

.section-canvas-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
}
.section-canvas-wrap canvas {
    max-height: 280px !important;
}

/* ═══════════ DETAILS ═══════════ */
.details-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
}

.details-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 16px 20px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
}
.details-toggle h3 {
    font-size: 0.85rem;
    font-weight: 600;
}
.details-toggle .chevron {
    color: var(--text-muted);
    transition: transform var(--transition);
}
.details-toggle.open .chevron { transform: rotate(180deg); }

.details-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}
.details-body.open {
    max-height: 2000px;
}

#detailsContent {
    padding: 0 20px 20px;
}

.detail-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 12px 0 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    gap: 12px;
}
.detail-row:last-child { border-bottom: none; }

.detail-param {
    color: var(--text-secondary);
    font-weight: 400;
}
.detail-symbol {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    color: var(--text-primary);
}
.detail-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    text-align: right;
    color: var(--text-primary);
    white-space: nowrap;
    flex-shrink: 0;
}
.detail-unit {
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 4px;
}

/* ═══════════ ANIMATIONS ═══════════ */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.6; }
}

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 1200px) {
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
    :root { --sidebar-w: 340px; }
}

@media (max-width: 900px) {
    .app-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    body { overflow: auto; height: auto; }
    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: none;
    }
    .content { min-height: 100vh; }
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .metrics-grid { grid-template-columns: 1fr; }
    .header { padding: 0 16px; }
    .header-title { font-size: 1rem; }
    .header-sub { display: none; }
    .sidebar, .content { padding: 16px; }
    .verdict { flex-wrap: wrap; }
}
