/* ═══════════════════════════════════════════════════════════════
   Word Search Book Architect — Premium Dark Theme v2
   Three-column dashboard layout with glassmorphism
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    --bg-deep: #0a0e1a;
    --bg-surface: #111827;
    --bg-card: #1a2035;
    --bg-elevated: #1f2a45;
    --bg-hover: #253050;
    --bg-active: #2a3a60;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --accent2: #ec4899;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-faint: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.12);
    --glass: rgba(17, 24, 39, 0.85);
    --glass-border: rgba(255, 255, 255, 0.1);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --transition: 0.2s ease;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --sidebar-w: 320px;
    --chapters-w: 56px;
    --chapters-w-open: 200px;
    --header-h: 52px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-faint);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn-accent {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-accent:hover {
    background: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border-light);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--bg-hover);
    border-color: var(--text-faint);
}

.btn-success {
    background: var(--success);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-success:hover {
    background: #16a34a;
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    font-size: 1rem;
}

.btn-icon:hover {
    color: var(--text);
    background: var(--bg-hover);
}

/* ── Top Header Bar ────────────────────────────────────────── */
.top-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--header-h);
    background: var(--glass);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.top-header .brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.top-header .brand a {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.85rem;
    transition: var(--transition);
}

.top-header .brand a:hover {
    color: var(--text);
}

.top-header .project-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-header .actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-header .divider {
    width: 1px;
    height: 24px;
    background: var(--border-light);
    margin: 0 4px;
}

/* ── Main Layout (3-column) ────────────────────────────────── */
.app-layout {
    display: flex;
    height: calc(100vh - var(--header-h));
    margin-top: var(--header-h);
}

/* ── Column 1: Chapter Sidebar ─────────────────────────────── */
.chapters-sidebar {
    width: var(--chapters-w);
    min-width: var(--chapters-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, min-width 0.25s ease;
    overflow: hidden;
    z-index: 10;
}

.chapters-sidebar.expanded {
    width: var(--chapters-w-open);
    min-width: var(--chapters-w-open);
}

.chapters-header {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    flex-shrink: 0;
}

.chapters-header .title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
    overflow: hidden;
}

.chapters-sidebar:not(.expanded) .chapters-header .title {
    display: none;
}

.chapters-sidebar:not(.expanded) .ch-add-btn span {
    display: none;
}

.ch-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 4px 0;
}

.ch-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: var(--transition);
    position: relative;
}

.ch-item:hover {
    background: var(--bg-hover);
}

.ch-item.active {
    background: var(--bg-active);
    border-left-color: var(--accent);
}

.ch-item .ch-num {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
    background: var(--bg-elevated);
    color: var(--text-dim);
}

.ch-item.active .ch-num {
    background: var(--accent);
    color: #fff;
}

.ch-item.built .ch-num {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.ch-item.active.built .ch-num {
    background: var(--accent);
    color: #fff;
}

.ch-item.warn {
    border-left-color: var(--danger);
    background: rgba(239, 68, 68, 0.06);
}

.ch-item.warn .ch-num {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.ch-item .ch-label {
    flex: 1;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.ch-item .ch-meta {
    font-size: 0.65rem;
    color: var(--text-faint);
    white-space: nowrap;
}

.chapters-sidebar:not(.expanded) .ch-label,
.chapters-sidebar:not(.expanded) .ch-meta {
    display: none;
}

.ch-add-btn {
    margin: 6px 8px;
    padding: 6px;
    text-align: center;
    border: 1px dashed var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-faint);
    cursor: pointer;
    font-size: 0.78rem;
    transition: var(--transition);
    flex-shrink: 0;
}

.ch-add-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Column 2: Properties Panel ────────────────────────────── */
.props-panel {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.25s ease, min-width 0.25s ease;
}

.props-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* Accordion Sections */
.prop-section {
    border-bottom: 1px solid var(--border);
}

.prop-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    transition: var(--transition);
    user-select: none;
}

.prop-section-header:hover {
    background: var(--bg-hover);
}

.prop-section-header .icon {
    font-size: 1rem;
}

.prop-section-header .arrow {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-faint);
    transition: transform 0.2s;
}

.prop-section.open .prop-section-header .arrow {
    transform: rotate(90deg);
}

.prop-section-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.prop-section.open .prop-section-body {
    max-height: 2000px;
}

.prop-section-inner {
    padding: 0 16px 16px 16px;
}

/* ── Column 3: Preview Canvas ──────────────────────────────── */
.preview-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-deep);
    overflow: hidden;
    min-width: 0;
}

