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

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #111111;
    --bg-card: #161616;
    --bg-input: #1a1a1a;
    --bg-sidebar: #141414;
    --border: #1e1e1e;
    --border-light: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --text-muted: rgba(255, 255, 255, 0.4);
    --text-faint: rgba(255, 255, 255, 0.2);
    --accent: #e94560;
    --accent-dark: #c23152;
    --accent-glow: rgba(233, 69, 96, 0.15);
    --accent-blue: #567bff;
    --color-success: #2ed573;
    --color-warning: #ffc107;
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-secondary);
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ===== Login Page ===== */
.login-page {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.brand-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    position: relative;
    overflow: hidden;
}

.brand-section::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(233, 69, 96, 0.15) 0%, transparent 70%);
    top: -100px;
    right: -100px;
    border-radius: 50%;
}

.brand-section::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(86, 123, 255, 0.1) 0%, transparent 70%);
    bottom: -80px;
    left: -80px;
    border-radius: 50%;
}

.brand-name {
    font-size: 5rem;
    font-weight: 800;
    letter-spacing: -2px;
    background: linear-gradient(135deg, var(--accent), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
    z-index: 1;
}

.brand-tagline {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-top: 12px;
    letter-spacing: 4px;
    text-transform: uppercase;
    font-weight: 300;
    position: relative;
    z-index: 1;
}

.login-section {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-secondary);
    padding: 2rem;
}

.login-box {
    width: 100%;
    max-width: 380px;
}

.login-box h2 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-box .subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

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

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-brand {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand h1 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.sidebar-nav a.active {
    color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
    border-left-color: var(--accent);
}

.sidebar-nav a .icon {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

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

.sidebar-footer a {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.15s;
}

.sidebar-footer a:hover {
    color: var(--accent);
}

/* Main content */
.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 32px 40px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.page-header h2 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
}

.page-header-sm h2 {
    font-size: 1.2rem;
}

/* ===== Buttons ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font);
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: var(--text-primary);
}

.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(233, 69, 96, 0.3);
}

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

.btn-danger {
    background: rgba(233, 69, 96, 0.1);
    color: var(--accent);
    border: 1px solid rgba(233, 69, 96, 0.2);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.82rem;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-faint);
}

.form-group textarea {
    min-height: 400px;
    resize: vertical;
    line-height: 1.7;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ===== Cards & Tables ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-padded {
    padding: 24px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    text-align: left;
    padding: 14px 20px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.35);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

table td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--bg-input);
    font-size: 0.92rem;
}

table tr:last-child td { border-bottom: none; }
table tr:hover td { background: rgba(255, 255, 255, 0.02); }

.cell-muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.cell-bold { font-weight: 600; }

.actions { display: flex; gap: 8px; }

/* ===== Status Badges ===== */
.status-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}

.status-published {
    background: rgba(46, 213, 115, 0.1);
    color: var(--color-success);
}

.status-draft {
    background: rgba(255, 193, 7, 0.1);
    color: var(--color-warning);
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

.alert-success {
    background: rgba(46, 213, 115, 0.1);
    border: 1px solid rgba(46, 213, 115, 0.2);
    color: var(--color-success);
}

.alert-error {
    background: rgba(233, 69, 96, 0.1);
    border: 1px solid rgba(233, 69, 96, 0.3);
    color: var(--accent);
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: rgba(255, 255, 255, 0.3);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state p { margin-bottom: 20px; }

/* ===== Media Grid ===== */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    padding: 20px;
}

.media-item {
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-input);
    position: relative;
    aspect-ratio: 1;
}

.media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 10px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    word-break: break-all;
}

.media-delete-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0;
    margin-top: 4px;
    font-family: var(--font);
}

/* Upload area */
.upload-form {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.upload-form .form-group {
    flex: 1;
    margin-bottom: 0;
    min-width: 200px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .login-page { flex-direction: column; }
    .brand-section { flex: 0 0 35vh; }
    .brand-name { font-size: 3rem; }
    .login-section { flex: 1; }

    .sidebar { width: 60px; }
    .sidebar-brand h1 span { display: none; }
    .sidebar-nav a span:not(.icon) { display: none; }
    .sidebar-footer span { display: none; }
    .main-content { margin-left: 60px; padding: 20px; }
    .form-row { grid-template-columns: 1fr; }
}

/* ===== Story Reader ===== */
.story-reader {
    max-width: 800px;
}

.story-body {
    font-size: 1.05rem;
    line-height: 1.9;
    color: rgba(255, 255, 255, 0.85);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    padding: 16px 0;
    gap: 16px;
}

.pagination-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-select {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: var(--font);
    outline: none;
    cursor: pointer;
    max-width: 280px;
}

.pagination-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ===== Episode count badge ===== */
.episode-count {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(86, 123, 255, 0.1);
    color: var(--accent-blue);
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
}

/* ===== Cover Image Preview ===== */
.cover-preview {
    margin-bottom: 12px;
    display: flex;
    align-items: flex-end;
    gap: 16px;
}

.cover-preview img {
    width: 160px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.cover-remove {
    font-size: 0.82rem;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}

.cover-remove input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
}

/* ===== Editor Toolbar ===== */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-bottom: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.editor-toolbar + textarea {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.toolbar-btn {
    padding: 6px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.toolbar-btn:hover {
    background: var(--border);
    border-color: var(--text-muted);
}

.toolbar-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

.upload-status {
    font-size: 0.82rem;
    font-weight: 500;
}

.upload-status.uploading { color: var(--color-warning); }
.upload-status.success { color: var(--color-success); }
.upload-status.error { color: var(--accent); }

/* ===== Inline Story Images ===== */
.story-inline-img {
    margin: 20px 0;
    text-align: center;
}

.story-inline-img img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

/* ===== Utility Classes ===== */
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-primary-color { color: var(--text-primary); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.8rem; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mb-24 { margin-bottom: 24px; }
.d-inline { display: inline; }
.d-hidden { display: none; }

/* Page subtitle under headers */
.page-subtitle {
    color: var(--text-muted);
    margin-top: 4px;
    font-size: 0.9rem;
}

/* Breadcrumb-style back link */
.breadcrumb-link {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.breadcrumb-link:hover {
    color: var(--text-secondary);
}

/* Episode part number cell */
.cell-part-number {
    font-weight: 800;
    color: var(--accent);
    width: 50px;
}

/* Login button full width */
.btn-login-full {
    width: 100%;
    padding: 14px;
}

/* Textarea short (for description) */
.textarea-short {
    min-height: 120px;
}

/* Label hint text */
.label-hint {
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}

/* Editor footer row */
.editor-footer {
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

/* Disabled/end state button */
.btn-disabled {
    opacity: 0.3;
    cursor: default;
}

/* Delete inline form */
.inline-form {
    display: inline;
}
