/* ══════════════════════════════════════════════════════
   FormalCS Platform — Main Stylesheet
   Design: Dark editorial with electric amber accents
   ══════════════════════════════════════════════════════ */

:root {
    --bg-base: #0a0a0f;
    --bg-surface: #111118;
    --bg-card: #16161e;
    --bg-card-hover: #1c1c27;
    --bg-input: #0e0e16;
    --bg-code: #0c0c14;

    --accent: #f5a623;
    --accent-dim: rgba(245, 166, 35, 0.15);
    --accent-border: rgba(245, 166, 35, 0.3);
    --accent-glow: 0 0 24px rgba(245, 166, 35, 0.25);

    --green: #3de68a;
    --green-dim: rgba(61, 230, 138, 0.12);
    --red: #ff5c7a;
    --red-dim: rgba(255, 92, 122, 0.12);
    --blue: #5b9fff;
    --blue-dim: rgba(91, 159, 255, 0.12);
    --purple: #a78bfa;
    --purple-dim: rgba(167, 139, 250, 0.12);

    --text-primary: #e8e8f0;
    --text-secondary: #8888a8;
    --text-muted: #55556a;
    --text-accent: var(--accent);

    --border: rgba(255,255,255,0.06);
    --border-hover: rgba(255,255,255,0.12);
    --border-accent: var(--accent-border);

    --sidebar-w: 240px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --font-display: 'Syne', sans-serif;
    --font-body: 'Instrument Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-card: 0 4px 24px rgba(0,0,0,0.4);
    --shadow-elevated: 0 8px 40px rgba(0,0,0,0.6);
}

/* ── Reset ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

/* ── Noise Texture ───────────────────────────────────── */
.noise-overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 128px 128px;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-mark {
    width: 36px;
    height: 36px;
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    flex-shrink: 0;
}

.logo-mark svg { width: 20px; height: 20px; }

.logo-text { display: flex; flex-direction: column; line-height: 1.2; }

.logo-main {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 15px;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.logo-sub {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.sidebar-section {
    padding: 20px 12px 12px;
    flex: 1;
}

.sidebar-section.sidebar-bottom {
    flex: 0;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.section-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 0 8px;
    display: block;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
    transition: width var(--transition);
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.nav-item.active {
    color: var(--accent);
    background: var(--accent-dim);
}

.nav-item.active::before { width: 3px; }

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nav-icon svg { width: 16px; height: 16px; }

/* ── Main Content ────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

.page-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 40px 80px;
}

/* ── Mobile Toggle ───────────────────────────────────── */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
}
.mobile-toggle:hover { background: var(--bg-card-hover); }

/* ── Page Header ─────────────────────────────────────── */
.page-header {
    margin-bottom: 40px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}

.page-header-content {}

.page-tag {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.1em;
    color: var(--accent);
    text-transform: uppercase;
    display: inline-block;
    margin-bottom: 8px;
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    padding: 3px 10px;
    border-radius: 20px;
}

.page-title {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    line-height: 1.1;
    margin-bottom: 10px;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    max-width: 500px;
}

/* ── Cards ───────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: all var(--transition);
}

.card:hover { border-color: var(--border-hover); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title-icon {
    width: 28px;
    height: 28px;
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 13px;
}

/* ── Grid layouts ────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Form Elements ───────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 6px;
}

.form-label .required { color: var(--accent); margin-left: 2px; }
.form-label .hint {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-muted);
    margin-left: 8px;
}

.form-input, .form-textarea, .form-select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
    transition: all var(--transition);
    outline: none;
    appearance: none;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-input::placeholder, .form-textarea::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.7;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    transition: opacity var(--transition);
}
.btn:hover::after { opacity: 0.06; }
.btn:active::after { opacity: 0.12; }

.btn-primary {
    background: var(--accent);
    color: #0a0a0f;
}

.btn-secondary {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--border-hover); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-card); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 13px 28px; font-size: 14px; }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-icon { padding: 8px; width: 34px; height: 34px; justify-content: center; }

/* ── Status Badges ───────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.05em;
}

.badge-success { background: var(--green-dim); color: var(--green); border: 1px solid rgba(61,230,138,0.2); }
.badge-error { background: var(--red-dim); color: var(--red); border: 1px solid rgba(255,92,122,0.2); }
.badge-info { background: var(--blue-dim); color: var(--blue); border: 1px solid rgba(91,159,255,0.2); }
.badge-warning { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent-border); }
.badge-purple { background: var(--purple-dim); color: var(--purple); border: 1px solid rgba(167,139,250,0.2); }

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Result Panel ────────────────────────────────────── */
.result-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-top: 24px;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.result-title {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.result-body { padding: 20px; }

/* ── Code/Mono blocks ────────────────────────────────── */
.code-block {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.8;
    color: var(--text-primary);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.formula-display {
    font-family: var(--font-mono);
    font-size: 15px;
    color: var(--accent);
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    display: block;
    margin: 8px 0;
    letter-spacing: 0.02em;
}

/* ── Step List ───────────────────────────────────────── */
.step-list { display: flex; flex-direction: column; gap: 8px; }

.step-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    animation: stepIn 0.3s ease both;
}

@keyframes stepIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: none; }
}

.step-num {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--accent-border);
    border-radius: 4px;
    padding: 2px 6px;
    flex-shrink: 0;
    min-width: 32px;
    text-align: center;
}

