/* ===== CSS Reset & Variables ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --accent-color: #ff6600;
    --background: #ffffff;
    --surface: #f8fafc;
    --surface-hover: #f1f5f9;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

/* ===== Base Styles ===== */
html, body {
    height: 100%;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== Header ===== */
.header {
    background: var(--background);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-center {
    text-align: center;
    flex: 1;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.header .subtitle {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 0.15rem;
}

.header-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-primary);
    transition: var(--transition);
}

.header-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.profile-btn {
    padding: 0.25rem;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    overflow: hidden;
}

.profile-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* ===== Dialog Overlay ===== */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.dialog-overlay.hidden {
    display: none;
}

.dialog {
    background: var(--background);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    max-height: 80vh;
    width: 90%;
    overflow: hidden;
    animation: dialogSlideIn 0.2s ease-out;
}

@keyframes dialogSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
}

.dialog-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: white;
    margin: 0;
}

.dialog-close {
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid white;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    line-height: 1;
}

.dialog-close:hover {
    background: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.dialog-content {
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(80vh - 60px);
}

.dialog-content h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0 0 0.5rem 0;
}

.dialog-content h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0 0 0.4rem 0;
}

.dialog-content p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 0 0.75rem 0;
}

.dialog-content ol,
.dialog-content ul {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0 0 1rem 0;
    padding-left: 1.25rem;
}

.dialog-content li {
    margin-bottom: 0.35rem;
}

.about-section,
.tutorial-section,
.features-section,
.tips-section,
.profile-section {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.about-section:last-child,
.tutorial-section:last-child,
.features-section:last-child,
.tips-section:last-child,
.profile-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Profile Dialog Specific */
.profile-hero {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.profile-hero-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary-color);
}

.profile-hero-info h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin: 0 0 0.25rem 0;
}

.profile-tagline {
    font-size: 0.7rem !important;
    color: var(--primary-color) !important;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.contact-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.contact-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.4rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.75rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: var(--transition);
}

.contact-link:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.profile-footer {
    text-align: center;
    font-size: 0.7rem !important;
    color: var(--text-muted) !important;
    margin-top: 1rem !important;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* ===== Main Content ===== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== Control Panel (Left) ===== */
.control-panel {
    width: 240px;
    min-width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 0.75rem;
    font-size: 0.8rem;
}

.control-panel::-webkit-scrollbar {
    width: 6px;
}

.control-panel::-webkit-scrollbar-track {
    background: transparent;
}

.control-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.control-panel::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* ===== Info Panel (Right) ===== */
.info-panel {
    width: 220px;
    min-width: 220px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 0.75rem;
    font-size: 0.8rem;
}

.info-panel::-webkit-scrollbar {
    width: 6px;
}

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

.info-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ===== Panel Sections ===== */
.panel-section {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem;
    margin-bottom: 0.6rem;
    transition: var(--transition);
}

.panel-section:hover {
    box-shadow: var(--shadow-sm);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.6rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}

.section-title .icon {
    font-size: 0.85rem;
}

/* ===== Collapsible Sections ===== */
.collapsible .section-title {
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
    border-bottom: none;
    transition: var(--transition);
}

.collapsible .section-title:hover {
    color: var(--primary-color);
}

.collapsible.collapsed .section-title {
    margin-bottom: 0;
    padding-bottom: 0;
}

.collapse-icon {
    margin-left: auto;
    font-size: 0.7rem;
    transition: transform 0.3s ease;
    color: var(--text-muted);
}

.collapsible.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.collapsible .section-content {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    opacity: 1;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 0.75rem;
}

.collapsible.collapsed .section-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    border-top: none;
    margin-top: 0;
}

