/* ====== CAFE TRUYỆN - CSS CHÍNH ====== */

/* === RESET & BASE === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --purple: #8B5CF6;
    --purple-light: #a78bfa;
    --purple-dark: #7c3aed;
    --emerald: #10B981;
    --rose: #f43f5e;
    --amber: #f59e0b;
    --border: rgba(255, 255, 255, 0.08);
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--purple-light);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--purple);
}

img {
    max-width: 100%;
    height: auto;
}

/* === SCROLLBAR === */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--purple);
}

/* === HEADER / NAVBAR === */
.navbar {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    font-size: 1.4rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--purple), var(--emerald));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.navbar-brand span {
    font-size: 1.5rem;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
}

.navbar-nav a {
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.navbar-nav a:hover,
.navbar-nav a.active {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.navbar-nav .btn-login {
    background: var(--purple);
    color: white;
    padding: 8px 20px;
    border-radius: 8px;
}

.navbar-nav .btn-login:hover {
    background: var(--purple-dark);
}

/* Mobile menu */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

/* === CONTAINER === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* === HERO SECTION === */
.hero {
    text-align: center;
    padding: 60px 24px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(16, 185, 129, 0.05));
    border-bottom: 1px solid var(--border);
}

.hero-icon {
    width: 80px;
    height: 80px;
    background: rgba(139, 92, 246, 0.15);
    border: 2px solid rgba(139, 92, 246, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    font-size: 2.5rem;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--purple-light), var(--emerald));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 12px;
}

.hero p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    max-width: 600px;
    margin: 0 auto;
}

/* === STORY GRID === */
.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.section-title h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

.section-title a {
    font-size: 0.9rem;
    color: var(--purple-light);
}

.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 24px;
    margin-bottom: 48px;
}

.story-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: all 0.3s;
    cursor: pointer;
}

.story-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--purple);
}

.story-card-cover {
    aspect-ratio: 3/4;
    background: var(--bg-hover);
    position: relative;
    overflow: hidden;
}

.story-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-card-cover .play-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.story-card:hover .play-overlay {
    opacity: 1;
}

.play-overlay .play-btn {
    width: 48px;
    height: 48px;
    background: var(--purple);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}

.story-card-body {
    padding: 12px;
}

.story-card-body h3 {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

.story-card-body .meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--purple);
    color: white;
}

.btn-primary:hover {
    background: var(--purple-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
}

.btn-danger {
    background: var(--rose);
    color: white;
}

.btn-danger:hover {
    background: #e11d48;
}

.btn-success {
    background: var(--emerald);
    color: white;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
}

/* === FORMS === */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-control:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

/* === AUTH PAGES === */
.auth-container {
    min-height: calc(100vh - 64px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-box h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1.5rem;
}

.auth-box .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.auth-box .btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
}

/* === ALERT / MESSAGE === */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--rose);
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--emerald);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--amber);
}

/* === AUDIO PLAYER BAR (FIXED BOTTOM) === */
.player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(24px);
    border-top: 1px solid var(--border);
    padding: 12px 24px;
    z-index: 200;
    display: none;
    /* Ẩn khi chưa phát */
}

.player-bar.active {
    display: block;
}

.player-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.player-info {
    flex: 0 0 200px;
    overflow: hidden;
}

