/* ============================================
   CSS Variables & Theme
   ============================================ */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-tertiary: #2d2d2d;
    --bg-hover: #3a3a3a;
    --bg-card: #333333;
    --text-primary: #e8e8e8;
    --text-secondary: #b0b0b0;
    --text-muted: #888888;
    --border-color: #444444;
    --accent: #4a9eff;
    --accent-hover: #6bb0ff;
    --accent-dark: #3a7abd;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --info: #00bcd4;
    --purple: #9c27b0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    --radius: 8px;
    --radius-sm: 4px;
    --transition: 0.2s ease;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8e8;
    --bg-hover: #e0e0e0;
    --bg-card: #f0f0f0;
    --text-primary: #222222;
    --text-secondary: #555555;
    --text-muted: #999999;
    --border-color: #cccccc;
    --border-light: #dddddd;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

html,
body {
    height: 100%;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background var(--transition), color var(--transition);
}

#app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

button {
    cursor: pointer;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    padding: 6px 14px;
    font-size: 13px;
    transition: all var(--transition);
}

input,
select,
textarea {
    font-family: inherit;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 13px;
    transition: border var(--transition);
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

/* ============================================
   Scrollbar
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   Buttons
   ============================================ */
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background: var(--accent-hover);
}
.btn-primary:active {
    background: var(--accent-dark);
}

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

.btn-sm {
    padding: 3px 10px;
    font-size: 12px;
}

.icon-btn {
    background: transparent;
    color: var(--text-secondary);
    font-size: 18px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover {
    background: #d32f2f;
}

/* ============================================
   Top Bar
   ============================================ */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    height: 56px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo-icon {
    font-size: 24px;
}
.logo h1 {
    font-size: 18px;
    font-weight: 600;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.path-display {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 4px 12px;
    border-radius: 12px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   Main Layout
   ============================================ */
.main-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow: hidden;
}

.left-panel {
    flex: 0 0 280px;
    min-width: 220px;
}

.center-panel {
    flex: 1;
    border-right: 1px solid var(--border-color);
}

.right-panel {
    flex: 0 0 320px;
    min-width: 250px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    min-height: 44px;
}
.panel-header h2 {
    font-size: 14px;
    font-weight: 600;
}

.panel-search {
    display: flex;
    gap: 6px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    align-items: center;
}
.panel-search input {
    flex: 1;
}
.panel-search select {
    flex: 0 0 80px;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.panel-footer {
    padding: 6px 14px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ============================================
   Lists
   ============================================ */
.list-items {
    list-style: none;
}
.list-items li {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
}
.list-items li:last-child {
    border-bottom: none;
}
.list-items li:hover {
    background: var(--bg-hover);
}
.list-items li.active {
    background: var(--accent);
    color: #fff;
}

.list-items li .item-actions {
    display: flex;
    gap: 4px;
}
.list-items li .item-actions button {
    padding: 0 6px;
    font-size: 12px;
    background: transparent;
    color: var(--text-muted);
}
.list-items li .item-actions button:hover {
    color: var(--text-primary);
}
.list-items li .item-actions button.delete-btn:hover {
    color: var(--danger);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
}
.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}
.empty-state p {
    font-size: 14px;
}

/* ============================================
   Editor Controls
   ============================================ */
.editor-controls {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    background: var(--bg-tertiary);
}
.editor-controls .form-group {
    flex: 1;
    min-width: 150px;
}
.editor-controls .form-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-with-button {
    display: flex;
    gap: 4px;
}
.input-with-button input {
    flex: 1;
}

.editor-scroll {
    padding: 14px;
}

/* ============================================
   Topic Cards (Content Cards)
   ============================================ */
.topic-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
    transition: border var(--transition);
}

.topic-card.highlight {
    border-color: var(--warning);
    box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.2);
}

.topic-card .topic-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.topic-card .topic-header .topic-title {
    font-weight: 600;
    font-size: 15px;
}
.topic-card .topic-header .topic-actions {
    display: flex;
    gap: 4px;
}

.topic-card .topic-field {
    margin-bottom: 8px;
}
.topic-card .topic-field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.topic-card .topic-field input,
.topic-card .topic-field textarea {
    background: var(--bg-secondary);
}

/* Content Cards */
.content-card {
    border-radius: var(--radius-sm);
    padding: 10px;
    margin-top: 8px;
    border-left: 3px solid var(--accent);
    display: flex;
    gap: 8px;
    align-items: flex-start;
    background: var(--bg-secondary);
}

.content-card .content-body {
    flex: 1;
}
.content-card .content-body textarea {
    background: var(--bg-primary);
}
.content-card .content-body input {
    background: var(--bg-primary);
}

.content-card .content-type {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    min-width: 60px;
}

.content-card .content-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}
.content-card .content-actions button {
    padding: 2px 6px;
    font-size: 11px;
    background: transparent;
    color: var(--text-muted);
}
.content-card .content-actions button:hover {
    color: var(--text-primary);
}
.content-card .content-actions button.delete-btn:hover {
    color: var(--danger);
}

.content-card.info {
    border-left-color: var(--success);
}
.content-card.image {
    border-left-color: var(--warning);
}
.content-card.title {
    border-left-color: var(--purple);
}
.content-card.carousel {
    border-left-color: var(--info);
}
.content-card.textarea {
    border-left-color: var(--accent);
}

/* Add content buttons */
.add-content-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.add-content-row button {
    font-size: 11px;
    padding: 4px 12px;
}

/* Carousel images */
.carousel-images {
    margin-top: 6px;
    padding-left: 10px;
}
.carousel-image-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 4px;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}
.carousel-image-row input {
    flex: 1;
}
.carousel-image-row .img-index {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 50px;
}

/* ============================================
   Bottom Bar
   ============================================ */
.bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    height: 48px;
}

.bottom-bar-left {
    display: flex;
    gap: 8px;
}

.bottom-bar-right {
    font-size: 13px;
    color: var(--text-muted);
}

#statusMessage {
    transition: color var(--transition);
}
#statusMessage.success {
    color: var(--success);
}
#statusMessage.error {
    color: var(--danger);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {
    .left-panel {
        flex: 0 0 200px;
        min-width: 160px;
    }
    .right-panel {
        flex: 0 0 240px;
        min-width: 180px;
    }
}

@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }
    .left-panel,
    .right-panel {
        flex: none;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .center-panel {
        flex: 1;
        min-height: 300px;
    }
    .top-bar {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 12px;
    }
    .top-bar-actions {
        flex-wrap: wrap;
    }
    .editor-controls {
        flex-direction: column;
    }
    .editor-controls .form-group {
        min-width: 100%;
    }
}