.step-content {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    line-height: 1.6;
}

.step-content strong { color: var(--text-primary); }

.step-item.step-accept { border-color: rgba(61,230,138,0.25); background: var(--green-dim); }
.step-item.step-reject { border-color: rgba(255,92,122,0.25); background: var(--red-dim); }
.step-item.step-highlight { border-color: var(--accent-border); }

/* ── Loading ─────────────────────────────────────────── */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 13px;
}

/* ── Table ───────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-card); }
.data-table .td-true { color: var(--green); }
.data-table .td-false { color: var(--red); }
.data-table .td-result { font-weight: 600; }

/* ── Accordion ───────────────────────────────────────── */
.accordion { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.accordion-item { border-bottom: 1px solid var(--border); }
.accordion-item:last-child { border-bottom: none; }

.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--bg-card);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}
.accordion-header:hover { background: var(--bg-card-hover); }

.accordion-title {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.accordion-arrow {
    color: var(--text-muted);
    transition: transform var(--transition);
    font-size: 10px;
}
.accordion-item.open .accordion-arrow { transform: rotate(180deg); }

.accordion-body {
    display: none;
    padding: 16px 18px;
    background: var(--bg-surface);
}
.accordion-item.open .accordion-body { display: block; }

/* ── Toast ───────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    font-size: 13px;
    color: var(--text-primary);
    min-width: 240px;
    max-width: 360px;
    box-shadow: var(--shadow-elevated);
    pointer-events: all;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px) scale(0.96); }
    to { opacity: 1; transform: none; }
}

.toast.toast-success { border-color: rgba(61,230,138,0.3); }
.toast.toast-error { border-color: rgba(255,92,122,0.3); }

/* ── Divider ─────────────────────────────────────────── */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

/* ── Empty State ─────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 32px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.empty-sub {
    font-size: 13px;
    max-width: 280px;
    line-height: 1.6;
}

/* ── Tabs ────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 3px;
    width: fit-content;
    margin-bottom: 20px;
}

.tab-btn {
    padding: 7px 16px;
    border-radius: calc(var(--radius-sm) - 2px);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Info Box ────────────────────────────────────────── */
.info-box {
    background: var(--blue-dim);
    border: 1px solid rgba(91,159,255,0.2);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 12.5px;
    color: var(--blue);
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.warn-box {
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 12.5px;
    color: var(--accent);
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 16px;
}

/* ── Visualization ───────────────────────────────────── */
#fa-graph {
    width: 100%;
    height: 340px;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: none;
        box-shadow: 4px 0 40px rgba(0,0,0,0.6);
    }
    .main-content { margin-left: 0; }
    .mobile-toggle { display: flex; }
    .page-inner { padding: 72px 20px 60px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .page-title { font-size: 26px; }
}

@media (max-width: 600px) {
    .page-inner { padding: 64px 16px 48px; }
    .card { padding: 16px; }
    .page-header { flex-direction: column; }
}

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Selection ───────────────────────────────────────── */
::selection { background: var(--accent-dim); color: var(--accent); }