/* ========================================================
   Badminton Manager – global stylesheet
   CSS variables → layout → components → utilities → media
   ======================================================== */

/* ── 0. Variables ────────────────────────────────────────── */
:root {
    /* Brand */
    --bm-primary:        #0f766e;
    --bm-primary-dark:   #0c5f58;
    --bm-primary-light:  #e6f7f5;
    --bm-accent:         #2563eb;

    /* Neutrals */
    --bm-bg:             #f1f5f9;
    --bm-surface:        #ffffff;
    --bm-border:         #e2e8f0;
    --bm-border-strong:  #cbd5e1;

    /* Text */
    --bm-text:           #0f172a;
    --bm-text-muted:     #64748b;
    --bm-text-light:     #94a3b8;

    /* Shadows */
    --bm-shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
    --bm-shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --bm-shadow:    0 4px 6px -1px rgba(15, 23, 42, .08), 0 2px 4px -2px rgba(15, 23, 42, .05);

    /* Layout */
    --bm-sidebar-width:  256px;
    --bm-topbar-height:  64px;
    --bm-radius:         10px;
    --bm-radius-sm:       6px;
    --bm-radius-xs:       4px;

    /* Transitions */
    --bm-ease: 150ms ease;
}

/* ── 1. Base reset ───────────────────────────────────────── */
html, body { min-height: 100%; }

body {
    background: var(--bm-bg);
    color: var(--bm-text);
    font-size: .9375rem;
}

a { text-decoration: none; }

/* ── 2. Auth page ────────────────────────────────────────── */
.bm-auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(ellipse at 20% 25%, rgba(15, 118, 110, .13) 0%, transparent 55%),
        radial-gradient(ellipse at 80% 75%, rgba(37, 99, 235, .08) 0%, transparent 55%),
        var(--bm-bg);
}

.bm-auth-card { width: min(420px, 100%); }

/* ── 3. App shell ────────────────────────────────────────── */
.bm-shell { min-height: 100vh; }

/* ── 4. Sidebar ──────────────────────────────────────────── */
.bm-sidebar {
    width: var(--bm-sidebar-width);
    background: var(--bm-primary-dark);
    color: #fff;
}

.bm-sidebar .offcanvas-body { overflow-y: auto; }

/* Brand / logo row */
.bm-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: .9375rem;
    font-weight: 700;
    letter-spacing: -.01em;
}

.bm-brand:hover { color: rgba(255, 255, 255, .9); }

.bm-brand-mark {
    width: 34px;
    height: 34px;
    border-radius: var(--bm-radius-sm);
    display: inline-grid;
    place-items: center;
    background: rgba(255, 255, 255, .18);
    font-size: 1rem;
    flex-shrink: 0;
}

/* Nav section label */
.bm-nav-label {
    padding: 14px 12px 5px;
    color: rgba(255, 255, 255, .38);
    font-size: .67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
}

/* Nav links */
.bm-sidebar .nav-link {
    position: relative;
    color: rgba(255, 255, 255, .7);
    border-radius: var(--bm-radius-sm);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px 9px 15px;
    font-size: .875rem;
    transition: color var(--bm-ease), background var(--bm-ease);
    overflow: hidden;
}

/* Active left-bar indicator */
.bm-sidebar .nav-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: rgba(255, 255, 255, .85);
    border-radius: 0 3px 3px 0;
    transition: height var(--bm-ease);
}

.bm-sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, .1);
}

.bm-sidebar .nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, .16);
    font-weight: 600;
}

.bm-sidebar .nav-link.active::before { height: 55%; }

/* Sidebar footer */
.bm-sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, .1);
}

/* User avatar */
.bm-user-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, .16);
    font-size: .85rem;
}

.bm-user-avatar-light {
    color: var(--bm-primary-dark);
    background: var(--bm-primary-light);
}

/* ── 5. Main area ────────────────────────────────────────── */
.bm-main { min-height: 100vh; }

.min-w-0 { min-width: 0; }