/* ===== Upload Area ===== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--surface);
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.upload-area.drag-over {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.upload-icon {
    font-size: 1.5rem;
}

.upload-content p {
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.upload-hint {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.file-info {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    font-size: 0.7rem;
    color: var(--text-secondary);
}

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

/* ===== Form Elements ===== */
.setting-group {
    margin-bottom: 0.5rem;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group label {
    display: block;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.setting-row {
    display: flex;
    gap: 0.5rem;
}

.setting-group.half {
    flex: 1;
}

.input-field {
    width: 100%;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.75rem;
    color: var(--text-primary);
    background: var(--background);
    transition: var(--transition);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

/* ===== Range Slider ===== */
.range-slider {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    margin: 0.5rem 0;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: var(--transition);
}

.range-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.range-value {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== Color Input ===== */
.color-input {
    width: 100%;
    height: 28px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--background);
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-input::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

/* ===== Checkbox ===== */
.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font-size: 0.75rem !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    color: var(--text-primary) !important;
    margin-bottom: 0 !important;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: '✓';
    color: white;
    font-size: 10px;
    font-weight: bold;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.4rem 0.6rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--secondary-color);
}

.export-buttons {
    display: flex;
    gap: 0.5rem;
}

.export-buttons .btn {
    flex: 1;
}

.export-hint {
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* ===== Graph Container ===== */
.graph-container {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 0.5rem;
    position: relative;
    background: var(--background);
    min-width: 0;
    overflow: hidden;
}

.graph-wrapper {
    background: var(--background);
    border: 2px solid var(--text-primary);
    border-radius: 2px;
    padding: 0.5rem;
    position: relative;
    aspect-ratio: 16 / 9;
    width: 100%;
    max-width: calc(100% - 1rem);
    max-height: calc(100% - 1rem);
    box-sizing: border-box;
}

.graph-wrapper.hidden {
    display: none;
}

.graph-wrapper.auto-fit {
    aspect-ratio: auto;
    width: calc(100% - 1rem) !important;
    height: calc(100% - 1rem) !important;
}

.graph-wrapper canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.export-section {
    background: linear-gradient(135deg, var(--primary-color) 0%, #4f46e5 100%);
    border: none;
}

.export-section .section-title {
    color: white;
    border-bottom-color: rgba(255,255,255,0.2);
}

.export-section .export-hint {
    color: rgba(255,255,255,0.8);
}

.graph-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    margin: 2rem;
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border);
}

.graph-placeholder.hidden {
    display: none;
}

.placeholder-content {
    text-align: center;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
}

.placeholder-content h3 {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.placeholder-content p {
    font-size: 0.875rem;
}

/* ===== Peak List ===== */
.peak-list {
    max-height: 300px;
    overflow-y: auto;
}

.peak-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.75rem;
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
    transition: var(--transition);
}

.peak-item:hover {
    border-color: var(--primary-color);
}

.peak-wavenumber {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.peak-group {
    font-size: 0.75rem;
    color: var(--accent-color);
    margin-top: 0.25rem;
}

.peak-class {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.peak-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    transition: var(--transition);
}

.peak-remove:hover {
    color: #ef4444;
}

.no-peaks {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 1rem;
}

/* ===== Database Results ===== */
.search-box {
    margin-bottom: 0.75rem;
}

.db-results {
    max-height: 400px;
    overflow-y: auto;
}

.db-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 1rem;
}

.db-item {
    padding: 0.75rem;
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
}

.db-item:hover {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.db-range {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.85rem;
}

.db-group {
    font-size: 0.8rem;
    color: var(--text-primary);
    margin-top: 0.25rem;
}

.db-class {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.db-details {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-style: italic;
}

/* ===== Footer ===== */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.4rem;
    text-align: center;
}

.footer p {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* ===== Responsive Design ===== */
@media (max-width: 1200px) {
    .info-panel {
        width: 200px;
        min-width: 200px;
    }

    .control-panel {
        width: 220px;
        min-width: 220px;
    }
}

@media (max-width: 992px) {
    .main-content {
        flex-direction: column;
        overflow-y: auto;
    }

    .control-panel,
    .info-panel {
        width: 100%;
        min-width: 100%;
        max-height: none;
        border: none;
        border-bottom: 1px solid var(--border);
    }

    .graph-container {
        min-height: 500px;
    }
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.panel-section {
    animation: fadeIn 0.3s ease;
}

/* ===== Print Styles ===== */
@media print {
    .control-panel,
    .info-panel,
    .header,
    .footer {
        display: none;
    }

    .graph-container {
        width: 100%;
        padding: 0;
    }

    .graph-wrapper {
        max-width: none;
        max-height: none;
    }
}
