/* ==================== Global Reset & Variables ==================== */
:root {
    /* Facebook Brand Palette */
    --primary-color: #0866ff;
    /* Facebook Blue */
    --primary-hover: #0064d1;
    --primary-light: rgba(8, 102, 255, 0.1);

    --success-color: #31a24c;
    /* Facebook Green */
    --success-bg: rgba(49, 162, 76, 0.1);

    --warning-color: #f7b928;
    /* Facebook Yellow */
    --warning-bg: rgba(247, 185, 40, 0.1);

    --danger-color: #f02849;
    /* Facebook Red */
    --danger-color: #f02849;
    /* Facebook Red */
    --danger-bg: rgba(240, 40, 73, 0.1);

    --purple-color: #8C52FF;
    --purple-bg: rgba(140, 82, 255, 0.1);

    /* Light Theme Backgrounds */
    --bg-body: #f0f2f5;
    /* Classic FB Background */
    --bg-glass: rgba(255, 255, 255, 0.95);

    --bg-card: #ffffff;
    --bg-hover: #e4e6eb;
    /* FB Hover Gray */
    --bg-active: #ced0d4;

    /* Typography */
    --text-primary: #050505;
    --text-secondary: #65676b;
    --text-tertiary: #b0b3b8;

    /* Borders & Shadows */
    --border-color: #dadde1;
    --border-focus: var(--primary-color);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    /* Slightly softer shadow */
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    /* Layout Dimensions */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --navbar-height: 64px;
    --content-padding: 24px;

    /* Effects */
    --backdrop-blur: blur(8px);
    --transition-speed: 0.2s;
    /* Snappier like FB */
    --radius-lg: 12px;
    /* Slightly more rounded but not pill-shaped */
    --radius-md: 8px;
    --radius-sm: 4px;
}

[data-theme="dark"] {
    --primary-color: #2d88ff;
    /* Lighter Blue for Dark Mode */
    --primary-hover: #1877f2;
    --primary-light: rgba(45, 136, 255, 0.15);

    --bg-body: #18191a;
    /* FB Dark Background */
    --bg-glass: rgba(24, 25, 26, 0.9);

    --bg-card: #242526;
    /* FB Dark Card */
    --bg-hover: #3a3b3c;
    --bg-active: #4e4f50;

    --text-primary: #e4e6eb;
    --text-secondary: #b0b3b8;
    --text-tertiary: #a0a3a7;

    --border-color: #393a3b;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

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

html {
    scrollbar-gutter: stable;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ==================== Layout Container ==================== */
.app-wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
    position: relative;
}

/* ==================== Sidebar ==================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    /* Solid color for better reliability */
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transition: width var(--transition-speed) ease;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    justify-content: space-between;
}

.sidebar-logo {
    font-size: 20px;
    font-weight: 700;
    background: var(--primary-color);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .user-name {
    display: none;
    opacity: 0;
}

.sidebar-toggle {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--primary-color);
}

.sidebar-nav {
    flex: 1;
    padding: 20px 12px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    padding: 0 12px;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-tertiary);
    letter-spacing: 0.5px;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 14px;
}

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

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary-color);
}

.nav-icon {
    font-size: 18px;
    margin-right: 12px;
    min-width: 20px;
    text-align: center;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0;
    width: 48px;
    height: 48px;
    margin: 0 auto 4px auto;
    border-radius: var(--radius-md);
}

.sidebar.collapsed .nav-icon {
    margin-right: 0;
    font-size: 24px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: default;
    background: var(--bg-hover);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #818cf8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    flex-shrink: 0;
    transition: all 0.2s;
}

.user-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: var(--text-tertiary);
}

.btn-logout {
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-footer {
    padding: 16px 0;
    display: flex;
    justify-content: center;
}

.sidebar.collapsed .sidebar-user {
    padding: 0;
    width: 48px;
    height: 48px;
    justify-content: center;
    background: transparent;
}

.sidebar.collapsed .user-avatar {
    width: 32px;
    height: 32px;
}

.sidebar.collapsed .user-info,
.sidebar.collapsed .btn-logout {
    display: none;
}

/* ==================== SVG Icons ==================== */
.icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    display: block;
    /* Removes inline spacing issues */
}

.icon-sm {
    width: 16px;
    height: 16px;
}

.icon-md {
    width: 20px;
    height: 20px;
}

.icon-lg {
    width: 24px;
    height: 24px;
}

.icon-xl {
    width: 48px;
    height: 48px;
    stroke-width: 1;
    /* Thinner stroke for large icons */
}

/* Adjustments for specific containers */
.nav-icon .icon {
    width: 20px;
    height: 20px;
}

.sidebar.collapsed .nav-icon .icon {
    width: 24px;
    height: 24px;
}

.stat-icon .icon {
    width: 28px;
    /* Adjusted size inside stat card */
    height: 28px;
    stroke-width: 2;
}

.sidebar-toggle .icon,
.mobile-menu-btn .icon {
    width: 20px;
    height: 20px;
}

.theme-toggle .icon,
.refresh-btn .icon,
.view-btn .icon {
    width: 18px;
    height: 18px;
}

.search-icon .icon {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.empty-icon .icon {
    width: 48px;
    height: 48px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
}

/* ==================== Main Wrapper ==================== */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    /* Prevent flex overflow */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition-speed) ease;
}

.sidebar.collapsed~.main-wrapper {
    margin-left: var(--sidebar-collapsed-width);
}

/* ==================== Top Navbar ==================== */
.top-navbar {
    height: var(--navbar-height);
    background: var(--bg-card);
    /* Clean background */
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.mobile-menu-btn {
    display: none;
    /* Only show on mobile */
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-primary);
    cursor: pointer;
}

