/* ============================================================
   Badminton App — Sports Theme
   Mobile-first, responsive, Bootstrap 5 compatible
   ============================================================ */

/* ── CSS Variables ── */
:root {
    --primary:        #1a6b3a;   /* xanh lá sân cầu */
    --primary-dark:   #124d2a;
    --primary-light:  #e8f5ee;
    --accent:         #f5a623;   /* vàng lông cầu */
    --accent-dark:    #d4891a;
    --danger:         #dc3545;
    --surface:        #ffffff;
    --surface-2:      #f8f9fa;
    --border:         #dee2e6;
    --text:           #212529;
    --text-muted:     #6c757d;
    --sidebar-width:  260px;
    --sidebar-collapsed-width: 72px;
    --topbar-height:  60px;
    --bottom-nav-h:   64px;
    --radius:         10px;
    --shadow:         0 2px 12px rgba(0,0,0,.08);
    --shadow-lg:      0 8px 32px rgba(0,0,0,.12);
    --transition:     all .2s ease;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--surface-2);
    overflow-x: hidden;
}

/* Force the Vietnamese-safe font everywhere (fixes broken bold Vietnamese glyphs) */
body, button, input, select, textarea,
h1, h2, h3, h4, h5, h6, strong, b, .fw-bold, .fw-semibold {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ================================================================
   LAYOUT
   ================================================================ */

/* Topbar */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: .75rem;
    z-index: 1030;
    box-shadow: var(--shadow);
}
.topbar-brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: .5rem;
    flex: 1;
}
.topbar-brand .brand-icon { font-size: 1.4rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.topbar-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,.85);
    font-size: 1.25rem;
    cursor: pointer;
    padding: .25rem .5rem;
    border-radius: 6px;
    transition: var(--transition);
}
.topbar-btn:hover { background: rgba(255,255,255,.15); color: #fff; }

/* Sidebar */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1020;
    transition: transform .3s ease, width .3s ease;
    overflow-y: auto;
}
.sidebar-hidden { transform: translateX(-100%); }

/* Main content area */
.main-content {
    margin-top: var(--topbar-height);
    padding: 1.5rem;
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left .3s ease;
}

/* Desktop: sidebar always open */
@media (min-width: 992px) {
    .main-content { margin-left: var(--sidebar-width); }
    .sidebar { transform: none !important; }
    .sidebar-overlay { display: none !important; }
    .topbar-menu-btn { display: none; }

    /* Collapsed (icon-only) state */
    .sidebar.collapsed { width: var(--sidebar-collapsed-width); }
    .main-content.collapsed { margin-left: var(--sidebar-collapsed-width); }

    .sidebar.collapsed .nav-label,
    .sidebar.collapsed .nav-section-title,
    .sidebar.collapsed .text-small,
    .sidebar.collapsed .btn-full span,
    .sidebar.collapsed .authorize-user-info { display: none; }

    .sidebar.collapsed .nav-link-item {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
        gap: 0;
    }
    .sidebar.collapsed .nav-icon { width: 100%; }
}
.topbar-collapse-btn { display: none; }
@media (min-width: 992px) {
    .topbar-collapse-btn { display: inline-flex; }
}

/* Mobile: bottom nav */
@media (max-width: 991px) {
    .main-content {
        padding: 1rem;
        padding-bottom: calc(var(--bottom-nav-h) + 1rem);
    }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1015;
}
.sidebar-overlay.show { display: block; }

/* Nav links inside sidebar */
.nav-section-title {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    padding: 1rem 1.25rem .35rem;
}
.nav-link-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1.25rem;
    color: var(--text);
    border-radius: 0;
    transition: var(--transition);
    font-size: .92rem;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}
.nav-link-item:hover  { background: var(--primary-light); color: var(--primary); }
.nav-link-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; border-right: 3px solid var(--primary); }
.nav-link-item .nav-icon { font-size: 1.1rem; width: 1.4rem; text-align: center; }

/* Bottom navigation (mobile only) */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 1020;
    box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
