/* App layout styles shared by every signed-in page (sidebar, header, cards,
   tables, forms, dark mode). Moved out of templates/base.html so browsers
   download it once and keep it, instead of receiving ~50 KB of CSS inside
   every page. The brand colour variables stay inline in base.html (they come
   from SystemSettings), and this file is linked straight after them, so the
   cascade order is unchanged. */

[data-bs-theme="dark"] {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    /* Form fields. Sign-in, sign-up and other pages style inputs with
       var(--input-bg, #f8fafc) etc.; without dark values here those fields
       stayed near-white in dark mode while the typed text turned light, so
       nothing could be read. */
    --input-bg: #0f172a;
    --input-border: #334155;
    --bg-hover: #334155;
    --text-tertiary: #94a3b8;
    /* Brand text on a dark page needs lifting to stay readable. */
    --bs-link-color: color-mix(in srgb, var(--primary-color) 55%, #fff);
    --bs-link-hover-color: color-mix(in srgb, var(--primary-color) 35%, #fff);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* Prevent text size adjustment on orientation change */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    /* Prevent pull-to-refresh on mobile when not needed */
    overscroll-behavior-y: contain;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    z-index: 1050;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    padding-top: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    background: var(--card-bg);
    z-index: 10;
}

/* Mode accent bar at top of sidebar */
.sidebar-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #10b981, #059669);
    transition: background 0.3s ease;
}

/* Club mode - purple/indigo accent */
.sidebar-header.club-mode::before {
    background: linear-gradient(90deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
}

/* Mode badge styles */
.mode-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.25rem;
}

.mode-badge.home-mode {
    background: rgba(16, 185, 129, 0.15);
    color: #059669;
}

.mode-badge.club-mode {
    background: color-mix(in srgb, var(--sx-brand) 12%, transparent);
    color: var(--primary-color);
}

.mode-badge i {
    font-size: 0.65rem;
}

[data-bs-theme="dark"] .mode-badge.home-mode {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

[data-bs-theme="dark"] .mode-badge.club-mode {
    background: color-mix(in srgb, var(--sx-brand) 20%, transparent);
    color: #a5b4fc;
}

.sidebar-header-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    margin: -0.5rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    /* Minimum touch target size */
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

.sidebar-close:hover,
.sidebar-close:active {
    background: var(--bg-color);
    color: var(--text-primary);
}

.sidebar-logo {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.5rem;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-logo.club-logo {
    background: white;
    padding: 4px;
    border: 1px solid var(--border-color);
}

.sidebar-logo.club-logo img {
    border-radius: 8px;
    object-fit: contain;
}

.sidebar-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar-logo.has-logo {
    background: white;
    padding: 6px;
    border: 1px solid var(--border-color);
}

.sidebar-logo.has-logo img {
    object-fit: contain;
    border-radius: 8px;
}

.sidebar-brand {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.3;
    max-width: 180px;
    word-wrap: break-word;
}

.sidebar-nav {
    padding: 1rem 0;
    padding-bottom: calc(1rem + var(--safe-area-bottom));
}

.nav-section {
    padding: 0.5rem 1.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.nav-item {
    padding: 0 0.75rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
    font-size: 0.9rem;
    /* Ensure minimum touch target */
    min-height: 48px;
}

.nav-link:hover {
    background: var(--bg-color);
    color: var(--primary-color);
}

.nav-link:active {
    transform: scale(0.98);
}

.nav-link.active {
    background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
    color: white;
}

.nav-link i {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

/* Collapsible nav sections */
.nav-section.collapsible {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    border-radius: 6px;
    margin-left: 0.75rem;
    margin-right: 0.75rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    transition: background 0.15s ease;
}

.nav-section.collapsible:hover {
    background: var(--bg-color);
}

.nav-section.collapsible::after {
    content: '\F282';
    font-family: 'bootstrap-icons';
    font-size: 0.65rem;
    transition: transform 0.25s ease;
    opacity: 0.5;
}

.nav-section.collapsible.collapsed::after {
    transform: rotate(-90deg);
}

.nav-section-items {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.25s ease;
    opacity: 1;
}

.nav-section-items.collapsed {
    max-height: 0;
    opacity: 0;
}

.nav-section.mt-4 {
    margin-top: 1.5rem !important;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.nav-link.text-danger {
    color: var(--danger-color) !important;
}

.nav-link.text-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color) !important;
}

/* Help & Tutorials — highlighted nav item */
.nav-link-help {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.10), rgba(139, 92, 246, 0.10));
    color: #4f46e5 !important;
    border: 1px solid rgba(99, 102, 241, 0.20);
    position: relative;
}
.nav-link-help i {
    color: #6366f1;
}
.nav-link-help:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(139, 92, 246, 0.18));
    color: #4338ca !important;
    border-color: rgba(99, 102, 241, 0.35);
}
.nav-link-help.active {
    background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
    color: white !important;
    border-color: transparent;
}
.nav-link-help.active i {
    color: white;
}
.nav-help-badge {
    background: linear-gradient(135deg, #f59e0b, #f97316);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 4px;
}
.nav-link-help.active .nav-help-badge {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* Context Switcher */
.context-switcher-wrapper {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    background: color-mix(in srgb, var(--sx-brand) 5%, transparent);
}

.context-switcher {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--sx-brand) 25%, transparent);
}