.page-title h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.page-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-toggle,
.refresh-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.theme-toggle:hover,
.refresh-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ==================== Main Content Area ==================== */
.main-content {
    flex: 1;
    padding: var(--content-padding);
    background-color: var(--bg-body);
}

.content-container {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Page Visibility Logic */
.page-content {
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.page-content.active {
    display: block;
    opacity: 1;
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== Cards - Stats ==================== */
.dashboard-section {
    width: 100%;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    /* Force 5 columns on large screens */
    gap: 20px;
    overflow: visible;
    /* Ensure tooltip can overflow */
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s;
    position: relative;
    /* Ensure relative positioning */
    overflow: visible;
    /* Allow tooltip to overflow */
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-focus);
    z-index: 500;
    /* Greatly increased to ensure visibility over all other sections */
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--bg-active);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

/* Specific Stat Colors */
.stat-card:nth-child(1) .stat-icon {
    background: var(--primary-light);
    color: var(--primary-color);
}

.stat-card.stat-success .stat-icon {
    background: var(--success-bg);
    color: var(--success-color);
}

.stat-card.stat-warning .stat-icon {
    background: var(--warning-bg);
    color: var(--warning-color);
}

.stat-card.stat-danger .stat-icon {
    background: var(--danger-bg);
    color: var(--danger-color);
}

.stat-card.stat-purple .stat-icon {
    background: var(--purple-bg);
    color: var(--purple-color);
}

/* Tooltip Styles */
.stat-card {
    position: relative;
    /* Ensure tooltip positions relative to card */
}

.stat-action-btn {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0;
    pointer-events: none;
}

.stat-card:hover .stat-action-btn {
    opacity: 1;
    pointer-events: auto;
}

.stat-action-btn:hover {
    background: var(--primary-light);
}

.stat-tooltip {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    /* Full width of the card */
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-top: 8px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    max-height: 300px;
    overflow-y: auto;
    pointer-events: none;
    /* Prevent interaction when hidden */
}

/* Polished Active List Styles (Modal) */
#todayActiveModal .modal-content,
#configModal .modal-content {
    max-width: 600px;
    /* Increased from default */
    width: 90%;
}

.active-list-header {
    display: flex;
    padding: 16px 24px;
    /* Increased padding */
    background: var(--bg-hover);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    /* Increased font size */
    font-weight: 600;
    color: var(--text-secondary);
}

.active-list-item {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    /* Reduced padding */
    border-bottom: none;
    transition: background-color 0.2s;
}

/* Zebra Striping */
.active-list-item:nth-child(even) {
    background-color: var(--bg-body);
    /* Slightly different background for even rows */
}

.active-list-item:nth-child(odd) {
    background-color: var(--bg-card);
}

.active-list-item:hover {
    background-color: var(--bg-hover) !important;
    /* Force hover color on top of striping */
}

.active-list-item:last-child {
    border-bottom: none;
}



.active-col-code {
    flex: 2;
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 14px;
    font-weight: 500;
    /* Reduced from 600 */
    color: var(--text-secondary);
    /* Changed from primary to secondary */
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.active-col-user {
    flex: 1.5;
    color: var(--text-primary);
    /* Changed from secondary to primary */
    font-size: 15px;
    /* Slightly larger for emphasis */
    font-weight: 600;
    /* Added weight */
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.active-col-time {
    flex: 1;
    text-align: right;
    color: var(--text-tertiary);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.copy-btn-sm {
    opacity: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: var(--primary-color);
    transition: all 0.2s;
}

.active-list-item:hover .copy-btn-sm {
    opacity: 1;
}

.copy-btn-sm:hover {
    background: var(--primary-light);
}

.stat-card:hover .stat-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.stat-tooltip-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.stat-tooltip-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.stat-tooltip-item {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    padding: 4px 6px;
    border-radius: 4px;
    background: var(--bg-hover);
}

.stat-tooltip-code {
    font-family: monospace;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-tooltip-user {
    color: var(--text-secondary);
}

.stat-content {
    flex: 1;
    overflow: visible;
    /* Changed from hidden to visible */
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== Filter Section ==================== */
.filter-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    /* Safe wrapping */
}

.filter-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    flex-wrap: wrap;
}

/* Tabs */
.status-tabs {
    background: var(--bg-active);
    padding: 4px;
    border-radius: 8px;
    display: inline-flex;
}

.status-tab {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.status-tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.search-box {
    position: relative;
    max-width: 300px;
    min-width: 200px;
    flex: 1;
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    /* Changed from var(--bg-body) to ensure correct theming */
    color: var(--text-primary);
    font-size: 13px;
    height: 36px;
    transition: all 0.2s;
}

/* Specific Dark Mode Override using Variables */
[data-theme="dark"] .search-input {
    background-color: var(--bg-card);
    /* #242526 */
    border-color: var(--border-color);
    color: var(--text-primary);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--bg-card);
    box-shadow: 0 0 0 4px var(--primary-light);
    /* Softer focus shadow */
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 14px;
}

/* .filter-select merged below */

.filter-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ==================== View Toggle Fix ==================== */
.view-toggle {
    display: flex;
    flex-direction: row;
    align-items: center;
    background: var(--bg-hover);
    /* Light gray container */
    padding: 4px;
    border-radius: 8px;
    gap: 2px;
}

.view-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.view-btn:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.05);
}

.view-btn.active {
    background: var(--primary-color);
    color: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.view-btn.active .icon {
    color: #ffffff;
    stroke: #ffffff;
}

/* ==================== Codes Grid Fix ==================== */
.codes-section {
    width: 100%;
    min-height: 500px;
    /* Prevent layout collapse */
    transition: opacity 0.2s ease;
}

.codes-section.updating {
    opacity: 0.6;
}

.codes-grid {
    display: grid;
    /* Ensure minimum width is small enough to fit side-by-side but large enough for content */
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    width: 100%;
}

/* Ensure empty state takes full width */
.codes-grid:empty {
    display: flex;
}

.codes-group {
    grid-column: 1 / -1;
    width: 100%;
    margin-bottom: 24px;
}

.codes-group-header {
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.codes-group-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.codes-group-content {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

/* Card Status Modifiers (Matches JS Logic) */
.code-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: visible;
    /* Changed from hidden to visible */
    transition: all 0.25s;
}

.code-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Status-specific Borders */
.code-card-unused {
    border-top: 4px solid var(--success-color);
}

.code-card-used {
    border-top: 4px solid var(--warning-color);
}

.code-card-expired {
    border-top: 4px solid var(--danger-color);
    opacity: 0.85;
}

.code-card-expired:hover {
    opacity: 1;
}

.code-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.code-value {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--bg-active);
    padding: 4px 10px;
    border-radius: 6px;
    letter-spacing: 0.5px;
}

.highlight-user-text {
    color: #e41e3f !important;
    /* Impactful Red */
    font-weight: 700;
    background: rgba(228, 30, 63, 0.1);
    /* Light red background */
    padding: 2px 6px;
    border-radius: 4px;
}

/* Status Badges */
.code-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.status-unused {
    background: var(--success-bg);
    color: var(--success-color);
}

.status-used {
    background: var(--warning-bg);
    color: var(--warning-color);
}

.status-expired {
    background: var(--danger-bg);
    color: var(--danger-color);
}

.code-card-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.code-info-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border-color);
}

.code-info-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.code-info-label {
    color: var(--text-tertiary);
}

.code-info-value {
    color: var(--text-secondary);
    font-weight: 500;
}

.code-card-actions {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
}

/* ==================== List View (Matches JS 7 Columns) ==================== */
.codes-list {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.list-header,
.list-item {
    display: grid;
    /* JS Logic: 激活码, 状态, 分配对象, 设备, 有效期, 剩余天数, 操作 (7 cols) */
    grid-template-columns: 2fr 100px 1.5fr 100px 100px 100px 120px;
    gap: 16px;
    padding: 16px 24px;
    align-items: center;
}

.list-header {
    background: var(--bg-active);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
}

.list-item {
    font-size: 14px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background: var(--bg-hover);
}

/* ==================== Modals & Dynamic Content ==================== */
.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-section {
    margin-bottom: 24px;
}

.detail-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border-color);
    font-size: 14px;
}

