/* ========================================================
   Computational Chemistry 3D Viewer — Stylesheet
   ======================================================== */

/* ── CSS Custom Properties (Design Tokens) ── */
:root {
    /* Colors */
    --bg-deep: #06060e;
    --bg-mid: #0c0c1e;
    --bg-surface: rgba(16, 16, 36, 0.65);
    --glass-border: rgba(120, 200, 255, 0.10);
    --glass-bg: rgba(18, 18, 44, 0.55);
    --glass-hover: rgba(24, 24, 56, 0.7);

    --accent: #e91e8c;
    --accent-dim: rgba(233, 30, 140, 0.14);
    --accent-glow: rgba(233, 30, 140, 0.32);
    --accent-purple: #a855f7;
    --accent-purple-dim: rgba(168, 85, 247, 0.15);

    --text-primary: #e8ecf4;
    --text-secondary: #8892a8;
    --text-muted: #515b70;

    --danger: #ff4d6a;
    --danger-bg: rgba(255, 77, 106, 0.12);

    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --duration: 0.3s;
}

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

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

body {
    font-family: var(--font-sans);
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ── Animated Background Canvas ── */
#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* ── App Container ── */
.app-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 0 24px;
    max-width: 1560px;
    margin: 0 auto;
}

/* ── Header ── */
.app-header {
    position: relative;
    padding: 28px 0 20px;
    text-align: left;
}

.header-glow {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 500px;
    height: 160px;
    background: radial-gradient(ellipse, var(--accent-glow) 0%, transparent 70%);
    opacity: 0.25;
    pointer-events: none;
    filter: blur(40px);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    color: var(--accent);
    filter: drop-shadow(0 0 8px var(--accent-glow));
    animation: logoPulse 4s ease-in-out infinite;
}

@keyframes logoPulse {

    0%,
    100% {
        filter: drop-shadow(0 0 8px var(--accent-glow));
    }

    50% {
        filter: drop-shadow(0 0 18px var(--accent-glow));
    }
}

.app-title {
    font-size: 1.6rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.app-subtitle {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.04em;
    margin-top: 2px;
}

/* ── Main Layout ── */
.main-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 24px;
    padding-bottom: 24px;
}

/* ── Side Panel ── */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* ── Glass Card ── */
.glass-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 22px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow:
        0 4px 30px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    transition: border-color var(--duration) var(--ease-out),
        box-shadow var(--duration) var(--ease-out);
}

.glass-card:hover {
    border-color: rgba(120, 200, 255, 0.18);
}

/* ── Card Titles ── */
.card-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-icon {
    font-size: 1rem;
}

/* ── Search Card ── */
.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.molecule-input {
    flex: 1;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.92rem;
    outline: none;
    transition: border-color var(--duration) var(--ease-out),
        box-shadow var(--duration) var(--ease-out);
}

.molecule-input::placeholder {
    color: var(--text-muted);
}

.molecule-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 180ms ease;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #c21875);
    color: #fff;
    box-shadow: 0 2px 16px var(--accent-dim);
}

.btn-primary:hover {
    box-shadow: 0 4px 24px var(--accent-glow);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary.loading .btn-text {
    opacity: 0;
}

.btn-primary.loading .btn-loader {
    display: block;
}

.btn-loader {
    display: none;
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(10, 10, 26, 0.25);
    border-top-color: #0a0a1a;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    position: absolute;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    padding: 8px 14px;
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.14);
}

.btn-ghost.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-ghost svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ── Quick Pick Chips ── */
.quick-picks {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quick-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    padding: 5px 12px;
    font-size: 0.78rem;
    font-family: var(--font-sans);
    font-weight: 500;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 999px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
}

.chip:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

/* ── Info Card ── */
.info-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

.placeholder-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
}

/* Skeleton loading */
.info-loading {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}

