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

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 260px;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--gray-800);
    background: var(--gray-50);
}

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* === Auth Page === */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-100);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 0 20px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}
.auth-logo h1 {
    font-size: 28px;
    color: var(--primary);
}
.auth-logo p {
    color: var(--gray-500);
    margin-top: 4px;
}

.auth-form {
    background: #fff;
    padding: 32px;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* === App Layout === */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--gray-700);
}
.sidebar-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
}

.nav-item {
    display: block;
    padding: 10px 20px;
    color: var(--gray-300);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    font-size: 15px;
}
.nav-item:hover {
    background: var(--gray-800);
    color: #fff;
    text-decoration: none;
}
.nav-item.active {
    background: var(--primary);
    color: #fff;
}
.nav-item.logout {
    color: var(--gray-400);
    border-top: 1px solid var(--gray-700);
    margin-top: 8px;
    padding-top: 12px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-700);
}

.user-info {
    margin-bottom: 8px;
}
.user-name {
    display: block;
    font-weight: 600;
    font-size: 14px;
}
.user-role {
    display: block;
    font-size: 12px;
    color: var(--gray-400);
}

/* === Main Content === */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    max-width: 1200px;
}

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.content-header h1 {
    font-size: 24px;
    font-weight: 700;
}

.content-body {
    /* container for page content */
}

/* === Alerts === */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
}
.alert ul {
    margin: 0;
    padding-left: 20px;
}
.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}
.alert-success {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}

/* === Cards === */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 24px;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}
.card-body {
    padding: 20px;
}

/* === Stats === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: #fff;
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    text-align: center;
}
.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}
.stat-label {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
}

/* === Tables === */
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}
.table th {
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.table tbody tr:hover {
    background: var(--gray-50);
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.badge-success {
    background: #dcfce7;
    color: var(--success);
}
.badge-warning {
    background: #fef3c7;
    color: #b45309;
}
.badge-danger {
    background: #fef2f2;
    color: var(--danger);
}

/* === Forms === */
.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
    color: var(--gray-700);
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.form-group textarea {
    resize: vertical;
    min-height: 100px;
}
.form-group .form-hint {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
}
.form-group input[type="file"] {
    font-size: 14px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s;
    font-family: inherit;
}
.btn:hover {
    text-decoration: none;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
}
.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover {
    background: var(--danger-hover);
}
.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}
.btn-secondary:hover {
    background: var(--gray-300);
}
.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}
.btn-block {
    display: block;
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* === Misc === */
.text-muted {
    color: var(--gray-500);
}
.text-danger {
    color: var(--danger);
}
.text-success {
    color: var(--success);
}

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

/* === Chapter List (Drag & Drop) === */
.chapter-list {
    list-style: none;
}
.chapter-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: grab;
    transition: box-shadow 0.15s;
}
.chapter-item:active {
    cursor: grabbing;
}
.chapter-item.dragging {
    opacity: 0.5;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.chapter-item .drag-handle {
    color: var(--gray-400);
    font-size: 18px;
    user-select: none;
}
.chapter-item .chapter-info {
    flex: 1;
}
.chapter-item .chapter-title {
    font-weight: 600;
}
.chapter-item .chapter-meta {
    font-size: 13px;
    color: var(--gray-500);
}

/* === File List === */
.file-list {
    list-style: none;
}
.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 14px;
}
.file-item .file-name {
    flex: 1;
}
.file-item .file-size {
    color: var(--gray-500);
    margin: 0 12px;
}

/* === Preview Image === */
.preview-image {
    max-width: 300px;
    border-radius: 6px;
    margin-top: 8px;
}

/* === Code Display === */
.code-display {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 16px;
    letter-spacing: 2px;
    padding: 8px 16px;
    background: var(--gray-100);
    border-radius: 6px;
    display: inline-block;
    cursor: pointer;
    user-select: all;
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    .main-content {
        margin-left: 0;
        padding: 16px;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}