.detail-label {
    color: var(--text-secondary);
}

.detail-value {
    font-weight: 500;
    color: var(--text-primary);
}

/* Dynamic Device List */
.device-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.device-item {
    background: var(--bg-active);
    padding: 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
    border: 1px solid var(--border-color);
}

/* Validity Options in Modal */
.validity-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.validity-btn {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-body);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.validity-btn:hover {
    border-color: var(--primary-color);
}

.validity-btn.active {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 600;
}

/* Animations & States */
.spinning {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Mobile Open State */
.sidebar.active {
    transform: translateX(0);
    box-shadow: 0 0 0 100vw rgba(0, 0, 0, 0.5);
    /* Backdrop */
}

/* ==================== Responsive ==================== */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
        --content-padding: 16px;
    }

    .sidebar {
        width: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.active {
        /* Toggled via JS */
        transform: translateX(0);
        box-shadow: 100px 0 0 rgba(0, 0, 0, 0.5);
        /* Hacky overlay */
    }

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

    .mobile-menu-btn {
        display: flex;
    }

    .sidebar-toggle {
        display: none !important;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-card {
        padding: 12px;
        gap: 10px;
    }

    .stat-icon {
        width: 32px;
        height: 32px;
        border-radius: 8px;
    }

    .stat-icon .icon {
        width: 18px;
        height: 18px;
    }

    .stat-value {
        font-size: 18px;
    }

    .stat-label {
        font-size: 11px;
    }

    .filter-section {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-left,
    .filter-right {
        width: 100%;
        justify-content: space-between;
    }

    .search-box {
        max-width: none;
    }
}

:root {
    /* Premium Color Palette */
    --primary-color: #0866ff;
    /* Facebook Blue */
    --primary-hover: #1877f2;
    --primary-light: rgba(8, 102, 255, 0.1);

    --success-color: #10b981;
    /* Emerald 500 */
    --success-bg: rgba(16, 185, 129, 0.1);

    --warning-color: #f59e0b;
    /* Amber 500 */
    --warning-bg: rgba(245, 158, 11, 0.1);

    --danger-color: #ef4444;
    /* Red 500 */
    --danger-bg: rgba(239, 68, 68, 0.1);

    /* Light Theme Backgrounds */
    --bg-body: #f3f4f6;
    /* Cool Gray 100 */
    --bg-glass: rgba(255, 255, 255, 0.85);
    --bg-card: #ffffff;
    --bg-hover: #f9fafb;
    --bg-active: #f3f4f6;

    /* Typography */
    --text-primary: #111827;
    /* Gray 900 */
    --text-secondary: #6b7280;
    /* Gray 500 */
    --text-tertiary: #9ca3af;
    /* Gray 400 */

    /* Borders & Shadows */
    --border-color: rgba(229, 231, 235, 0.6);
    /* Gray 200 with opacity */
    --border-focus: rgba(99, 102, 241, 0.4);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Layout Dimensions */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --navbar-height: 72px;
    --content-padding: 32px;

    /* Effects */
    --backdrop-blur: blur(12px);
    --transition-speed: 0.3s;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

[data-theme="dark"] {
    --primary-color: #0866ff;
    /* Facebook Blue */
    --primary-hover: #1877f2;
    --primary-light: rgba(8, 102, 255, 0.15);

    --bg-body: #18191a;
    /* Facebook Dark Background */
    --bg-glass: rgba(24, 25, 26, 0.9);

    --bg-card: #242526;
    /* Facebook Dark Card */
    --bg-hover: #3a3b3c;
    /* Facebook Hover */
    --bg-active: #4e4f50;

    --text-primary: #e4e6eb;
    /* FB White */
    --text-secondary: #b0b3b8;
    /* FB Gray */
    --text-tertiary: #a0a3a7;

    --border-color: #3e4042;
    /* FB Border */

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

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

html {
    scrollbar-gutter: stable;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-body);
    /* Subtle simple background */
    background-image: none;
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ==================== Layout ==================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar with Glassmorphism */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-glass);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    /* Safari support */
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: all var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    font-size: 24px;
    font-weight: 800;
    background: var(--primary-color);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .user-name {
    display: none;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--primary-color);
}

.sidebar-nav {
    flex: 1;
    padding: 24px 16px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 32px;
}

.nav-section-title {
    padding: 0 16px;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-tertiary);
    letter-spacing: 1px;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 4px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

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

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary-color);
}