@media (max-width: 991px) { .bottom-nav { display: flex; } }
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    font-size: .65rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    padding: .5rem 0;
    transition: var(--transition);
}
.bottom-nav-item .bn-icon { font-size: 1.3rem; line-height: 1; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item:hover  { color: var(--primary); }

/* ================================================================
   CARDS & SURFACES
   ================================================================ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}
.card-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: .5rem;
}
.card-body { padding: 1.25rem; }

/* Stat cards on dashboard */
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}
.stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}
.stat-icon.green  { background: #e8f5ee; color: var(--primary); }
.stat-icon.yellow { background: #fff8e1; color: var(--accent-dark); }
.stat-icon.blue   { background: #e3f2fd; color: #1976d2; }
.stat-icon.red    { background: #fdecea; color: var(--danger); }
.stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1; color: var(--text); }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ================================================================
   MATCH / PAIRING CARDS
   ================================================================ */
.match-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: var(--transition);
    flex-shrink: 0;
}
.match-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.match-card-header {
    background: var(--primary);
    color: #fff;
    padding: .5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .82rem;
    font-weight: 600;
}
.match-badge-court {
    background: var(--accent);
    color: #fff;
    padding: .15rem .55rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: .78rem;
}
.match-vs {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .75rem;
    padding: 1rem;
}
.match-side { text-align: center; display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; justify-content: center; min-width: 0; }
.vs-divider {
    font-weight: 900;
    font-size: 1.1rem;
    color: var(--text-muted);
    padding: .25rem .5rem;
    background: var(--surface-2);
    border-radius: 6px;
}

/* Player avatar row */
.player-chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: .25rem .65rem .25rem .35rem;
    font-size: .82rem;
    font-weight: 500;
    margin: 2px;
}
.player-chip .avatar-xs {
    width: 24px; height: 24px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--primary-light);
    display: flex; align-items: center; justify-content: center;
    font-size: .7rem;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
    overflow: hidden;
}

/* ================================================================
   SKILL BADGES
   ================================================================ */