.skeleton-block {
    height: 18px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.04) 75%);
    background-size: 200% 100%;
    border-radius: var(--radius-sm);
    animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-block.short {
    width: 60%;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Info rows */
.info-content {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

/* SMILES row stacks vertically so the string has full width */
.info-row.smiles-row {
    flex-direction: column;
    gap: 6px;
}

.info-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    padding-top: 2px;
}

.info-value {
    font-size: 0.9rem;
    color: var(--text-primary);
    text-align: right;
    word-break: break-all;
}

.info-value.mono {
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.info-value.smiles {
    white-space: nowrap;
    overflow-x: auto;
    text-align: left;
    max-width: 100%;
    padding-bottom: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-dim) transparent;
}

.info-value.smiles::-webkit-scrollbar {
    height: 3px;
}

.info-value.smiles::-webkit-scrollbar-track {
    background: transparent;
}

.info-value.smiles::-webkit-scrollbar-thumb {
    background: var(--accent-dim);
    border-radius: 4px;
}

/* Copy SMILES button */
.smiles-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 6px;
    padding: 4px 10px;
    font-size: 0.72rem;
    font-family: var(--font-sans);
    font-weight: 500;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
}

.smiles-copy-btn:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.smiles-copy-btn.copied {
    background: rgba(0, 229, 255, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Controls Card ── */
.control-group {
    margin-bottom: 16px;
}

.control-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
    display: block;
}

.style-switcher {
    display: flex;
    gap: 6px;
}

.style-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
}

.style-btn svg {
    width: 22px;
    height: 22px;
}

.style-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
}

.style-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 12px var(--accent-dim);
}

.control-actions {
    display: flex;
    gap: 8px;
}

.control-actions .btn-ghost {
    flex: 1;
}

/* ── Viewer Section ── */
.viewer-section {
    display: flex;
    flex-direction: column;
}

.viewer-card {
    flex: 1;
    padding: 0;
    overflow: hidden;
    display: flex;
    min-height: 520px;
}

.viewer-container {
    flex: 1;
    position: relative;
    background: radial-gradient(ellipse at center, rgba(10, 10, 30, 0.9), var(--bg-deep));
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* Empty state animation */
.viewer-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 2;
    pointer-events: none;
    padding: 32px;
    text-align: center;
}

.viewer-empty.hidden {
    display: none;
}

.viewer-empty::before {
    content: "";
    position: absolute;
    inset: 8%;
    background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 520 320'%3E%3Cg fill='none' stroke='%23e91e8c' stroke-width='3' opacity='.18'%3E%3Cpath d='M92 175 165 102l90 40 88-68 86 112-76 58-98-45-92 72z'/%3E%3Ccircle cx='92' cy='175' r='24'/%3E%3Ccircle cx='165' cy='102' r='19'/%3E%3Ccircle cx='255' cy='142' r='30'/%3E%3Ccircle cx='343' cy='74' r='22'/%3E%3Ccircle cx='429' cy='186' r='28'/%3E%3Ccircle cx='353' cy='244' r='20'/%3E%3Ccircle cx='255' cy='199' r='17'/%3E%3Ccircle cx='163' cy='271' r='21'/%3E%3C/g%3E%3C/svg%3E");
    animation: emptyWireFloat 7s ease-in-out infinite alternate;
    pointer-events: none;
}

.empty-molecule-anim {
    position: relative;
    width: 120px;
    height: 120px;
    z-index: 1;
}

.nucleus {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 20px var(--accent-glow), 0 0 40px var(--accent-dim);
    animation: nucleusPulse 3s ease-in-out infinite;
}

@keyframes nucleusPulse {

    0%,
    100% {
        box-shadow: 0 0 20px var(--accent-glow), 0 0 40px var(--accent-dim);
    }

    50% {
        box-shadow: 0 0 30px var(--accent-glow), 0 0 60px var(--accent-dim);
    }
}

.orbit-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    border: 1px solid rgba(0, 229, 255, 0.15);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.ring-1 {
    width: 60px;
    height: 60px;
    animation: orbitSpin 6s linear infinite;
}

.ring-2 {
    width: 90px;
    height: 90px;
    border-color: rgba(168, 85, 247, 0.12);
    animation: orbitSpin 10s linear infinite reverse;
}

.ring-3 {
    width: 116px;
    height: 116px;
    border-style: dashed;
    border-color: rgba(0, 229, 255, 0.08);
    animation: orbitSpin 14s linear infinite;
}

@keyframes orbitSpin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

.empty-text {
    position: relative;
    z-index: 1;
    font-size: 1.15rem;
    color: var(--text-primary);
    font-weight: 700;
}