/* Active indicator strip */
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10%;
    bottom: 10%;
    width: 3px;
    background: var(--primary-color);
    border-radius: 0 2px 2px 0;
}

.nav-icon {
    font-size: 20px;
    margin-right: 12px;
    min-width: 24px;
    display: flex;
    justify-content: center;
}

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

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.sidebar-user:hover {
    background: var(--bg-hover);
}

/* .user-avatar merged above */

/* ==================== Main Content ==================== */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed~.main-wrapper {
    margin-left: var(--sidebar-collapsed-width);
}

.top-navbar {
    height: var(--navbar-height);
    background: var(--bg-glass);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--content-padding);
    position: sticky;
    top: 0;
    z-index: 998;
}

.page-title h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.theme-toggle,
.refresh-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 18px;
}

.theme-toggle:hover,
.refresh-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.main-content {
    padding: var(--content-padding);
    max-width: 100%;
    width: 100%;
}

/* ==================== Dashboard Cards ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-card:hover::after {
    opacity: 1;
}

.stat-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: background 0.3s;
}

/* Custom icon colors */
.stat-card:nth-child(1) .stat-icon {
    background: var(--primary-light);
    color: var(--primary-color);
}

.stat-card.stat-success .stat-icon {
    background: var(--success-bg);
    color: var(--success-color);
}

.stat-card.stat-warning .stat-icon {
    background: var(--warning-bg);
    color: var(--warning-color);
}

.stat-card.stat-danger .stat-icon {
    background: var(--danger-bg);
    color: var(--danger-color);
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ==================== Filters & Controls ==================== */
.filter-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 32px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.filter-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.status-tabs {
    display: flex;
    background: var(--bg-body);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.status-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.status-tab.active {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

.search-box {
    position: relative;
    min-width: 280px;
}

.search-input {
    width: 100%;
    padding: 10px 12px 10px 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
    background: var(--bg-card);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
}

.filter-select {
    height: 38px;
    padding: 0 36px 0 16px;
    /* Extra padding on right for custom arrow */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    appearance: none;
    /* Remove default arrow */
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2365676b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

.filter-select:hover {
    background: var(--bg-hover);
}

/* ==================== Buttons ==================== */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.3px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: none;
}

.btn-primary:hover {
    transform: translateY(-2px);
    /* background: var(--primary-hover); */
    filter: brightness(1.1);
    box-shadow: none;
}

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

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--text-secondary);
}

/* ==================== Grid & List of Codes ==================== */
.codes-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    min-height: 48px;
    /* Stabilize header height */
}

.codes-group-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

/* Validity Tabs */
.validity-tabs {
    display: flex;
    gap: 8px;
    background: var(--bg-hover);
    padding: 3px;
    border-radius: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* Hide scrollbar for Firefox */
    max-width: 100%;
}

.validity-tabs::-webkit-scrollbar {
    display: none;
    /* Hide scrollbar for Chrome/Safari */
}

.validity-tab {
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    user-select: none;
    white-space: nowrap;
    /* Prevent text wrapping */
    flex-shrink: 0;
    /* Prevent squashing */
}

.validity-tab:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.05);
}

.validity-tab.active {
    background: var(--primary-color);
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .validity-tab.active {
    color: #ffffff;
}

.codes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.code-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 24px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    animation: fadeInUp 0.4s ease-out forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.code-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
    border-color: var(--border-focus);
}

.code-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Align center */
    margin-bottom: 20px;
    gap: 12px;
    /* Add gap */
}

.code-value {
    font-family: 'Monaco', 'Consolas', 'SF Mono', 'Roboto Mono', monospace;
    font-size: 14px;
    /* Smaller, delicate size */
    font-weight: 500;
    /* Lighter weight for refinement */
    color: var(--text-primary);
    letter-spacing: 1px;
    background: var(--bg-body);
    /* Subtle contrast */
    padding: 3px 8px;
    /* Minimal padding */
    border-radius: 4px;
    border: 1px solid var(--border-color);
    box-shadow: none;
    /* Flat and clean */

    /* Prevent wrapping */
    display: inline-block;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 100%;
}

/* Allow shrinking in flex */

.code-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    /* Prevent status from shrinking */
}

.status-unused {
    background: var(--success-bg);
    color: var(--success-color);
}

.status-used {
    background: var(--warning-bg);
    color: var(--warning-color);
}

.status-expired {
    background: var(--danger-bg);
    color: var(--danger-color);
}

.code-card-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.code-info-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border-color);
}

.code-info-row:last-child {
    border-bottom: none;
}

.code-info-label {
    color: var(--text-tertiary);
}