.context-switcher:hover {
    background: linear-gradient(135deg, var(--sx-brand-deep, #3730a3), color-mix(in srgb, var(--sx-brand-deep, #3730a3) 82%, #000));
    box-shadow: 0 4px 12px color-mix(in srgb, var(--sx-brand) 35%, transparent);
    transform: translateY(-1px);
}

.switcher-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #ffffff;
    display: flex;
    align-items: center;
}

.switcher-icon {
    color: #ffffff;
    font-size: 0.85rem;
    transition: transform 0.2s ease;
}

.context-switcher-wrapper.open .switcher-icon {
    transform: rotate(180deg);
}

.context-dropdown {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0.75rem;
    right: 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    max-height: 280px;
    overflow-y: auto;
    padding: 0.5rem;
}

.context-switcher-wrapper.open .context-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.context-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.context-option:hover {
    background: var(--bg-color);
}

.context-option.active {
    background: color-mix(in srgb, var(--sx-brand) 8%, transparent);
}

.context-option .option-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Club logo avatars - white background for visibility */
.context-option .option-avatar.club-logo {
    background: white;
    padding: 3px;
    border: 1px solid var(--border-color);
}

.context-option .option-avatar.club-logo img {
    object-fit: contain;
    border-radius: 4px;
}

.context-option .option-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.context-option .option-details {
    flex: 1;
    min-width: 0;
}

.context-option .option-name {
    display: block;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.context-option .option-subtitle {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.context-option .option-check {
    flex-shrink: 0;
    color: var(--primary-color);
    opacity: 0;
    font-size: 1rem;
}

.context-option.active .option-check {
    opacity: 1;
}

.context-option.loading {
    pointer-events: none;
    opacity: 0.6;
}

.context-option .option-avatar.home-icon {
    background: linear-gradient(135deg, #10b981, #059669);
}

.context-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}

/* Main Content */
.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    min-height: 100dvh;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

/* Top Header */
.top-header {
    position: sticky;
    top: 0;
    min-height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    padding-top: var(--safe-area-top);
    z-index: 1000;
    gap: 0.5rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    /* Minimum touch target */
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.menu-toggle:hover,
.menu-toggle:active {
    background: var(--bg-color);
}

.search-box {
    position: relative;
    width: 100%;
    max-width: 300px;
}

.search-box input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-primary);
    /* 16px minimum prevents zoom on iOS */
    font-size: 16px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--sx-brand) 10%, transparent);
}

