* {
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    margin: 0;
    background: #f5f7fb;
    color: #1f2937;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: #111827;
    color: #ffffff;
}

main {
    padding: 14px;
    flex: 1;
}

.topbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.card {
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.subtle {
    background: #fbfcff;
}

.hidden {
    display: none !important;
}

label {
    display: block;
    margin: 8px 0;
}

input[type="text"],
input[type="password"],
textarea {
    width: 100%;
    border: 1px solid #9ca3af;
    border-radius: 6px;
    padding: 8px;
}

button {
    border: 1px solid #1d4ed8;
    background: #2563eb;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
}

button:hover {
    background: #1d4ed8;
}

button.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-color: var(--btn-border, #1d4ed8);
    background: var(--btn-bg, #2563eb);
    color: #ffffff;
}

button.icon-btn:hover {
    background: var(--btn-hover, #1d4ed8);
}

button.icon-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-sign-in {
    --btn-bg: #1f7a2d;
    --btn-border: #166534;
    --btn-hover: #166534;
}

.btn-logout {
    --btn-bg: #475569;
    --btn-border: #334155;
    --btn-hover: #334155;
}

.btn-admin-tools {
    --btn-bg: #7e22ce;
    --btn-border: #6b21a8;
    --btn-hover: #6b21a8;
}

.btn-refresh-projects {
    --btn-bg: #0f766e;
    --btn-border: #115e59;
    --btn-hover: #115e59;
}

.btn-upload-project {
    --btn-bg: #0b5ed7;
    --btn-border: #0a58ca;
    --btn-hover: #0a58ca;
}

.btn-open-project {
    --btn-bg: #7c3aed;
    --btn-border: #6d28d9;
    --btn-hover: #6d28d9;
}

.btn-projects {
    --btn-bg: #0369a1;
    --btn-border: #075985;
    --btn-hover: #075985;
}

.btn-save {
    --btn-bg: #15803d;
    --btn-border: #166534;
    --btn-hover: #166534;
}

.btn-undo {
    --btn-bg: #0d9488;
    --btn-border: #0f766e;
    --btn-hover: #0f766e;
}

.btn-redo {
    --btn-bg: #0284c7;
    --btn-border: #0369a1;
    --btn-hover: #0369a1;
}

.btn-new-topic {
    --btn-bg: #4f46e5;
    --btn-border: #4338ca;
    --btn-hover: #4338ca;
}

.btn-new-lesson {
    --btn-bg: #7e22ce;
    --btn-border: #6b21a8;
    --btn-hover: #6b21a8;
}

.btn-delete-topic {
    --btn-bg: #be123c;
    --btn-border: #9f1239;
    --btn-hover: #9f1239;
}

.btn-delete-lesson {
    --btn-bg: #dc2626;
    --btn-border: #b91c1c;
    --btn-hover: #b91c1c;
}

.btn-merge {
    --btn-bg: #c2410c;
    --btn-border: #9a3412;
    --btn-hover: #9a3412;
}

.btn-upload-image {
    --btn-bg: #1d4ed8;
    --btn-border: #1e40af;
    --btn-hover: #1e40af;
}

.btn-refresh-backups {
    --btn-bg: #7c2d12;
    --btn-border: #9a3412;
    --btn-hover: #9a3412;
}

.btn-restore-backup {
    --btn-bg: #0e7490;
    --btn-border: #155e75;
    --btn-hover: #155e75;
}

.btn-view-backup {
    --btn-bg: #4f46e5;
    --btn-border: #4338ca;
    --btn-hover: #4338ca;
}

.btn-load-users {
    --btn-bg: #4338ca;
    --btn-border: #3730a3;
    --btn-hover: #3730a3;
}

.btn-add-user {
    --btn-bg: #2563eb;
    --btn-border: #1d4ed8;
    --btn-hover: #1d4ed8;
}

.btn-save-users {
    --btn-bg: #166534;
    --btn-border: #14532d;
    --btn-hover: #14532d;
}

.btn-row-delete {
    --btn-bg: #b91c1c;
    --btn-border: #991b1b;
    --btn-hover: #991b1b;
}

.btn-move-up {
    --btn-bg: #0891b2;
    --btn-border: #0e7490;
    --btn-hover: #0e7490;
}

.btn-move-down {
    --btn-bg: #6d28d9;
    --btn-border: #5b21b6;
    --btn-hover: #5b21b6;
}

.btn-modal-close {
    --btn-bg: #334155;
    --btn-border: #1e293b;
    --btn-hover: #1e293b;
}

.btn-audio-editor,
.btn-upload-audio-file {
    --btn-bg: #0f766e;
    --btn-border: #115e59;
    --btn-hover: #115e59;
}

.btn-record-audio {
    --btn-bg: #be123c;
    --btn-border: #9f1239;
    --btn-hover: #9f1239;
}

.btn-stop-record {
    --btn-bg: #7c2d12;
    --btn-border: #9a3412;
    --btn-hover: #9a3412;
}

.btn-audio-select {
    --btn-bg: #0c4a6e;
    --btn-border: #075985;
    --btn-hover: #075985;
}

.btn-audio-trim {
    --btn-bg: #4338ca;
    --btn-border: #3730a3;
    --btn-hover: #3730a3;
}

.btn-audio-delete {
    --btn-bg: #b91c1c;
    --btn-border: #991b1b;
    --btn-hover: #991b1b;
}

.btn-audio-split {
    --btn-bg: #9a3412;
    --btn-border: #7c2d12;
    --btn-hover: #7c2d12;
}

.btn-save-audio {
    --btn-bg: #166534;
    --btn-border: #14532d;
    --btn-hover: #14532d;
}

.row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 8px 0;
}

.wrap {
    flex-wrap: wrap;
}

.small {
    font-size: 12px;
    color: #4b5563;
}

.dashboard-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.editor-layout {
    display: grid;
    grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
    gap: 12px;
}

.editor-layout > section {
    min-width: 0;
}

.list {
    margin: 0;
    padding-left: 16px;
    max-height: 320px;
    overflow: auto;
}

.project-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}

.tree-topic {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 6px;
    margin-bottom: 8px;
    background: #f9fafb;
}

.tree-topic.active {
    border-color: #2563eb;
}

.tree-topic-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    margin-bottom: 6px;
}