.code-info-value {
    color: var(--text-secondary);
    font-weight: 500;
}

.code-remaining-days {
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 12px;
}

.remaining-normal {
    background: var(--primary-light);
    color: var(--primary-color);
}

.remaining-warning {
    background: var(--warning-bg);
    color: var(--warning-color);
}

.remaining-urgent {
    background: var(--danger-bg);
    color: var(--danger-color);
}

.code-card-actions {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    height: 32px;
}

/* ==================== Modals ==================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border-radius: 24px;
    box-shadow: var(--shadow-xl);
    padding: 0;
    max-width: 500px;
    position: relative;
    z-index: 10;
}

/* Modal Sizing */
.modal-content.modal-large {
    max-width: 800px;
    width: 90%;
}

/* Modal 2-Column Layout */
.detail-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

@media (min-width: 769px) {
    .detail-col-left {
        border-right: 1px solid var(--border-color);
        padding-right: 24px;
    }
}

@media (max-width: 768px) {
    .detail-cols {
        grid-template-columns: 1fr;
    }
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 700;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.modal-close .icon {
    width: 24px;
    height: 24px;
    stroke-width: 2.5;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    background: var(--bg-body);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-radius: 0 0 24px 24px;
}

/* Form Styles within Modal/Generate */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 15px;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
    background: var(--bg-card);
}

.quantity-options,
.validity-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quantity-btn,
.validity-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-body);
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    transition: all 0.2s;
}

.quantity-btn:hover,
.validity-btn:hover {
    background: var(--bg-hover);
}

.quantity-btn.active,
.validity-btn.active {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* ==================== Extra Polish ==================== */
/* Loading Spinner */
.spinner {
    width: 14px;
    /* Reduced for buttons */
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Empty State */
.empty-state {
    padding: 64px 0;
    text-align: center;
}

.empty-icon {
    font-size: 72px;
    margin-bottom: 16px;
    opacity: 0.3;
    filter: grayscale(100%);
}

/* ==================== Advanced Settings Styling ==================== */
.settings-card-content {
    padding: 24px;
}

.settings-card-inner {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 16px;
}

.settings-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.settings-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    background: var(--primary-light);
    color: var(--primary-color);
}

.settings-desc {
    margin: 0 0 16px 0;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.settings-status {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
}

.settings-status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--success-color);
    border-radius: 50%;
    margin-right: 8px;
}

.settings-alert {
    padding: 16px;
    background: rgba(234, 179, 8, 0.1);
    border: 1px solid rgba(234, 179, 8, 0.3);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: #b45309;
    line-height: 1.5;
}

[data-theme="dark"] .settings-alert {
    background: rgba(234, 179, 8, 0.1);
    border-color: rgba(234, 179, 8, 0.2);
    color: #fbbf24;
}

/* ==================== Refined Inputs & Buttons ==================== */
.quantity-input {
    width: 80px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 13px;
    text-align: center;
    transition: all 0.2s;
}

.quantity-input:focus {
    border-color: var(--primary-color);
    outline: none;
    background: var(--bg-card);
}

.quantity-btn.active,
.validity-btn.active {
    background: var(--primary-color) !important;
    color: #ffffff !important;
    border-color: var(--primary-color) !important;
}

.quantity-btn:not(.active),
.validity-btn:not(.active) {
    color: var(--text-secondary);
    background: var(--bg-body);
    border-color: var(--border-color);
}

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

.form-input {
    background: var(--bg-body);
    border-color: var(--border-color);
}

.form-input:hover {
    border-color: var(--text-tertiary);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .codes-group-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding-bottom: 16px;
    }

    .validity-tabs {
        width: 100%;
        padding: 4px;
        justify-content: flex-start;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
        --content-padding: 16px;
    }

    .settings-alert {
        padding: 16px;
        background: rgba(234, 179, 8, 0.1);
        /* Yellow/Amber with opacity */
        border: 1px solid rgba(234, 179, 8, 0.3);
        border-radius: var(--radius-md);
        font-size: 13px;
        color: #ca8a04;
        /* Darker amber text */
        line-height: 1.5;
    }

    [data-theme="dark"] .settings-alert {
        background: rgba(234, 179, 8, 0.1);
        border-color: rgba(234, 179, 8, 0.2);
        color: #fca5a5;
        /* Adjust for readability if needed, or stick to amber */
        color: #fbbf24;
        /* Amber 400 */
    }

    /* ==================== Refined Inputs & Buttons (Bulk Generate Fixes) ==================== */
    /* Custom Quantity Input Fix */
    .quantity-input {
        width: 80px;
        padding: 8px 12px;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        background: var(--bg-body);
        /* Ensure it takes body bg, not white */
        color: var(--text-primary);
        font-size: 13px;
        text-align: center;
        transition: all 0.2s;
    }

    .quantity-input::placeholder {
        color: var(--text-tertiary);
    }

    .quantity-input:focus {
        border-color: var(--primary-color);
        outline: none;
        background: var(--bg-card);
    }

    /* Generate Button Gradient & Contrast */
    .quantity-btn.active,
    .validity-btn.active {
        background: var(--primary-color);
        color: #ffffff;
        border-color: var(--primary-color);
        font-weight: 600;
        box-shadow: 0 2px 4px rgba(8, 102, 255, 0.2);
    }

    /* Improve Assign To / Note Input Contrast */
    .form-input {
        background: var(--bg-body);
        border-color: var(--border-color);
    }

    .form-input:hover {
        border-color: var(--text-tertiary);
    }

    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 100px 0 0 rgba(0, 0, 0, 0.5);
        /* Overlay effect hack */
    }

    .app-wrapper {
        display: block;
        /* Fix layout */
    }

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

    .mobile-menu-btn {
        display: block;
    }
}

