* {
    box-sizing: border-box;
}

:root {
    --bg: #111;
    --panel: #1b1b1b;
    --panel-2: #161616;
    --border: #333;
    --input: #222;
    --text: #eee;
    --muted: #aaa;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100%;
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    overflow: hidden;
}

.app {
    display: flex;
    width: 100%;
    height: 100dvh;
    min-height: 100vh;
}

.sidebar {
    width: 340px;
    max-width: 100%;
    background: var(--panel);
    padding: 16px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

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

.sidebar h1 {
    margin: 0;
    font-size: 1.6rem;
}

.sidebar-header p {
    margin: 6px 0 0 0;
    color: #cfcfcf;
}

.sidebar-body {
    margin-top: 10px;
}

.mobile-sidebar-toggle {
    display: none;
    width: auto;
    min-width: 96px;
}

.field-label {
    display: block;
    margin-top: 12px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0 8px;
    font-size: 0.98rem;
}

.check-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    flex: 0 0 auto;
}

.sidebar input,
.sidebar button,
.sidebar select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    margin-top: 8px;
    margin-bottom: 12px;
    border: 1px solid #444;
    border-radius: 8px;
    background: var(--input);
    color: #fff;
    font-size: 16px;
}

.sidebar input[type="file"] {
    padding: 8px;
}

.sidebar button {
    cursor: pointer;
}

.sidebar button:hover {
    background: #333;
}

.flash-message {
    padding: 10px 12px;
    margin: 12px 0;
    border-radius: 8px;
    border: 1px solid;
    font-size: 0.95rem;
}

.flash-message.success {
    background: #16351f;
    border-color: #2e7d46;
    color: #d7ffe2;
}

.info,
.import-form {
    margin-top: 16px;
    padding: 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.info h2,
.info h3 {
    margin-top: 0;
}

.info p {
    margin: 0 0 10px 0;
    line-height: 1.35;
}

.molecule-list {
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #101010;
    padding: 6px;
    -webkit-overflow-scrolling: touch;
}

.molecule-list-empty {
    padding: 10px;
    color: var(--muted);
    font-size: 0.95rem;
}

.molecule-item {
    display: block;
    width: 100%;
    text-align: left;
    background: #1a1a1a;
    color: #eee;
    border: 1px solid #2d2d2d;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.molecule-item:hover {
    background: #262626;
    border-color: #555;
}

.molecule-item.active {
    background: #2d3f56;
    border-color: #6fa8dc;
}

.molecule-item-name {
    font-weight: bold;
    display: block;
}

.molecule-item-formula {
    font-size: 0.9rem;
    color: #bbb;
    display: block;
    margin-top: 2px;
}

.molecule-properties-block {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.molecule-properties-block h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
}

.molecule-properties-empty {
    color: var(--muted);
    font-size: 0.92rem;
}

.molecule-property-item {
    padding: 8px 0;
    border-bottom: 1px solid #262626;
}

.molecule-property-name {
    display: block;
    font-weight: bold;
    color: #ddd;
    margin-bottom: 2px;
}

.molecule-property-value {
    display: block;
    color: #bbb;
    font-size: 0.92rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.atom-info {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.75);
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    pointer-events: none;
}

.atom-info.hidden {
    display: none;
}

.viewer-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-width: 0;
    background: #0d0d0d;
}

.viewer-toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 2;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #ddd;
    font-size: 0.88rem;
    pointer-events: none;
}

#viewer {
    width: 100%;
    height: 100%;
    touch-action: none;
}

@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    .app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 14px;
    }

    .mobile-sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin: 0;
    }

    .sidebar-body {
        display: none;
        margin-top: 14px;
    }

    .sidebar.mobile-open .sidebar-body {
        display: block;
    }

    .molecule-list {
        max-height: 220px;
    }

    .viewer-area {
        width: 100%;
        height: 60vh;       /* fallback */
        min-height: 420px;  /* safety floor */
        flex: 0 0 auto;
    }

    #viewer {
        width: 100%;
        height: 100%;
        min-height: 420px;  /* keeps canvas alive */
    }

    .viewer-toolbar {
        top: 10px;
        left: 10px;
        right: 10px;
        font-size: 0.82rem;
    }
}

@supports (height: 100dvh) {
    @media (max-width: 900px) {
        .viewer-area {
            height: 60dvh;
        }
    }
}

@media (min-width: 901px) {
    .sidebar-body {
        display: block !important;
    }
}