.badge-skill {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .02em;
}
.badge-newbee { background: #e9ecef; color: #495057; }
.badge-weak   { background: #d1ecf1; color: #0c5460; }
.badge-medium { background: #fff3cd; color: #856404; }
.badge-good   { background: #d4edda; color: #155724; }

/* ================================================================
   FORMS
   ================================================================ */
.form-label { font-weight: 600; font-size: .88rem; margin-bottom: .35rem; color: var(--text); }
.form-control, .form-select {
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: .55rem .85rem;
    font-size: .92rem;
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,107,58,.15);
    outline: none;
}

/* ================================================================
   BUTTONS
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1.1rem;
    border-radius: 8px;
    font-size: .88rem;
    font-weight: 600;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent    { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-dark); }
.btn-outline   { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.9); }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-lg { padding: .7rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: .4rem; border-radius: 8px; }
.btn-full { width: 100%; justify-content: center; }

/* ================================================================
   TABLE
   ================================================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th {
    background: var(--surface-2);
    padding: .75rem 1rem;
    text-align: left;
    font-weight: 700;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--primary-light); }

/* ================================================================
   AVATAR
   ================================================================ */
.avatar {
    border-radius: 50%;
    object-fit: cover;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    text-transform: uppercase;
}
.avatar-sm { width: 32px; height: 32px; font-size: .85rem; }
.avatar-md { width: 42px; height: 42px; font-size: 1rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.4rem; }

/* ================================================================
   ALERTS / TOASTS
   ================================================================ */
.alert {
    padding: .85rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: .9rem;
    display: flex;
    align-items: flex-start;
    gap: .6rem;
}
.alert-success { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.alert-danger  { background: #fdecea; color: #721c24; border-color: #f5c6cb; }
.alert-info    { background: #d1ecf1; color: #0c5460; border-color: #bee5eb; }
.alert-warning { background: #fff3cd; color: #856404; border-color: #ffeeba; }

/* Toast notification */
.toast-container {
    position: fixed;
    top: calc(var(--topbar-height) + 1rem);
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    max-width: 340px;
}
.toast {
    padding: .85rem 1.1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: .88rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: .6rem;
    animation: slideIn .25s ease;
    color: #fff;
}
.toast.success { background: var(--primary); }
.toast.error   { background: var(--danger); }
.toast.info    { background: #1976d2; }
@keyframes slideIn {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0);   opacity: 1; }
}

/* ================================================================
   MODAL
   ================================================================ */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1050;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    animation: fadeIn .2s ease;
}
.modal-box {
    background: var(--surface);
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: scaleIn .2s ease;
}
.modal-header {
    padding: 1.1rem 1.4rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 700; font-size: 1rem;
}
.modal-body    { padding: 1.4rem; }
.modal-footer  { padding: 1rem 1.4rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ================================================================
   EMPTY STATE
   ================================================================ */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3.5rem; margin-bottom: 1rem; opacity: .35; }
.empty-state h5 { font-weight: 700; color: var(--text); margin-bottom: .35rem; }
.empty-state p  { font-size: .9rem; max-width: 320px; margin: 0 auto .75rem; }

/* ================================================================
   LOADING SPINNER
   ================================================================ */
.spinner {
    display: inline-block;
    width: 1.2rem; height: 1.2rem;
    border: 2.5px solid rgba(26,107,58,.25);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
.spinner-lg { width: 2.5rem; height: 2.5rem; border-width: 3.5px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 3rem; gap: 1rem; color: var(--text-muted);
}

/* ================================================================
   RESPONSIVE GRID
   ================================================================ */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) {
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) { .grid-4 { grid-template-columns: 1fr; } }

/* ================================================================
   PAGE HEADER
   ================================================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1.5rem;
}
.page-title {
    font-size: 1.35rem;
    font-weight: 800;
    margin: 0;
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--text);
}
.page-subtitle { font-size: .85rem; color: var(--text-muted); margin: .1rem 0 0; }

/* ================================================================
   LOGIN PAGE
   ================================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, #2e8b57 100%);
    padding: 1rem;
}
.login-card {
    background: var(--surface);
    border-radius: 18px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.login-logo {
    text-align: center;
    margin-bottom: 1.75rem;
}
.login-logo .logo-icon { font-size: 3rem; }
.login-logo h1 { font-size: 1.4rem; font-weight: 800; color: var(--primary); margin: .4rem 0 .2rem; }
.login-logo p  { color: var(--text-muted); font-size: .85rem; margin: 0; }

/* ================================================================
   MISC UTILITIES
   ================================================================ */
.gap-1 { gap: .25rem; } .gap-2 { gap: .5rem; } .gap-3 { gap: .75rem; }
.flex   { display: flex; } .flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.w-full { width: 100%; } .text-center { text-align: center; }
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; } .mt-3 { margin-top: 1rem; }
.mb-3 { margin-bottom: 1rem; } .mb-4 { margin-bottom: 1.5rem; }
.text-muted { color: var(--text-muted); } .text-small { font-size: .82rem; }
.fw-bold { font-weight: 700; } .fw-600 { font-weight: 600; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.rounded { border-radius: var(--radius); }
.overflow-hidden { overflow: hidden; }
.d-none { display: none; }

/* ===== Tiêu đề khối xuất PDF/PNG ===== */
.export-header {
    text-align: center;
    padding: 0 0 1rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}
.export-title { margin: 0 0 .5rem; font-size: 1.4rem; font-weight: 700; }
.export-meta {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: .9rem;
    color: var(--text-muted);
}

/* ===== In lịch thi đấu (Xuất PDF qua trình duyệt) ===== */
@media print {
    body.printing-schedule * { visibility: hidden !important; }
    body.printing-schedule .print-target,
    body.printing-schedule .print-target * { visibility: visible !important; }
    body.printing-schedule .print-target {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        padding: 1rem;
    }
    /* Ẩn các nút thao tác khi in */
    body.printing-schedule .no-print { display: none !important; }
    /* Tránh cắt ngang thẻ trận đấu giữa 2 trang */
    body.printing-schedule .card,
    body.printing-schedule .match-card { break-inside: avoid; page-break-inside: avoid; }
}