/* ==================== Toast Notifications ==================== */
.toast-container {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 50px;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 90vw;
    font-size: 14px;
    font-weight: 500;
    pointer-events: auto;
    animation: slideDown 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

.toast.hiding {
    animation: slideUp 0.3s ease forwards;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(0);
        opacity: 1;
    }

    to {
        transform: translateY(-100%);
        opacity: 0;
    }
}

.toast-success {
    border-left: 4px solid var(--success-color);
}

.toast-error {
    border-left: 4px solid var(--danger-color);
}

.toast-info {
    border-left: 4px solid var(--primary-color);
}

/* ==================== Success Modal Styles ==================== */
.success-modal .modal-content {
    max-width: 500px;
    width: 90%;
}

.generated-codes-list {
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-body);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-top: 20px;
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--text-tertiary) transparent;
}

.generated-codes-list::-webkit-scrollbar {
    width: 6px;
}

.generated-codes-list::-webkit-scrollbar-track {
    background: transparent;
}

.generated-codes-list::-webkit-scrollbar-thumb {
    background-color: var(--text-tertiary);
    border-radius: 3px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.generated-code-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px dashed var(--border-color);
    background: var(--bg-card);
    transition: background 0.2s;
}

.generated-code-item:hover {
    background: var(--bg-hover);
}

.generated-code-item:last-child {
    border-bottom: none;
}

.generated-code-value {
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    flex: 1;
    margin-right: 16px;
}

.copy-single-btn {
    padding: 4px 12px;
    font-size: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.copy-single-btn:hover {
    background: var(--bg-hover);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

/* ==================== Mobile Menu Backdrop ==================== */
/* Backdrop should be behind sidebar on desktop, disabled on mobile */
.sidebar::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(2px);
}

.sidebar.active::before {
    opacity: 1;
    pointer-events: auto;
}

/* 移动端：禁用伪元素遮罩，防止干扰侧边栏背景 */
@media (max-width: 768px) {
    .sidebar::before,
    .sidebar.active::before {
        display: none !important;
    }
}

/* ==================== Device Item Styling ==================== */
.device-item {
    background: var(--bg-body);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
    border-left: 3px solid var(--status-color);
    /* No border on other sides to keep it clean, uses background contrast */
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.device-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.device-id {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: inherit;
    display: block;
}

.device-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.meta-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.meta-row:last-child {
    margin-bottom: 0;
}

.meta-label {
    color: var(--text-tertiary);
}

.meta-value {
    color: var(--text-secondary);
}

.meta-value.text-danger {
    color: #ef4444;
}

/* Reset Button in Device Card */
.device-header .btn {
    padding: 4px 12px;
    font-size: 12px;
    height: auto;
    background: var(--bg-card);
    /* Slightly lighter/different than bg-body */
    border: 1px solid var(--border-color);
}

.device-header .btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-secondary);
}

/* Validity Badges - Added for UI Distinction */
.validity-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s;
    line-height: 1.4;
}

.badge-1day {
    background: var(--warning-bg);
    color: var(--warning-color);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-1month {
    background: var(--primary-light);
    color: var(--primary-color);
    border: 1px solid rgba(8, 102, 255, 0.2);
}

.badge-3months {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.badge-6months {
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.badge-12months {
    background: rgba(251, 191, 36, 0.1);
    color: #d97706;
    border: 1px solid rgba(251, 191, 36, 0.2);
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.05);
}

.badge-unlimited {
    background: var(--success-bg);
    color: var(--success-color);
    border: 1px solid rgba(16, 185, 129, 0.2);
    font-weight: 700;
}

.badge-standard {
    background: var(--bg-active);
    color: var(--text-secondary);
}

/* ==========================================================================
   MOBILE UX FINAL FIXES (PRIORITY)
   ========================================================================== */
@media (max-width: 768px) {

    /* 1. Stats Grid Optimization (2x2) */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        margin-bottom: 20px !important;
    }

    .stat-card {
        padding: 12px !important;
        gap: 10px !important;
    }

    .stat-icon {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        font-size: 16px !important;
    }

    .stat-icon .icon {
        width: 18px !important;
        height: 18px !important;
    }

    .stat-value {
        font-size: 20px !important;
    }

    .stat-label {
        font-size: 11px !important;
    }

    /* 2. Sidebar Mobile Logic */
    .sidebar {
        width: 260px !important;
        left: -260px !important;
        transition: left 0.3s ease !important;
        box-shadow: none !important;
        background: #ffffff !important;
        z-index: 1000 !important;
    }

    /* 暗色模式下侧边栏背景 */
    [data-theme="dark"] .sidebar {
        background: #242526 !important;
    }

    .sidebar.active {
        left: 0 !important;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5) !important;
    }

    /* Fix sidebar text colors in light mode on mobile - 强制使用深色文字 */
    .sidebar .nav-item {
        color: #1a1a1a !important;
    }

    .sidebar .nav-item .nav-icon {
        color: #1a1a1a !important;
    }

    .sidebar .nav-section-title {
        color: #1a1a1a !important;
        opacity: 0.6 !important;
        font-size: 12px !important;
        font-weight: 600 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
    }

    .sidebar .sidebar-logo {
        color: #1a1a1a !important;
        font-weight: 600 !important;
    }

    .sidebar .user-name {
        color: #1a1a1a !important;
        font-weight: 500 !important;
    }

    .sidebar .user-role {
        color: #666666 !important;
        font-size: 13px !important;
    }

    .sidebar .nav-item.active {
        background: #f0f2ff !important;
        color: #5B6EF5 !important;
    }

    .sidebar .nav-item.active .nav-icon {
        color: #5B6EF5 !important;
    }

    /* 暗色模式下的侧边栏颜色 */
    [data-theme="dark"] .sidebar .nav-item {
        color: #e4e6eb !important;
    }

    [data-theme="dark"] .sidebar .nav-item .nav-icon {
        color: #b0b3b8 !important;
    }

    [data-theme="dark"] .sidebar .nav-section-title {
        color: #e4e6eb !important;
    }

    [data-theme="dark"] .sidebar .sidebar-logo {
        color: #5B6EF5 !important;
    }

    [data-theme="dark"] .sidebar .user-name {
        color: #e4e6eb !important;
    }

    [data-theme="dark"] .sidebar .user-role {
        color: #b0b3b8 !important;
    }

    [data-theme="dark"] .sidebar .nav-item.active {
        background: rgba(91, 110, 245, 0.15) !important;
        color: #5B6EF5 !important;
    }

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

    /* 3. Group Header Stacking */
    .codes-group-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        padding-bottom: 16px !important;
    }

    .validity-tabs {
        width: 100% !important;
        padding: 4px !important;
        justify-content: flex-start !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
    }

    .validity-tab {
        flex-shrink: 0 !important;
    }

    /* 4. Sidebar Collapsed Reset for Mobile */
    .sidebar.collapsed {
        width: 260px !important;
    }

    .sidebar.collapsed .sidebar-logo,
    .sidebar.collapsed .nav-text,
    .sidebar.collapsed .nav-section-title,
    .sidebar.collapsed .user-name {
        display: block !important;
    }

    .sidebar.collapsed .nav-item {
        justify-content: flex-start !important;
        padding: 12px 16px !important;
    }

    .sidebar.collapsed .nav-icon {
        margin-right: 12px !important;
    }

    .sidebar.collapsed .sidebar-footer {
        padding: 20px !important;
    }

    .sidebar.collapsed .sidebar-user {
        padding: 8px !important;
    }
}