.tree-topic-main {
    flex: 1;
}

.tree-topic-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tree-topic-actions button {
    padding: 2px 6px;
    font-size: 12px;
    min-width: 28px;
}

.tree-lesson {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 4px 6px;
    margin: 4px 0;
    background: #ffffff;
    cursor: pointer;
}

.tree-lesson-main {
    flex: 1;
}

.tree-lesson-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tree-lesson-actions button {
    padding: 2px 6px;
    font-size: 12px;
    min-width: 28px;
}

.tree-lesson.active {
    border-color: #2563eb;
    background: #eff6ff;
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.inline-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#lessonContentInput {
    min-height: 108.5vh;
}

.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    background: #111827;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 6px;
    z-index: 100;
}

.app-footer {
    border-top: 1px solid #d1d5db;
    background: #ffffff;
    color: #4b5563;
    text-align: center;
    padding: 10px 12px;
    font-size: 12px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: grid;
    place-items: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.6);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(1100px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.35);
}

.modal-card-wide {
    width: min(1280px, calc(100vw - 32px));
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.modal-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.modal-body .list {
    max-height: 52vh;
}

.audio-editor-body {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    gap: 16px;
}

.audio-editor-panel {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px;
    background: #f8fafc;
}

.audio-preview {
    width: 100%;
    margin-top: 8px;
}

.audio-waveform-canvas {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
}

.audio-selection-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.preview-body {
    display: block;
}

.backup-preview-frame {
    width: 100%;
    height: 72vh;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
}

.progress-bar-shell {
    width: 100%;
    height: 14px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid #d1d5db;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #2563eb, #0ea5e9);
    transition: width 0.2s ease;
}

.user-row {
    display: grid;
    grid-template-columns: 1fr 1fr 120px 70px 70px;
    gap: 6px;
    align-items: center;
    margin: 6px 0;
}

@media (max-width: 1200px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }

    .dashboard-layout {
        grid-template-columns: 1fr;
    }

    .modal-body {
        grid-template-columns: 1fr;
    }

    .audio-editor-body {
        grid-template-columns: 1fr;
    }
}