/* ── 6. Top bar ──────────────────────────────────────────── */
.bm-topbar {
    height: var(--bm-topbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    background: var(--bm-surface);
    border-bottom: 1px solid var(--bm-border);
    box-shadow: var(--bm-shadow-xs);
    position: sticky;
    top: 0;
    z-index: 100;
}

.bm-topbar-title {
    font-weight: 700;
    font-size: .9375rem;
    line-height: 1.15;
}

.bm-topbar-subtitle,
.text-muted-2 { color: var(--bm-text-muted); }

/* Breadcrumb */
.bm-breadcrumb {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    margin-top: 2px;
    color: var(--bm-text-muted);
    font-size: .75rem;
    white-space: nowrap;
}

.bm-breadcrumb a {
    color: var(--bm-text-muted);
    transition: color var(--bm-ease);
}

.bm-breadcrumb a:hover { color: var(--bm-primary); }

.bm-breadcrumb .bi { font-size: .55rem; }

/* Icon & account buttons */
.bm-icon-button {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: var(--bm-radius-sm);
}

.bm-account-button {
    max-width: 220px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-radius: var(--bm-radius-sm);
}

.bm-account-button::after { margin-left: 2px; }

/* ── 7. Content area ─────────────────────────────────────── */
.bm-content { padding: 24px; }

/* ── 8. Page header ──────────────────────────────────────── */
.bm-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.bm-page-title {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.2;
    margin: 0;
}

/* ── 9. Cards ────────────────────────────────────────────── */
.bm-card {
    border: 1px solid var(--bm-border);
    border-radius: var(--bm-radius);
    box-shadow: var(--bm-shadow-xs);
}

/* Metric / summary card */
.bm-metric { min-height: 104px; }

.bm-metric .metric-label {
    color: var(--bm-text-muted);
    font-size: .8rem;
    font-weight: 500;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.bm-metric .metric-value {
    font-size: 1.625rem;
    font-weight: 750;
    letter-spacing: -.02em;
    line-height: 1.1;
}

/* Metric icon pill */
.bm-metric-icon {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: var(--bm-radius);
    font-size: 1.15rem;
    align-self: center;
}

.bm-metric-icon.text-primary { background: #eff6ff; }
.bm-metric-icon.text-success  { background: #f0fdf4; }
.bm-metric-icon.text-warning  { background: #fefce8; }
.bm-metric-icon.text-danger   { background: #fef2f2; }
.bm-metric-icon.text-info     { background: #f0f9ff; }

/* ── 10. Mobile bottom nav ───────────────────────────────── */
.bm-mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1020;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-height: 60px;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bm-surface);
    border-top: 1px solid var(--bm-border);
    box-shadow: 0 -2px 8px rgba(15, 23, 42, .06);
}

.bm-mobile-nav-link {
    min-width: 0;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px;
    border: 0;
    color: var(--bm-text-muted);
    background: transparent;
    font-size: .65rem;
    font-weight: 500;
    transition: color var(--bm-ease);
}

.bm-mobile-nav-link .bi { font-size: 1.2rem; }

.bm-mobile-nav-link:hover,
.bm-mobile-nav-link.active { color: var(--bm-primary); }

/* ── 11. Tables ──────────────────────────────────────────── */
.table > :not(caption) > * > * { vertical-align: middle; }

.table thead th {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--bm-text-muted);
}

/* ── 12. Action buttons ──────────────────────────────────── */
.bm-actions {
    display: inline-flex;
    gap: 5px;
    justify-content: flex-end;
    white-space: nowrap;
}

/* ── 13. Form grid ───────────────────────────────────────── */
.bm-form-grid { display: grid; gap: 16px; }

/* ── 14. Profit / status colours ────────────────────────── */
.profit-pos { color: #16a34a; font-weight: 600; }
.profit-neg { color: #dc2626; font-weight: 600; }

.player-row.checked { background: #f0fdf4; }

/* ── 15. Summary / detail card ───────────────────────────── */
.summary-card .label { color: var(--bm-text-muted); }

/* ── 16. Status badges ───────────────────────────────────── */
.badge-soft {
    color: var(--bm-text);
    background: var(--bm-border);
}

.badge-soft-success {
    color: #166534;
    background: #dcfce7;
}

.badge-soft-warning {
    color: #854d0e;
    background: #fef3c7;
}

.badge-soft-danger {
    color: #991b1b;
    background: #fee2e2;
}

/* ── 17. Companion (bạn được dẫn) ───────────────────────── */
.bm-companion-row {
    background: #fafbfc;
}

.bm-companion-row td {
    border-top: none !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
}

.bm-companion-name {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.bm-companion-arrow {
    color: var(--bm-text-light);
    font-size: .85rem;
    flex-shrink: 0;
}

/* ── 18. Empty state ─────────────────────────────────────── */
.bm-empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    border-radius: 14px;
    background: var(--bm-border);
    color: var(--bm-text-light);
    font-size: 1.5rem;
}

/* ── 18. Desktop fixed sidebar ───────────────────────────── */
@media (min-width: 992px) {
    .bm-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        transform: none !important;
        visibility: visible !important;
    }

    .bm-main { margin-left: var(--bm-sidebar-width); }

    .bm-sidebar .offcanvas-header { min-height: var(--bm-topbar-height); }
}

/* ── 19. Tablet ──────────────────────────────────────────── */
@media (max-width: 767.98px) {
    .bm-topbar { padding: 0 14px; }

    .bm-content {
        padding: 16px 14px calc(72px + env(safe-area-inset-bottom));
    }

    .bm-page-header { flex-direction: column; }
}

/* ── 20. Phone ───────────────────────────────────────────── */
@media (max-width: 575.98px) {
    .bm-topbar {
        height: 60px;
        gap: 8px;
    }

    .bm-account-button {
        width: 38px;
        height: 38px;
        padding: 0;
        justify-content: center;
    }

    .bm-account-button::after { display: none; }

    .bm-breadcrumb { max-width: calc(100vw - 110px); }
}

/* ── 21. Activity log panel ──────────────────────────────── */
.bm-activity-log {
    max-height: 340px;
    overflow-y: auto;
    padding: 4px 0;
}

.bm-activity-entry {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 8px 14px;
    border-bottom: 1px solid var(--bm-border);
    transition: background .15s;
}

.bm-activity-entry:last-child { border-bottom: none; }
.bm-activity-entry:hover { background: #f8fafc; }

.bm-activity-entry__icon {
    flex-shrink: 0;
    font-size: .95rem;
    margin-top: 2px;
    width: 18px;
    text-align: center;
}

.bm-activity-entry__body { flex: 1; min-width: 0; }

.bm-activity-entry__text {
    font-size: .83rem;
    line-height: 1.4;
    flex-wrap: wrap;
    gap: 3px;
}

.bm-activity-entry__actor {
    font-weight: 600;
    color: #1f2937;
}

.bm-activity-entry__action {
    color: #6b7280;
    margin: 0 2px;
}

.bm-activity-entry__player {
    font-weight: 500;
    color: #374151;
}

.bm-activity-entry__detail {
    font-size: .77rem;
    color: #9ca3af;
    margin-top: 1px;
}

.bm-activity-entry__time {
    font-size: .73rem;
    color: #9ca3af;
    margin-top: 2px;
}

/* ── 22. Toast notification ──────────────────────────────── */
.bm-toast {
    min-width: 300px;
    max-width: 420px;
    border: none;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.14), 0 2px 6px rgba(0,0,0,.08);
    overflow: hidden;
    padding: 0;
    background: #fff;
}

.bm-toast__bar {
    height: 3px;
    width: 100%;
}

.bm-toast--success .bm-toast__bar  { background: #16a34a; }
.bm-toast--error   .bm-toast__bar  { background: #dc2626; }
.bm-toast--warning .bm-toast__bar  { background: #d97706; }
.bm-toast--info    .bm-toast__bar  { background: #2563eb; }

.bm-toast__body {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
}

.bm-toast__icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.bm-toast--success .bm-toast__icon { color: #16a34a; }
.bm-toast--error   .bm-toast__icon { color: #dc2626; }
.bm-toast--warning .bm-toast__icon { color: #d97706; }
.bm-toast--info    .bm-toast__icon { color: #2563eb; }

.bm-toast__content {
    flex: 1;
    min-width: 0;
}

.bm-toast__title {
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #374151;
    line-height: 1.3;
}

.bm-toast__message {
    font-size: .875rem;
    color: #4b5563;
    margin-top: 2px;
    line-height: 1.45;
    word-break: break-word;
}

.bm-toast__close {
    flex-shrink: 0;
    margin-top: 1px;
    opacity: .45;
}

.bm-toast__close:hover { opacity: .75; }

@media (max-width: 575.98px) {
    #bm-toast-container {
        left: 12px !important;
        right: 12px !important;
        bottom: 80px !important; /* trên mobile nav */
    }
    .bm-toast { min-width: 0; max-width: 100%; }
}

/* ── Court image upload ──────────────────────────────────── */
.bm-img-slot {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.bm-img-slot-label {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #64748b;
    margin-bottom: 8px;
}

.bm-img-preview {
    min-height: 120px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
}

.bm-img-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 7px 14px;
    border: 1.5px dashed #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    color: #64748b;
    font-size: .83rem;
    cursor: pointer;
    transition: border-color .15s, background .15s, color .15s;
    user-select: none;
}

.bm-img-upload-btn:hover {
    border-color: var(--bm-primary);
    background: #f0fdfa;
    color: var(--bm-primary);
}

.bm-img-thumb {
    position: relative;
    width: 90px;
    height: 90px;
    border-radius: 8px;
    overflow: hidden;
    border: 1.5px solid #e2e8f0;
    background: #f1f5f9;
    flex-shrink: 0;
}

.bm-img-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.bm-img-thumb button {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,.55);
    color: #fff;
    font-size: .65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s;
    padding: 0;
}

.bm-img-thumb:hover button { opacity: 1; }