/* ==================== Revenue Page Styles ==================== */

/* Revenue Header */
.revenue-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.revenue-month-selector {
    display: flex;
    align-items: center;
    gap: 16px;
}

.month-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-speed);
}

.month-nav-btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary-color);
}

.month-nav-btn:hover .icon {
    stroke: var(--primary-color);
}

.month-nav-btn .icon {
    width: 20px;
    height: 20px;
    stroke: var(--text-secondary);
    stroke-width: 2;
    transition: stroke var(--transition-speed);
}

.revenue-month-display {
    display: flex;
    align-items: center;
    gap: 12px;
}

#currentMonthDisplay {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 120px;
    text-align: center;
}

.today-btn {
    padding: 6px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--primary-color);
    background: var(--primary-light);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-speed);
}

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

/* Revenue Summary Card */
.revenue-summary-card {
    display: flex;
    flex-direction: column;
    /* Reduced gap */
    padding: 16px 24px;
    /* Reduced padding */
    background: linear-gradient(120deg, var(--primary-color), #0a7fff, #00d2ff);
    /* Smoother gradient */
    border-radius: var(--radius-lg);
    color: white;
    box-shadow: var(--shadow-md);
    min-width: 200px;
    /* Ensure valid width */
}

.revenue-summary-label {
    display: flex;
    align-items: center;
    font-size: 14px;
    opacity: 0.9;
}

.revenue-summary-label .icon {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2.5;
}

.revenue-summary-amount {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* Revenue Stats Grid */
.revenue-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.revenue-stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    transition: all var(--transition-speed);
}

.revenue-stat-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.revenue-stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: var(--primary-light);
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.revenue-stat-icon .icon {
    width: 24px;
    height: 24px;
    stroke: var(--primary-color);
    stroke-width: 2;
    fill: none;
}

.revenue-stat-icon-warning {
    background: var(--warning-bg);
}

.revenue-stat-icon-warning .icon {
    stroke: var(--warning-color);
}

.revenue-stat-icon-success {
    background: var(--success-bg);
}

.revenue-stat-icon-success .icon {
    stroke: var(--success-color);
}

.revenue-stat-icon-purple {
    background: var(--purple-bg);
}

.revenue-stat-icon-purple .icon {
    stroke: var(--purple-color);
}

.revenue-stat-content {
    flex: 1;
}

.revenue-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.revenue-stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Revenue Daily Container */
.revenue-daily-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.revenue-daily-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.revenue-daily-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Calendar View */
.revenue-calendar {
    width: 100%;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.weekday {
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.calendar-day {
    /* aspect-ratio: 1; Removed to prevent excessive height on wide screens */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* Align to top */
    padding: 8px 4px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    cursor: pointer;
    transition: all var(--transition-speed);
    position: relative;
    min-height: 85px;
    /* Fixed reasonable height */
    height: 100%;
}

.calendar-day:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    z-index: 1;
}

.calendar-day.empty {
    background: transparent;
    border-color: transparent;
    cursor: default;
}

.calendar-day.today {
    background: rgba(45, 136, 255, 0.1);
    border: 1px dashed var(--primary-color);
}

.calendar-day.has-revenue {
    background: rgba(49, 162, 76, 0.1);
    border: 1px solid rgba(49, 162, 76, 0.3);
}

.calendar-day-number {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.calendar-day-revenue {
    font-size: 11px;
    font-weight: 600;
    color: var(--success-color);
    line-height: 1.2;
}

.calendar-day-count {
    font-size: 9px;
    color: var(--text-secondary);
    margin-top: 1px;
}

/* List View */
.revenue-list {
    width: 100%;
}

/* Revenue List Container */
.revenue-list {
    display: none;
    /* Default hidden, controlled by JS */
    width: 100%;
    min-height: 200px;
}

#revenueListContent {
    max-height: 600px;
    overflow-y: auto;
    /* Grid Layout for compact view */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
    gap: 12px;
    padding: 4px;
    /* Space for scrollbar and hover effects */
}

/* Custom Scrollbar */
#revenueListContent::-webkit-scrollbar {
    width: 6px;
}

#revenueListContent::-webkit-scrollbar-track {
    background: transparent;
}