.search-box i {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    /* Touch target */
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.search-toggle:hover,
.search-toggle:active {
    background: var(--bg-color);
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.header-btn {
    background: none;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.header-btn:hover,
.header-btn:active {
    background: var(--bg-color);
    color: var(--text-primary);
}

.header-btn i {
    font-size: 1.25rem;
}

/* Language Dropdown */
.lang-dropdown .dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: all 0.2s ease;
    /* Touch target */
    min-height: 44px;
}

.lang-dropdown .dropdown-toggle:hover,
.lang-dropdown .dropdown-toggle:focus {
    background: var(--bg-color);
    color: var(--text-primary);
}

.lang-dropdown .dropdown-toggle::after {
    display: none;
}

.lang-dropdown .dropdown-menu {
    min-width: 140px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.lang-dropdown .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
}

.lang-dropdown .dropdown-item.active {
    background: var(--primary-color);
    color: white;
}

/* User Dropdown */
.user-dropdown {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    background: none;
    /* Touch target */
    min-height: 44px;
}

.user-dropdown:hover,
.user-dropdown:focus {
    background: var(--bg-color);
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
    overflow: hidden;
}

/* White background when user has profile photo */
.user-avatar.has-photo {
    background: white;
    border: 1px solid var(--border-color);
    padding: 2px;
}

.user-avatar.has-photo img {
    border-radius: 50%;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-info {
    text-align: left;
}

.user-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.user-dropdown i.bi-chevron-down {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.dropdown-menu {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    background: var(--card-bg);
    padding: 0.5rem;
}

.dropdown-item {
    border-radius: 6px;
    padding: 0.625rem 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    /* Touch target */
    min-height: 44px;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--bg-color);
    color: var(--text-primary);
}

.dropdown-item i {
    font-size: 1rem;
    color: var(--text-secondary);
}

.dropdown-item.text-danger {
    color: var(--danger-color);
}

.dropdown-item.text-danger i {
    color: var(--danger-color);
}

.dropdown-divider {
    border-color: var(--border-color);
    margin: 0.25rem 0;
}

/* Main Content Area */
.main-content {
    flex: 1;
    padding: 1.5rem;
    /* Room for the floating Abang Sukan AI + WhatsApp buttons, so a
       page's last row (e.g. a Save button) can scroll clear of them.
       The mobile rule further down does the same. */
    padding-bottom: calc(1.5rem + 96px + var(--safe-area-bottom, 0px));
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.page-header-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    font-weight: 600;
}

.card-body {
    padding: 1.25rem;
}

/* Stat Cards */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.stat-card .stat-info h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

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

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-icon.primary {
    background: color-mix(in srgb, var(--sx-brand) 10%, transparent);
    color: var(--primary-color);
}

.stat-icon.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.stat-icon.warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.stat-icon.danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

/* Tables */
.table {
    color: var(--text-primary);
}

.table thead th {
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    padding: 0.875rem 1rem;
    white-space: nowrap;
}

.table tbody td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.table tbody tr:hover {
    background: var(--bg-color);
}

/* Badges */
.badge {
    font-weight: 500;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
    font-size: 0.75rem;
}

.badge.bg-primary-soft {
    background: color-mix(in srgb, var(--sx-brand) 10%, transparent);
    color: var(--primary-color);
}

.badge.bg-success-soft {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.badge.bg-warning-soft {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.badge.bg-danger-soft {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

/* Buttons */
.btn {
    font-weight: 500;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    /* Touch target */
    min-height: 44px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
    border: none;
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--sx-brand) 30%, transparent);
    background: var(--sx-brand-deep);
}

.btn-outline-primary {
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline-primary:hover {
    background: var(--primary-color);
    color: white;
}

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

.btn-light:hover {
    background: var(--border-color);
}

/* Forms */
.form-label {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.625rem 1rem;
    background: var(--card-bg);
    color: var(--text-primary);
    /* 16px minimum prevents zoom on iOS */
    font-size: 16px;
    /* Touch target */
    min-height: 44px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--sx-brand) 10%, transparent);
}

/* Dark mode: every field uses the same dark fill (matching the icon boxes
   beside them) and lifts to the card colour while typing. Without this,
   Bootstrap's own focus colour and some pages' light fallbacks made fields
   flip between white, grey and navy from page to page. */
[data-bs-theme="dark"] :is(.form-control, .form-select):not(:disabled) {
    background-color: var(--input-bg);
    color: var(--text-primary);
}
[data-bs-theme="dark"] :is(.form-control, .form-select):not(:disabled):focus {
    background-color: var(--card-bg);
    color: var(--text-primary);
}
[data-bs-theme="dark"] .form-control::placeholder {
    color: var(--text-tertiary);
    opacity: 1;
}

/* Browser autofill (saved email/password) paints its own pale yellow/white
   background, which hid the light text in dark mode. Keep autofilled fields
   in the same dark colours as every other field. */
[data-bs-theme="dark"] :is(input, textarea, select):-webkit-autofill,
[data-bs-theme="dark"] :is(input, textarea, select):-webkit-autofill:hover,
[data-bs-theme="dark"] :is(input, textarea, select):-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-primary);
    caret-color: var(--text-primary);
    -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset;
    box-shadow: 0 0 0 1000px var(--input-bg) inset;
    transition: background-color 600000s 0s, color 600000s 0s;
}
[data-bs-theme="dark"] :is(input, textarea, select):autofill {
    color: var(--text-primary);
}

/* Alerts */
.alert {
    border-radius: 10px;
    border: none;
    padding: 1rem 1.25rem;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    color: #065f46;
}

.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #991b1b;
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #92400e;
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    color: #1e40af;
}