.preview-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.preview-toolbar .status {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.preview-toolbar .status.success {
    color: var(--success);
}

.preview-toolbar .status.warning {
    color: var(--warning);
}

.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;
    background: radial-gradient(circle at 50% 50%, #131a2e 0%, var(--bg-deep) 100%);
}

.preview-area canvas {
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    max-width: 100%;
    height: auto;
}

/* ── Form Controls ─────────────────────────────────────────── */
.form-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 4px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-control,
.form-select {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-light) !important;
    color: var(--text) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 0.85rem !important;
    padding: 7px 10px !important;
    transition: var(--transition);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--accent-glow) !important;
    outline: none !important;
}

textarea.form-control {
    resize: vertical;
    min-height: 60px;
}

.form-check-input {
    background-color: var(--bg-elevated) !important;
    border-color: var(--border-light) !important;
}

.form-check-input:checked {
    background-color: var(--accent) !important;
    border-color: var(--accent) !important;
}

/* ── Badge ─────────────────────────────────────────────────── */
.badge-accent {
    background: var(--accent-glow);
    color: var(--accent);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-dark .modal-content {
    background: var(--bg-card) !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--radius-lg) !important;
    color: var(--text) !important;
    box-shadow: var(--shadow);
}

.modal-dark .modal-header {
    border-bottom: 1px solid var(--border) !important;
}

.modal-dark .modal-footer {
    border-top: 1px solid var(--border) !important;
}

.modal-dark .modal-title {
    font-weight: 700;
}

.modal-dark .btn-close-white {
    filter: invert(1);
}

.export-section {
    margin-bottom: 14px;
}

.export-section h6 {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Progress */
.progress-custom {
    background: var(--bg-elevated);
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
}

.progress-custom .progress-bar {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
}

/* ── Dropdown menus ────────────────────────────────────────── */
.dropdown-menu-dark {
    background: var(--bg-card) !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--radius) !important;
}

.dropdown-menu-dark .dropdown-item {
    color: var(--text) !important;
    font-size: 0.85rem;
}

.dropdown-menu-dark .dropdown-item:hover {
    background: var(--bg-hover) !important;
}

.dropdown-menu-dark .dropdown-divider {
    border-color: var(--border) !important;
}

/* ── Login & Dashboard pages (unchanged styling) ───────────── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-deep) 0%, #0f172a 50%, #1a1040 100%);
    padding: 20px;
}

.auth-card {
    background: var(--glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-card h1 {
    font-size: 1.6rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 6px;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}

.auth-tab.active {
    background: var(--accent);
    color: #fff;
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

/* Dashboard */
.dash-wrapper {
    min-height: 100vh;
    background: var(--bg-deep);
    overflow: auto;
}

.dash-header {
    background: var(--glass);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dash-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
}

.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    padding: 24px;
}

.project-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    transition: var(--transition);
}

.project-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.project-card h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.project-card .meta {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.new-project-card {
    border: 2px dashed var(--border-light);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    font-size: 0.9rem;
    color: var(--text-faint);
}

.new-project-card:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Responsive ────────────────────────────────────────────── */
.mobile-toggle {
    display: none;
}

@media (max-width: 1024px) {
    .props-panel {
        --sidebar-w: 280px;
    }
}

@media (max-width: 768px) {
    .mobile-toggle {
        display: inline-flex;
    }

    .chapters-sidebar {
        position: fixed;
        left: 0;
        top: var(--header-h);
        bottom: 0;
        transform: translateX(-100%);
        z-index: 50;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
        width: var(--chapters-w-open) !important;
        min-width: var(--chapters-w-open) !important;
    }

    .chapters-sidebar.mobile-open {
        transform: translateX(0);
    }

    .props-panel {
        position: fixed;
        left: 0;
        top: var(--header-h);
        bottom: 0;
        transform: translateX(-100%);
        z-index: 40;
        width: 300px !important;
        min-width: 300px !important;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }

    .props-panel.mobile-open {
        transform: translateX(0);
    }

    .preview-col {
        width: 100%;
    }

    .mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 30;
        background: rgba(0, 0, 0, 0.5);
    }

    .mobile-overlay.show {
        display: block;
    }
}

/* ── Animations ────────────────────────────────────────────── */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.pulse {
    animation: pulse 1.5s ease infinite;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

/* ── Mini row helpers ──────────────────────────────────────── */
.row-2 {
    display: flex;
    gap: 8px;
}

.row-2>* {
    flex: 1;
}

.row-3 {
    display: flex;
    gap: 6px;
    align-items: center;
}

.mt-sm {
    margin-top: 8px;
}

.mb-sm {
    margin-bottom: 8px;
}

.mb-md {
    margin-bottom: 14px;
}

.text-xs {
    font-size: 0.72rem;
}

.text-dim {
    color: var(--text-dim);
}

.text-faint {
    color: var(--text-faint);
}

.text-accent {
    color: var(--accent);
}

.w-full {
    width: 100%;
}

.gap-sm {
    gap: 6px;
}