#revenueListContent::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 3px;
}

#revenueListContent::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-secondary);
}

.revenue-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    /* More padding for card look */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    /* Larger radius */
    background: var(--bg-card);
    transition: all var(--transition-speed);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    /* Shadow by default */
}

.revenue-list-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    background: var(--bg-card);
}

.revenue-list-date {
    flex: 1;
}

.revenue-list-date-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.revenue-list-date-weekday {
    font-size: 14px;
    font-weight: 500;
    color: var(--primary-color);
    /* Highlight weekday */
    opacity: 0.9;
}

.revenue-list-stats {
    display: flex;
    gap: 32px;
    align-items: center;
}

.revenue-list-stat {
    text-align: right;
}

.revenue-list-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.revenue-list-stat-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'SF Mono', 'Roboto Mono', monospace;
    /* Monospace for numbers */
    letter-spacing: -0.5px;
}

.revenue-list-stat-value.revenue-amount {
    color: var(--success-color);
    font-weight: 700;
}

/* Empty State */
.revenue-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.revenue-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.revenue-empty h4 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.revenue-empty p {
    font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
    .revenue-header {
        flex-direction: column;
        align-items: stretch;
    }

    .revenue-month-selector {
        justify-content: center;
    }

    .revenue-summary-card {
        text-align: center;
    }

    .revenue-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .calendar-day {
        padding: 4px 2px;
    }

    .calendar-day-number {
        font-size: 14px;
    }

    .calendar-day-revenue {
        font-size: 11px;
    }

    .revenue-list-stats {
        flex-direction: column;
        gap: 12px;
        align-items: flex-end;
    }
}

/* ==================== Product Switcher ==================== */
/* ==================== Product Switcher ==================== */
.product-switch {
    display: flex;
    background: var(--bg-hover);
    padding: 3px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    position: relative;
    /* For absolute positioning of glider */
}

.product-switch-glider {
    position: absolute;
    top: 3px;
    left: 3px;
    height: calc(100% - 6px);
    background: var(--primary-color);
    /* Colored capsule */
    border-radius: 18px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 1;
}

.product-switch-btn {
    border: none;
    background: transparent !important;
    /* Override active background */
    padding: 6px 16px;
    /* Slightly wider for better look */
    border-radius: 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s ease;
    white-space: nowrap;
    position: relative;
    z-index: 2;
    /* Above glider */
    box-shadow: none !important;
    /* Remove shadow from button */
}

.product-switch-btn.active {
    color: #ffffff;
    /* White text on colored capsule */
}

.product-switch-btn:hover:not(.active) {
    color: var(--text-primary);
}

/* ==================== Theme Switch ==================== */
.theme-switch {
    display: flex;
    background: var(--bg-hover);
    padding: 3px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    position: relative;
    margin-top: 12px;
}

.theme-switch-glider {
    position: absolute;
    top: 3px;
    left: 3px;
    height: calc(100% - 6px);
    background: var(--primary-color);
    border-radius: 18px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 1;
}

.theme-switch-btn {
    border: none;
    background: transparent !important;
    padding: 8px 16px;
    border-radius: 18px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    z-index: 2;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    flex: 1;
}

.theme-switch-btn.active {
    color: #ffffff;
}

.theme-switch-btn:hover:not(.active) {
    color: var(--text-primary);
}

.theme-switch-btn .icon {
    flex-shrink: 0;
}

/* ==================== Search Clear Button ==================== */
.search-box {
    position: relative;
}

.search-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    display: none;
    /* Hidden by default */
    border-radius: 50%;
    transition: all 0.2s;
    background: transparent;
    border: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.search-clear:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.search-clear .icon {
    width: 16px;
    height: 16px;
    display: block;
}

.search-input {
    padding-right: 36px !important;
    /* Ensure content doesn't overlap button */
}/* ==================== Sidebar Submenu ==================== */
.nav-group {
    margin-bottom: 2px;
}

.nav-item.has-submenu {
    position: relative;
    cursor: pointer;
}

.nav-arrow {
    margin-left: auto;
    transition: transform 0.3s;
    opacity: 0.6;
    display: flex;
    align-items: center;
}

.nav-item.has-submenu.expanded .nav-arrow {
    transform: rotate(90deg);
}

.nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: rgba(0, 0, 0, 0.05);
    /* Slight background for nested items */
    border-radius: var(--radius-md);
    margin-top: 2px;
}

.nav-submenu.expanded {
    max-height: 200px;
    /* Approximate max height */
}

.nav-item.sub-item {
    padding-left: 44px;
    /* Indent sub items */
    font-size: 13px;
    height: 36px;
    /* Slightly smaller */
}

.sidebar.collapsed .nav-arrow {
    display: none;
}

.sidebar.collapsed .nav-submenu {
    display: none !important;
    /* Hide submenus when collapsed */
}

/* ==================== Chart Styles ==================== */
.chart-container-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.chart-title-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.chart-title-group h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chart-product-switch {
    display: flex;
    background: var(--bg-hover);
    padding: 4px;
    border-radius: var(--radius-md);
}

.chart-switch-btn {
    border: none;
    background: transparent;
    padding: 6px 12px;
    font-size: 13px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.chart-switch-btn.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 500;
}

.chart-time-filter {
    display: flex;
    gap: 8px;
}

.time-filter-btn {
    border: 1px solid var(--border-color);
    background: transparent;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.time-filter-btn:hover {
    background: var(--bg-hover);
}

.time-filter-btn.active {
    background: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-light);
    font-weight: 500;
}