.player-info h4 {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-info p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.player-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.player-buttons {
    display: flex;
    align-items: center;
    gap: 16px;
}

.player-buttons button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.player-buttons button:hover {
    color: var(--text-primary);
}

.player-buttons .btn-play-main {
    width: 44px;
    height: 44px;
    background: white;
    color: var(--bg-primary);
    border-radius: 50%;
    font-size: 1.3rem;
}

.player-buttons .btn-play-main:hover {
    transform: scale(1.05);
}

.player-progress {
    width: 100%;
    max-width: 500px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-progress span {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 40px;
    text-align: center;
}

.progress-bar {
    flex: 1;
    height: 4px;
    background: var(--bg-hover);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
}

.progress-bar:hover {
    height: 6px;
}

.progress-bar .progress-fill {
    height: 100%;
    background: var(--purple);
    border-radius: 4px;
    width: 0%;
    position: relative;
}

.progress-bar .progress-fill::after {
    content: '';
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s;
}

.progress-bar:hover .progress-fill::after {
    opacity: 1;
}

.player-options {
    flex: 0 0 200px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.speed-control {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.speed-control select {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}

.speed-control select option {
    background: var(--bg-secondary);
}

.btn-bgmusic {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-bgmusic.active {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.4);
    color: var(--purple-light);
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
}

.volume-slider {
    width: 70px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-hover);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
}

/* === STORY DETAIL PAGE === */
.story-detail {
    display: flex;
    gap: 32px;
    margin-bottom: 32px;
}

.story-detail-cover {
    flex: 0 0 240px;
}

.story-detail-cover img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    border-radius: var(--radius);
}

.story-detail-info {
    flex: 1;
}

.story-detail-info h1 {
    font-size: 2rem;
    margin-bottom: 8px;
}

.story-detail-info .author {
    color: var(--text-muted);
    margin-bottom: 16px;
}

.story-detail-info .description {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.8;
}

.story-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}

/* Chapter list */
.chapter-list {
    margin-top: 32px;
}

.chapter-list h2 {
    margin-bottom: 16px;
}

.chapter-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.chapter-item:hover {
    border-color: var(--purple);
    background: var(--bg-hover);
}

.chapter-item.playing {
    border-color: var(--purple);
    background: rgba(139, 92, 246, 0.1);
}

.chapter-item .ch-number {
    width: 36px;
    height: 36px;
    background: var(--bg-hover);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.chapter-item.playing .ch-number {
    background: var(--purple);
    color: white;
}

.chapter-item .ch-title {
    flex: 1;
    font-size: 0.95rem;
}

.chapter-item .ch-duration {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.chapter-item .ch-resume {
    font-size: 0.75rem;
    color: var(--emerald);
}

/* === ADMIN === */
.admin-layout {
    display: flex;
    min-height: calc(100vh - 64px);
}

.admin-sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 24px 0;
    flex-shrink: 0;
}

.admin-sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.admin-sidebar a:hover,
.admin-sidebar a.active {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-right: 3px solid var(--purple);
}

.admin-content {
    flex: 1;
    padding: 24px;
}

.admin-content h1 {
    margin-bottom: 24px;
}

/* Data table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 12px;
    background: var(--bg-hover);
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.data-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Badge */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--emerald);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--amber);
}

.badge-danger {
    background: rgba(244, 63, 94, 0.15);
    color: var(--rose);
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal h2 {
    margin-bottom: 24px;
}

/* === FAVORITES === */
.favorite-btn {
    background: none;
    border: 2px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
}

.favorite-btn:hover {
    border-color: var(--rose);
    color: var(--rose);
}

.favorite-btn.active {
    background: rgba(244, 63, 94, 0.15);
    border-color: var(--rose);
    color: var(--rose);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .navbar-nav {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        padding: 16px;
    }

    .navbar-nav.open {
        display: flex;
    }

    .menu-toggle {
        display: block;
    }

    .hero h1 {
        font-size: 1.8rem;
    }

    .story-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 16px;
    }

    .story-detail {
        flex-direction: column;
    }

    .story-detail-cover {
        flex: none;
        max-width: 200px;
        margin: 0 auto;
    }

    .player-inner {
        flex-wrap: wrap;
    }

    .player-info {
        flex: 1;
        min-width: 0;
    }

    .player-options {
        flex: 1 0 100%;
        justify-content: center;
    }

    .admin-sidebar {
        display: none;
    }

    .container {
        padding: 16px;
    }
}

/* === BODY PADDING for player bar === */
body.has-player {
    padding-bottom: 100px;
}

/* === EMPTY STATE === */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-state p {
    margin-top: 8px;
}