/* Dark-mode contrast — alerts use dark text by default which becomes
   unreadable on the dark page background. Lift to light-tint shades. */
[data-bs-theme="dark"] .alert-success { color: #6ee7b7; }
[data-bs-theme="dark"] .alert-danger  { color: #fca5a5; }
[data-bs-theme="dark"] .alert-warning { color: #fcd34d; }
[data-bs-theme="dark"] .alert-info    { color: #93c5fd; }

/* Dark-mode contrast — Bootstrap utility classes that don't auto-flip.
   448 templates use these; instead of editing each one, remap globally. */
[data-bs-theme="dark"] .bg-light  { background-color: var(--card-bg) !important; }
[data-bs-theme="dark"] .bg-white  { background-color: var(--card-bg) !important; }
[data-bs-theme="dark"] .text-dark { color: var(--text-primary) !important; }
[data-bs-theme="dark"] .text-body { color: var(--text-primary) !important; }

/* Bootstrap's default .text-muted is too dim on a dark slate-900 bg.
   Lift to slate-400 for readability. */
[data-bs-theme="dark"] .text-muted { color: #94a3b8 !important; }

/* Soft-background badges (bg-*-soft pattern used in some apps) — make
   sure their text stays readable when the soft tint sits on a dark bg. */
[data-bs-theme="dark"] .bg-primary-soft   { color: #c7d2fe !important; }
[data-bs-theme="dark"] .bg-success-soft   { color: #6ee7b7 !important; }
[data-bs-theme="dark"] .bg-warning-soft   { color: #fcd34d !important; }
[data-bs-theme="dark"] .bg-danger-soft    { color: #fca5a5 !important; }
[data-bs-theme="dark"] .bg-secondary-soft { color: #cbd5e1 !important; }

/* Cards / modals / dropdowns: ensure default text inherits the
   theme-aware text colour even when child elements bypass Bootstrap. */
[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .dropdown-menu { color: var(--text-primary); }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h4 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

/* Mobile Search Overlay */
.mobile-search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--card-bg);
    z-index: 1060;
    padding-top: var(--safe-area-top);
}

.mobile-search-overlay.show {
    display: block;
}

.mobile-search-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.mobile-search-header input {
    flex: 1;
    border: none;
    background: var(--bg-color);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    /* 16px prevents zoom on iOS */
    font-size: 16px;
    color: var(--text-primary);
}

.mobile-search-header input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-color);
}

.mobile-search-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    /* Touch target */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-search-results {
    padding: 1rem;
    overflow-y: auto;
    max-height: calc(100vh - 80px);
    max-height: calc(100dvh - 80px);
}

/* Sidebar Overlay (Mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* ============================================
   SUBSCRIPTION STATUS - NAVBAR INTEGRATION
   Seamlessly matches existing header design
   ============================================ */

/* Subscription Badges - Match header-btn style */
.sub-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.2s ease;
}

.sub-badge:hover {
    background: var(--bg-color);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.sub-badge i {
    font-size: 1rem;
}

.sub-badge-trial {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.05);
    color: #1e40af;
}

.sub-badge-warning {
    border-color: var(--warning-color);
    background: rgba(245, 158, 11, 0.05);
    color: #d97706;
}

.sub-badge-danger {
    border-color: var(--danger-color);
    background: rgba(239, 68, 68, 0.05);
    color: #dc2626;
    animation: pulse-sub 2s infinite;
}

@keyframes pulse-sub {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* Subscription Dropdown - Matches existing style */
.sub-dropdown .dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.875rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.sub-dropdown .dropdown-toggle:hover {
    border-color: var(--primary-color);
    background: var(--bg-color);
}

.sub-dropdown .dropdown-toggle .bi-star-fill {
    color: var(--primary-color);
}

.sub-dropdown .dropdown-toggle .bi-chevron-down {
    font-size: 0.75rem;
    transition: transform 0.2s;
}

.sub-dropdown.show .dropdown-toggle .bi-chevron-down {
    transform: rotate(180deg);
}

.sub-dropdown .dropdown-menu {
    min-width: 320px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    margin-top: 0.5rem;
}

[data-bs-theme="dark"] .sub-dropdown .dropdown-menu {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sub-dropdown-header {
    padding: 1.25rem;
    background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
    color: white;
    border-radius: 16px 16px 0 0;
}

.sub-dropdown-header .pkg-name {
    font-weight: 700;
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
}

.sub-dropdown-header .pkg-price {
    opacity: 0.9;
    font-size: 0.875rem;
}

.sub-dropdown-stats {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sub-stat {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.sub-stat-icon {
    width: 36px;
    height: 36px;
    background: color-mix(in srgb, var(--sx-brand) 8%, transparent);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    flex-shrink: 0;
}

[data-bs-theme="dark"] .sub-stat-icon {
    background: color-mix(in srgb, var(--sx-brand) 15%, transparent);
}

.sub-stat-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sub-stat-value {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Responsive - Mobile */
@media (max-width: 767px) {
    .sub-badge-text {
        display: none;
    }

    .sub-badge {
        width: 40px;
        height: 40px;
        padding: 0;
        justify-content: center;
    }

    .sub-dropdown {
        display: none !important;
    }
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* ============================================
   TABLET BREAKPOINT (below 992px)
   ============================================ */
@media (max-width: 991.98px) {
    :root {
        --sidebar-width: 280px;
    }

    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .sidebar-close {
        display: flex;
    }

    .main-wrapper {
        margin-left: 0;
    }

    .menu-toggle {
        display: flex;
    }

    .search-box {
        max-width: 100%;
    }

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* ============================================
   MOBILE BREAKPOINT (below 768px)
   ============================================ */
@media (max-width: 767.98px) {
    :root {
        --header-height: 56px;
    }

    .top-header {
        padding: 0 1rem;
    }

    .header-left {
        gap: 0.5rem;
    }

    /* Hide search box, show toggle */
    .search-box {
        display: none;
    }

    .search-toggle {
        display: flex;
    }

    .header-right {
        gap: 4px;
    }

    /* Shrink icon buttons on mobile */
    .header-btn {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }

    .header-btn i {
        font-size: 1.05rem;
    }

    /* Compact language switcher on mobile - same height as the icon buttons */
    .lang-dropdown .dropdown-toggle {
        min-height: 36px;
        height: 36px;
        padding: 0 0.5rem;
        gap: 0.25rem;
        font-size: 0.8125rem;
        font-weight: 600;
    }

    .lang-dropdown .dropdown-toggle i {
        font-size: 0.95rem;
    }

    .main-content {
        padding: 1rem;
        /* The floating WhatsApp/AI-help buttons are position:fixed
           at the bottom-right (~56px circle + ~24px margin) and sit
           on top of whatever content is in view when scrolled to
           the bottom of a page - without this, the last bit of a
           long page (e.g. a card's action buttons) is permanently
           hidden underneath them, with no way to scroll it clear. */
        padding-bottom: calc(1rem + 96px + var(--safe-area-bottom, 0px));
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    /* Page header stacks on mobile */
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .page-header-actions {
        width: 100%;
    }

    .page-header-actions .btn {
        flex: 1;
    }

    /* Card adjustments */
    .card-header {
        padding: 0.875rem 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    /* Form adjustments */
    .form-row > * {
        min-width: 100%;
    }

    /* Table adjustments */
    .table thead th,
    .table tbody td {
        padding: 0.75rem;
    }

    /* User dropdown - avatar only on small mobile */
    .user-info {
        display: none;
    }

    .user-dropdown {
        padding: 0.375rem;
    }

    /* Full width buttons on mobile */
    .btn-block-mobile {
        width: 100%;
    }

    /* Action buttons in tables/lists */
    .action-buttons {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .action-buttons .btn {
        flex: 1;
        min-width: 80px;
    }

    /* Modal adjustments */
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-content {
        border-radius: 16px;
    }

    .modal-header,
    .modal-footer {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    /* Empty state */
    .empty-state {
        padding: 2rem 1rem;
    }

    .empty-state i {
        font-size: 2.5rem;
    }
}

/* ============================================
   SMALL MOBILE BREAKPOINT (below 375px)
   ============================================ */
@media (max-width: 374.98px) {
    .top-header {
        padding: 0 0.75rem;
    }

    .header-btn {
        width: 34px;
        height: 34px;
    }

    .main-content {
        padding: 0.75rem;
    }

    .sidebar {
        width: 100%;
    }

    .page-title {
        font-size: 1.125rem;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    /* Code only (EN/MS) on the narrowest phones */
    .lang-dropdown .dropdown-toggle {
        min-width: 36px;
        padding: 0 0.375rem;
        justify-content: center;
    }

    .lang-dropdown .dropdown-toggle i {
        display: none;
    }

    .header-btn {
        width: 40px;
        height: 40px;
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar-nav {
        padding: 0.5rem 0;
    }

    .nav-link {
        padding: 0.625rem 1rem;
        min-height: 40px;
    }

    .nav-section {
        padding: 0.375rem 1.5rem;
        margin-top: 0.25rem;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover states that don't work well on touch */
    .nav-link:hover {
        background: transparent;
        color: var(--text-secondary);
    }

    .nav-link:active {
        background: var(--bg-color);
        color: var(--primary-color);
    }

    .nav-link.active:hover,
    .nav-link.active:active {
        background: linear-gradient(135deg, var(--sx-brand, #4f46e5), var(--sx-brand-deep, #3730a3));
        color: white;
    }

    .btn-primary:hover {
        transform: none;
        box-shadow: none;
    }

    .btn-primary:active {
        transform: scale(0.98);
    }

    /* Increase tap targets */
    .dropdown-item {
        padding: 0.875rem 1rem;
    }
}

/* ============================================
   HIGH CONTRAST / REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .sidebar {
        transition: none;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .sidebar,
    .top-header,
    .sidebar-overlay,
    .mobile-search-overlay {
        display: none !important;
    }

    .main-wrapper {
        margin-left: 0 !important;
    }

    .main-content {
        padding: 0 !important;
    }

    .card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* ============================================
   CUSTOM UTILITY CLASSES
   ============================================ */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.flex-gap-sm {
    gap: 0.5rem;
}

.flex-gap-md {
    gap: 1rem;
}

/* Hide on specific breakpoints */
@media (max-width: 767.98px) {
    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }
}

@media (max-width: 991.98px) {
    .hide-tablet {
        display: none !important;
    }

    .show-tablet {
        display: block !important;
    }
}

/* Scrollable container with visible scrollbar hint */
.scroll-hint {
    position: relative;
}

.scroll-hint::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(to right, transparent, var(--card-bg));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.scroll-hint.has-scroll::after {
    opacity: 1;
}