.empty-hint {
    position: relative;
    z-index: 1;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

@keyframes emptyWireFloat {
    from { transform: translateY(0) rotate(-2deg); opacity: 0.65; }
    to { transform: translateY(-10px) rotate(2deg); opacity: 1; }
}

[data-theme="light"] {
    --bg-deep: #f6f8fb;
    --bg-mid: #eef2f7;
    --bg-surface: rgba(255,255,255,0.9);
    --glass-bg: rgba(255,255,255,0.88);
    --glass-border: #e2e8f0;
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #4b5563;
}

[data-theme="light"] .glass-card {
    background: rgba(255,255,255,0.88);
    border-color: #e2e8f0;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07);
}

[data-theme="light"] .viewer-container {
    background: #f0f2f5;
}

[data-theme="light"] .molecule-input,
[data-theme="light"] .style-btn,
[data-theme="light"] .btn-ghost,
[data-theme="light"] .chip {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #374151;
}

[data-theme="light"] .molecule-input::placeholder {
    color: #4b5563;
}

/* ── Error Toast ── */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 22px;
    background: var(--danger-bg);
    border: 1px solid rgba(255, 77, 106, 0.25);
    border-radius: var(--radius-md);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px rgba(255, 77, 106, 0.15);
    z-index: 1000;
    opacity: 0;
    transition: all 0.4s var(--ease-out);
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.hidden {
    display: none;
}

.toast-icon {
    font-size: 1.1rem;
}

.toast-message {
    font-size: 0.88rem;
    color: var(--danger);
    font-weight: 500;
}

.toast-close {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
    transition: opacity var(--duration);
}

.toast-close:hover {
    opacity: 1;
}

/* ── Footer ── */
.app-footer {
    text-align: center;
    padding: 20px 0 24px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--duration);
}

.app-footer a:hover {
    color: #66f0ff;
}

.heart {
    color: var(--danger);
    display: inline-block;
    animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }
}

.footer-sub {
    margin-top: 4px;
    font-size: 0.72rem;
    opacity: 0.5;
}

/* ── Info Divider (NEW) ── */
.info-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 4px 0;
}

/* ── Viewer Loading Overlay (NEW) ── */
.viewer-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(6, 6, 14, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 5;
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: opacity 0.4s var(--ease-out);
}

.viewer-loading.hidden {
    display: none !important;
}

.viewer-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(0, 229, 255, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ── Atom Hover Tooltip (NEW) ── */
.atom-tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 10;
    padding: 6px 12px;
    background: rgba(12, 12, 30, 0.88);
    border: 1px solid rgba(0, 229, 255, 0.25);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--accent);
    white-space: nowrap;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    transition: opacity 0.15s ease;
}

.atom-tooltip.hidden {
    display: none !important;
}

/* ── Viewer Fade-in (NEW) ── */
.mol-viewer-div {
    animation: viewerFadeIn 0.5s ease forwards;
}

@keyframes viewerFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ── Utility ── */
.hidden {
    display: none !important;
}

/* ── Responsive ── */
@media (max-width: 960px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .viewer-card {
        min-height: 420px;
    }

    .app-container {
        padding: 0 14px;
    }

    .app-title {
        font-size: 1.25rem;
    }
}

@media (max-width: 600px) {
    .input-group {
        flex-direction: column;
    }

    .style-switcher {
        flex-direction: column;
    }

    .control-actions {
        flex-direction: column;
    }

    .viewer-card {
        min-height: 340px;
    }
}

[data-theme="light"] :is(.text-input, .molecule-input, input, textarea, select) {
    background: #ffffff;
    border-color: #d7dee8;
    color: #111827;
}

[data-theme="light"] :is(.text-input, .molecule-input, input, textarea, select)::placeholder { color: #64748b; }

[data-theme="light"] :is(.text-input, .molecule-input, input, textarea, select):focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

[data-theme="light"] :is(.chip, .style-btn, .btn-ghost, .back-link) {
    background: #ffffff;
    border-color: #d7dee8;
    color: #334155;
}

[data-theme="light"] :is(.chip, .style-btn, .btn-ghost, .back-link):hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

[data-theme="light"] .card-title { color: #1f2937; }

.app-footer a:hover { color: var(--accent-purple); }
