:root {
    /* Dark theme (default) */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a24;
    --bg-card: rgba(26, 26, 36, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);
}

[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-glass: rgba(0, 0, 0, 0.02);
    --border-color: rgba(0, 0, 0, 0.1);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #4f46e5;
    --accent-hover: #6366f1;
    --accent-glow: rgba(79, 70, 229, 0.2);
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    --shadow-glow: 0 0 40px rgba(79, 70, 229, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============ LOGIN PAGE ============ */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(ellipse at top left, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(139, 92, 246, 0.1) 0%, transparent 50%),
        var(--bg-primary);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 48px 40px;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 28px;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 8px;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 14px 16px;
    font-size: 15px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    width: 100%;
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-glass);
    border-color: var(--accent);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-small {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-icon {
    padding: 10px;
    border-radius: 10px;
}

.error-message {
    color: var(--danger);
    font-size: 14px;
    text-align: center;
    margin-top: 16px;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 8px;
    display: none;
}

.error-message.show {
    display: block;
}

/* ============ DASHBOARD LAYOUT ============ */
.dashboard {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: width 0.3s ease, transform 0.3s ease, padding 0.3s ease;
}

/* Collapsed sidebar state for desktop */
.sidebar.collapsed {
    width: 72px;
    padding: 24px 12px;
}

.sidebar.collapsed .sidebar-logo span,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .theme-toggle span,
.sidebar.collapsed .sidebar-footer .btn span {
    display: none;
}

.sidebar.collapsed .sidebar-logo {
    justify-content: center;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px;
}

.sidebar.collapsed .theme-toggle {
    justify-content: center;
    padding: 12px;
}

.sidebar.collapsed .sidebar-footer .btn {
    justify-content: center;
    padding: 12px;
}

/* Sidebar toggle button */
.sidebar-toggle {
    position: absolute;
    top: 24px;
    right: -14px;
    width: 28px;
    height: 28px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    z-index: 101;
}

.sidebar-toggle:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.sidebar-toggle svg {
    width: 14px;
    height: 14px;
    transition: transform 0.3s ease;
}

.sidebar.collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

.sidebar-logo {
    font-size: 20px;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 32px;
    padding: 8px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
}

.nav-menu {
    list-style: none;
    flex: 1;
}

.nav-item {
    margin-bottom: 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link:hover,
.nav-link.active {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-glow);
    color: var(--accent);
}

.nav-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    overflow: hidden;
    white-space: nowrap;
}

.theme-toggle:hover {
    background: var(--bg-glass);
}

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 32px;
    background: var(--bg-primary);
    transition: margin-left 0.3s ease;
}

/* When sidebar is collapsed */
.dashboard.sidebar-collapsed .main-content {
    margin-left: 72px;
}

/* ============ HEADER ============ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-menu-btn {
    display: none;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
}

/* ============ STATS CARDS ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-card.active {
    border-left: 4px solid var(--success);
}

.stat-card.expiring {
    border-left: 4px solid var(--warning);
}

.stat-card.expired {
    border-left: 4px solid var(--danger);
}

.stat-card.total {
    border-left: 4px solid var(--accent);
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============ TOOLBAR ============ */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
}

.search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    font-size: 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-box svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.filter-buttons {
    display: flex;
    gap: 8px;
}

.filter-btn {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-btn:hover,
.filter-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.bulk-actions {
    display: flex;
    gap: 8px;
}

/* ============ DATA TABLE ============ */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow-x: auto;
    /* Ensure container never overflows the screen width */
    max-width: 100%;
    width: 100%;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

.data-table {
    width: 100%;
    /* Reduced min-width to reduce scroll necessity on larger screens */
    min-width: 1400px;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}

.data-table th,
.data-table td {
    /* Compact padding */
    padding: 10px 6px;
    text-align: center;
    /* Smaller font for data density */
    font-size: 12px;
    vertical-align: middle;
}

.data-table th {
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, rgba(26, 26, 36, 0.95) 100%);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s ease;
}

.data-table th.sortable:hover {
    color: var(--accent);
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

/* Alternating row colors - SOLID colors to support sticky columns */
.data-table tbody tr:nth-child(odd) {
    background: #1a1a24;
    /* matches --bg-tertiary solid */
}

.data-table tbody tr:nth-child(even) {
    background: #1f1f29;
    /* slightly lighter solid */
}

.data-table tbody tr:hover {
    background: #252535 !important;
}

/* Selected row highlight */
.data-table tbody tr.selected {
    background: rgba(99, 102, 241, 0.15);
    border-left: 3px solid var(--accent);
}

.data-table tbody tr:last-child {
    border-bottom: none;
}

/* Column-specific widths for optimal readability */
.checkbox-cell {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    text-align: center;
}

.checkbox-cell input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* Column widths */
.data-table th:nth-child(1),
.data-table td:nth-child(1) {
    width: 30px;
    min-width: 30px;
}

/* Name */
.data-table th:nth-child(2),
.data-table td:nth-child(2) {
    width: 140px;
    min-width: 120px;
}

/* Username */
.data-table th:nth-child(3),
.data-table td:nth-child(3) {
    width: 120px;
    min-width: 100px;
}

/* Password */
.data-table th:nth-child(4),
.data-table td:nth-child(4) {
    width: 90px;
    min-width: 80px;
}

/* Package */
.data-table th:nth-child(5),
.data-table td:nth-child(5) {
    width: 140px;
    min-width: 120px;
}

/* Status */
.data-table th:nth-child(6),
.data-table td:nth-child(6) {
    width: 90px;
    min-width: 80px;
}

/* Days Left */
.data-table th:nth-child(7),
.data-table td:nth-child(7) {
    width: 80px;
    min-width: 70px;
}

/* Expires */
.data-table th:nth-child(8),
.data-table td:nth-child(8) {
    width: 100px;
    min-width: 90px;
}

/* Phone */
.data-table th:nth-child(9),
.data-table td:nth-child(9) {
    width: 110px;
    min-width: 100px;
}

/* Email */
.data-table th:nth-child(10),
.data-table td:nth-child(10) {
    width: 140px;
    min-width: 120px;
}

/* Price */
.data-table th:nth-child(11),
.data-table td:nth-child(11) {
    width: 70px;
    min-width: 60px;
}

/* Server */
.data-table th:nth-child(12),
.data-table td:nth-child(12) {
    width: 100px;
    min-width: 80px;
}

/* Notes */
.data-table th:nth-child(13),
.data-table td:nth-child(13) {
    width: 160px;
    min-width: 140px;
}

/* Actions */
.data-table th:last-child,
.data-table td:last-child {
    width: 220px;
    min-width: 220px;
    text-align: center;
    position: sticky;
    right: 0;
    z-index: 20;
    /* Ensure it stays above other content when scrolling horizontally */
}

/* Match header gradient for sticky header */
.data-table th:last-child {
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, #1a1a24 100%);
    border-left: 1px solid var(--border-color);
}

/* Match row background - Inherit because rows are now SOLID */
.data-table td:last-child {
    background: inherit;
    border-left: 1px solid var(--border-color);
}

/* Text overflow handling */
.data-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center !important;
}

.username-cell {
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

.password-cell {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
    font-size: 12px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.status-badge.expiring {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.status-badge.expired {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.days-cell {
    font-weight: 600;
}

.actions-cell {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    /* Increased gap */
    justify-content: center;
    align-items: center;
    white-space: nowrap;
    overflow: visible;
    width: 100%;
}

.action-btn {
    width: 32px;
    /* Fixed square size */
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    /* Slightly more rounded */
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.action-btn svg {
    width: 14px;
    height: 14px;
}

.action-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.action-btn.delete:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.action-btn svg {
    width: 16px;
    height: 16px;
}

/* ============ MODAL ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    width: 90%;
    max-width: 500px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.show .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 32px;
}

/* ============ AI CHAT WIDGET ============ */
.ai-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--gradient-primary);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    box-shadow: 0 8px 24px var(--accent-glow);
    transition: all 0.3s ease;
    z-index: 999;
}

.ai-chat-toggle:hover {
    transform: scale(1.1);
}

.ai-chat-toggle svg {
    width: 28px;
    height: 28px;
}

.ai-chat-panel {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-height: 500px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.ai-chat-panel.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.ai-chat-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-header .ai-icon {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.ai-chat-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-header p {
    font-size: 12px;
    color: var(--text-secondary);
}

.ai-chat-close {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.ai-chat-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 300px;
}

.chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.chat-message.user {
    background: var(--accent);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-message.bot {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.ai-chat-input {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
}

.ai-chat-input input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
}

.ai-chat-input input:focus {
    outline: none;
    border-color: var(--accent);
}

.ai-chat-input button {
    padding: 12px 20px;
    background: var(--gradient-primary);
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-chat-input button:hover {
    transform: scale(1.05);
}

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 24px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

/* ============ LOADING ============ */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============ TOAST ============ */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    padding: 16px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============ IMPORT MODAL RESULTS ============ */
/* #importModal removed to use standard .modal-overlay class */

#importResults {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-top: 20px;
}

#importStats {
    display: flex;
    justify-content: space-between;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    font-weight: 600;
}

#importList {
    max-height: 250px;
    overflow-y: auto;
}

#importList div {
    padding: 6px 10px;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#importList div:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-menu-btn {
        display: flex;
    }

    /* Hide desktop sidebar toggle on mobile */
    .sidebar-toggle {
        display: none !important;
    }

    .overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .overlay.show {
        opacity: 1;
        visibility: visible;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 22px;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        min-width: 100%;
    }

    .filter-buttons {
        flex-wrap: wrap;
    }

    .ai-chat-panel {
        width: calc(100% - 48px);
        left: 24px;
        right: 24px;
    }

    .data-table {
        display: block;
        overflow-x: auto;
    }

    /* Fix WhatsApp view grid on mobile */
    #view-whatsapp>div:nth-child(2) {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px;
    }

    #view-whatsapp .dashboard-card {
        width: 100% !important;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 16px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 24px;
    }

    .modal {
        padding: 24px;
    }
}

/* ============ INLINE EDITING ============ */
.editable {
    cursor: pointer;
    transition: background 0.2s ease;
    border-radius: 4px;
}

.editable:hover {
    background: var(--bg-glass);
}

.editable.editing {
    padding: 0;
}

.inline-edit-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
    background: var(--bg-tertiary);
    border: 2px solid var(--accent);
    border-radius: 6px;
    color: var(--text-primary);
    outline: none;
}

.editable.saved {
    animation: savedFlash 0.5s ease;
}

@keyframes savedFlash {

    0%,
    100% {
        background: transparent;
    }

    50% {
        background: rgba(16, 185, 129, 0.3);
    }
}

/* ============ LONG-PRESS COPY ============ */
.copyable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.copyable:hover {
    background: var(--bg-glass);
}

.copyable.copied {
    animation: copiedFlash 0.5s ease;
}

@keyframes copiedFlash {

    0%,
    100% {
        background: transparent;
    }

    50% {
        background: rgba(99, 102, 241, 0.3);
    }
}

.copyable::after {
    content: "Hold to copy";
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    white-space: nowrap;
}

.copyable:hover::after {
    opacity: 1;
}

/* ============ COMPOSE MESSAGE BUTTON ============ */
.action-btn.compose:hover {
    background: var(--success);
    border-color: var(--success);
}

/* ============ MESSAGE COMPOSER MODAL ============ */
.modal.show {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.show .modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.close-btn {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: var(--danger);
    color: white;
}

.modal-footer {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

/* ============ SORTABLE COLUMN INDICATORS ============ */
.data-table th.sortable.asc::after {
    content: " ↑";
    color: var(--accent);
}

.data-table th.sortable.desc::after {
    content: " ↓";
    color: var(--accent);
}

/* ============ USERNAME CELL POSITION FOR TOOLTIP ============ */
.username-cell {
    position: relative;
}

/* ============ WHATSAPP BUTTON ============ */
.action-btn.whatsapp {
    background: #25D366;
    border-color: #25D366;
    color: white;
}

.action-btn.whatsapp:hover {
    background: #128C7E;
    border-color: #128C7E;
    transform: scale(1.05);
}

.whatsapp-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #25D366;
    color: white;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.whatsapp-link:hover {
    background: #128C7E;
    transform: translateY(-2px);
}

.whatsapp-link svg {
    width: 18px;
    height: 18px;
}

/* ============ MOBILE BOTTOM NAVIGATION ============ */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    z-index: 1000;
    justify-content: space-around;
    align-items: center;
    backdrop-filter: blur(10px);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    transition: all 0.2s ease;
    border-radius: 12px;
}

.mobile-nav-item svg {
    width: 24px;
    height: 24px;
}

.mobile-nav-item.active,
.mobile-nav-item:hover {
    color: var(--accent);
}

.mobile-nav-item.active {
    background: var(--accent-glow);
}

/* Mobile Add Button (Center) */
.mobile-add-btn {
    width: 56px;
    height: 56px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -28px;
    box-shadow: 0 4px 20px var(--accent-glow);
    color: white !important;
}

.mobile-add-btn svg {
    width: 28px;
    height: 28px;
}

.mobile-add-btn span {
    display: none;
}

/* ============ PULL TO REFRESH ============ */
.pull-to-refresh {
    display: none;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: var(--bg-secondary);
    padding: 12px 24px;
    border-radius: 0 0 16px 16px;
    box-shadow: var(--shadow-lg);
    align-items: center;
    gap: 12px;
    z-index: 1001;
    font-size: 14px;
    color: var(--text-secondary);
}

.pull-to-refresh.active {
    transform: translateX(-50%) translateY(0);
}

.pull-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============ MOBILE CUSTOMER CARDS ============ */
.mobile-customer-card {
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.2s ease;
}

.mobile-customer-card:active {
    transform: scale(0.98);
}

.mobile-customer-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.mobile-customer-name {
    font-size: 16px;
    font-weight: 600;
}

.mobile-customer-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.mobile-customer-info-item {
    display: flex;
    flex-direction: column;
}

.mobile-customer-info-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.mobile-customer-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.mobile-customer-actions .btn {
    flex: 1;
    padding: 10px;
    font-size: 13px;
}

/* ============ SWIPE ACTIONS ============ */
.swipe-container {
    position: relative;
    overflow: hidden;
}

.swipe-actions {
    position: absolute;
    top: 0;
    right: -100px;
    height: 100%;
    display: flex;
    transition: transform 0.3s ease;
}

.swipe-action {
    width: 70px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: 600;
    flex-direction: column;
    gap: 4px;
}

.swipe-action.renew {
    background: var(--success);
}

.swipe-action.delete {
    background: var(--danger);
}

.swipe-action svg {
    width: 20px;
    height: 20px;
}

/* ============ RESPONSIVE - MOBILE OPTIMIZATIONS ============ */
@media (max-width: 768px) {

    /* Show mobile bottom nav */
    .mobile-bottom-nav {
        display: flex;
    }

    /* Add padding at bottom for bottom nav */
    .main-content {
        padding-bottom: 100px;
    }

    /* Add padding to sidebar so logout button isn't hidden by bottom nav */
    .sidebar {
        padding-bottom: 100px !important;
        height: calc(100vh - 70px) !important;
        max-height: calc(100vh - 70px) !important;
        overflow-y: auto !important;
        z-index: 1001 !important;
        /* Above bottom nav (1000) */
    }

    .nav-menu {
        padding-bottom: 80px;
        overflow-y: auto;
    }

    /* Hide AI chat toggle on mobile (use bottom nav instead) */
    .ai-chat-toggle {
        bottom: 90px;
    }

    /* Pull to refresh visible */
    .pull-to-refresh {
        display: flex;
    }

    /* Stats grid mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 24px;
    }

    .stat-label {
        font-size: 12px;
    }

    /* Header adjustments */
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .header-actions {
        width: 100%;
    }

    .header-actions .btn {
        flex: 1;
    }

    /* Filter buttons scrollable */
    .filter-buttons {
        overflow-x: auto;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
    }

    .filter-buttons::-webkit-scrollbar {
        display: none;
    }

    /* Dashboard cards */
    .dashboard-card {
        padding: 16px;
    }

    /* Modal fullscreen on mobile */
    .modal {
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: calc(100vh - 120px);
        border-radius: 20px 20px 0 0;
        padding: 20px;
        padding-bottom: 24px;
        margin: 0;
        position: fixed;
        bottom: 80px;
        /* Above bottom nav */
        left: 0;
        right: 0;
        overflow-y: auto;
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }

    .modal-overlay {
        align-items: flex-end;
    }

    .modal-overlay.show {
        padding: 0;
        overflow: hidden;
    }

    .modal-overlay.show .modal {
        transform: translateY(0);
    }

    /* Ensure modal content has space at bottom for buttons */
    .modal-actions {
        padding-bottom: 16px;
        margin-bottom: 0;
    }

    /* Modal form scrolling */
    .modal form,
    .modal #customerForm,
    .modal #renewForm {
        max-height: calc(100vh - 280px);
        overflow-y: auto;
        padding-bottom: 16px;
    }

    /* Customer form mobile */
    #customerForm>div {
        grid-template-columns: 1fr !important;
    }

    /* Toolbar mobile */
    .toolbar {
        padding: 16px;
    }

    /* AI Chat panel mobile */
    .ai-chat-panel {
        width: 100%;
        left: 0;
        right: 0;
        bottom: 80px;
        max-height: calc(100vh - 160px);
        border-radius: 16px 16px 0 0;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .main-content {
        padding: 12px;
        padding-bottom: 100px;
    }

    .header h1 {
        font-size: 20px;
    }

    /* Table remains visible on mobile with horizontal scroll */
    .table-container {
        display: block;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        width: 100%;
    }

    /* Table min-width for scroll - but contained */
    .table-container .data-table {
        min-width: 800px;
        width: max-content;
    }

    /* Prevent main content from expanding viewport */
    .main-content {
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Ensure view sections don't overflow */
    .view-section {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Body should not allow horizontal scroll */
    body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Mobile cards are hidden by default, JS toggles via .show class */
    .mobile-customer-card {
        display: none;
    }

    .mobile-cards-container {
        display: none;
    }

    /* Only show cards when explicitly activated */
    .mobile-cards-container.active {
        display: block;
    }

    .mobile-cards-container.active .mobile-customer-card {
        display: block;
    }

    /* Cards container for JS toggle */
    .cards-container {
        display: none !important;
    }

    .cards-container.active {
        display: grid !important;
    }

    /* When card view is active, hide table */
    .table-container.hidden {
        display: none !important;
    }
}

/* ============ TOUCH FEEDBACK ============ */
@media (hover: none) and (pointer: coarse) {

    .btn:active,
    .action-btn:active,
    .nav-link:active,
    .filter-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    .stat-card:active {
        transform: scale(0.98);
    }
}

/* ============ SAFE AREA INSETS FOR NOTCHED PHONES ============ */
@supports (padding: max(0px)) {
    .mobile-bottom-nav {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .main-content {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

[data-theme="light"] .action-btn.whatsapp {
    background: #25D366;
    border-color: #25D366;
}

[data-theme="light"] .whatsapp-link {
    background: #25D366;
}

/* ============ FORM ELEMENT DARK MODE FIX ============ */
/* Fix for select dropdowns and textareas in dark mode */
select,
textarea {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}

select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

/* WhatsApp view specific form elements */
#waCustomerSelect,
#waMessageTemplate,
#waBulkTemplate,
#waMessageText {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    color-scheme: dark;
}

[data-theme="light"] #waCustomerSelect,
[data-theme="light"] #waMessageTemplate,
[data-theme="light"] #waBulkTemplate,
[data-theme="light"] #waMessageText {
    color-scheme: light;
}

/* Ensure form inputs have proper styling */
.form-group select,
.form-group textarea,
.dashboard-card select,
.dashboard-card textarea {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

/* Payment section selects */
#paymentCurrency,
#subCurrency,
#subInterval {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

/* ============ TABLE COLUMN WIDTHS FOR LAPTOP ============ */
/* Optimized table layout for laptop screens (min-width: 1024px) */
@media (min-width: 1024px) {
    .data-table {
        table-layout: fixed;
        width: 100%;
    }

    .data-table th,
    .data-table td {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding: 12px 8px;
    }

    /* Column width definitions */
    .data-table th:nth-child(1),
    .data-table td:nth-child(1) {
        /* Checkbox */
        width: 40px;
        min-width: 40px;
        max-width: 40px;
    }

    .data-table th:nth-child(2),
    .data-table td:nth-child(2) {
        /* Name */
        width: 140px;
        min-width: 120px;
    }

    .data-table th:nth-child(3),
    .data-table td:nth-child(3) {
        /* Username */
        width: 110px;
        min-width: 100px;
        font-family: 'Consolas', 'Monaco', monospace;
        font-size: 12px;
    }

    .data-table th:nth-child(4),
    .data-table td:nth-child(4) {
        /* Password */
        width: 100px;
        min-width: 90px;
        font-family: 'Consolas', 'Monaco', monospace;
        font-size: 12px;
    }

    .data-table th:nth-child(5),
    .data-table td:nth-child(5) {
        /* Package */
        width: 80px;
        min-width: 70px;
    }

    .data-table th:nth-child(6),
    .data-table td:nth-child(6) {
        /* Status */
        width: 90px;
        min-width: 85px;
    }

    .data-table th:nth-child(7),
    .data-table td:nth-child(7) {
        /* Days Left */
        width: 60px;
        min-width: 55px;
        text-align: center;
    }

    .data-table th:nth-child(8),
    .data-table td:nth-child(8) {
        /* Expires */
        width: 95px;
        min-width: 90px;
    }

    .data-table th:nth-child(9),
    .data-table td:nth-child(9) {
        /* Phone */
        width: 115px;
        min-width: 100px;
        font-size: 12px;
    }

    .data-table th:nth-child(10),
    .data-table td:nth-child(10) {
        /* Email */
        width: 150px;
        min-width: 130px;
        font-size: 12px;
    }

    .data-table th:nth-child(11),
    .data-table td:nth-child(11) {
        /* Price */
        width: 75px;
        min-width: 70px;
        text-align: right;
    }

    .data-table th:nth-child(12),
    .data-table td:nth-child(12) {
        /* Server */
        width: 80px;
        min-width: 70px;
    }

    .data-table th:nth-child(13),
    .data-table td:nth-child(13) {
        /* Notes */
        width: 120px;
        min-width: 100px;
        font-size: 12px;
    }

    .data-table th:nth-child(14),
    .data-table td:nth-child(14) {
        /* Actions */
        width: 130px;
        min-width: 120px;
        text-align: center;
    }

    /* Hover effect for cells - show full content */
    .data-table td:hover {
        white-space: normal;
        overflow: visible;
        z-index: 1;
    }
}

/* Larger laptop screens (1440px+) */
@media (min-width: 1440px) {

    .data-table th:nth-child(2),
    .data-table td:nth-child(2) {
        /* Name */
        width: 180px;
    }

    .data-table th:nth-child(9),
    .data-table td:nth-child(9) {
        /* Phone */
        width: 130px;
    }

    .data-table th:nth-child(10),
    .data-table td:nth-child(10) {
        /* Email */
        width: 200px;
    }

    .data-table th:nth-child(13),
    .data-table td:nth-child(13) {
        /* Notes */
        width: 180px;
    }
}

/* Ensure table container allows horizontal scroll on smaller laptops */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Sticky header for table */
.data-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Alternate row colors for better readability */
.data-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.data-table tbody tr:nth-child(odd) {
    background: transparent;
}

.data-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.12);
    transform: scale(1.001);
}

/* Draggable column headers */
.data-table th[draggable="true"] {
    cursor: grab;
    user-select: none;
    transition: all 0.2s ease;
    position: relative;
}

.data-table th[draggable="true"]::before {
    content: '⋮⋮';
    opacity: 0;
    position: absolute;
    left: 4px;
    font-size: 10px;
    color: var(--text-muted);
    transition: opacity 0.2s ease;
}

.data-table th[draggable="true"]:hover::before {
    opacity: 0.6;
}

.data-table th[draggable="true"]:active {
    cursor: grabbing;
}

.data-table th.drag-over {
    background: var(--accent);
    color: white;
    box-shadow: inset 0 0 0 2px var(--accent-hover);
}

/* Enhanced action buttons */
.action-btn {
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.action-btn.delete:hover {
    background: var(--danger);
    border-color: var(--danger);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.action-btn.whatsapp:hover {
    background: #25D366;
    border-color: #25D366;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.action-btn.compose:hover {
    background: var(--warning);
    border-color: var(--warning);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.action-btn svg {
    width: 16px;
    height: 16px;
}

/* Enhanced status badges with pulse animation */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.status-badge .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.status-badge.active .status-dot {
    animation: pulse-green 2s infinite;
}

.status-badge.expiring .status-dot {
    animation: pulse-yellow 1.5s infinite;
}

.status-badge.expired .status-dot {
    animation: pulse-red 1s infinite;
}

@keyframes pulse-green {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(16, 185, 129, 0);
    }
}

@keyframes pulse-yellow {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.6);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(245, 158, 11, 0);
    }
}

@keyframes pulse-red {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(239, 68, 68, 0);
    }
}

/* Stats cards enhancements */
.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 80px;
    background: currentColor;
    opacity: 0.05;
    border-radius: 50%;
    transform: translate(20px, -20px);
}

.stat-card .stat-value {
    font-size: 36px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-card.total .stat-value {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
}

.stat-card.active .stat-value {
    background: linear-gradient(135deg, #10b981, #34d399);
    -webkit-background-clip: text;
    background-clip: text;
}

.stat-card.expiring .stat-value {
    background: linear-gradient(135deg, #f59e0b, #fbbf24);
    -webkit-background-clip: text;
    background-clip: text;
}

.stat-card.expired .stat-value {
    background: linear-gradient(135deg, #ef4444, #f87171);
    -webkit-background-clip: text;
    background-clip: text;
}

/* Name cell styling */
.name-cell {
    font-weight: 600;
    color: var(--text-primary);
}

/* Days cell conditional styling */
.days-cell {
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

/* Table scrollbar styling */
.table-container::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Filter buttons enhancement */
.filter-btn {
    position: relative;
    overflow: hidden;
}

.filter-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.1));
    opacity: 0;
    transition: opacity 0.2s ease;
}

.filter-btn:hover::after {
    opacity: 1;
}

.filter-btn.active {
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

/* Toolbar enhancement */
.toolbar {
    background: linear-gradient(145deg, var(--bg-card), var(--bg-secondary));
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Empty state enhancement */
.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

/* Editable cell hover indicator */
.editable {
    cursor: pointer;
    position: relative;
}

.editable:hover {
    background: rgba(99, 102, 241, 0.08);
}

.editable::after {
    content: '✏️';
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    font-size: 10px;
    transition: opacity 0.2s ease;
}

.editable:hover::after {
    opacity: 0.5;
}

/* ============ CARD VIEW ============ */
.cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    padding: 20px;
}

.customer-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    transition: all 0.3s ease;
    overflow: hidden;
}

.customer-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    border-color: var(--accent);
}

.customer-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.customer-card .card-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.customer-card .card-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.customer-card .card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.customer-card .card-row .label {
    color: var(--text-secondary);
    font-size: 13px;
}

.customer-card .card-row .value {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 14px;
}

.customer-card .card-row .value.mono {
    font-family: 'JetBrains Mono', monospace;
}

.customer-card .card-row .value.days {
    font-weight: 700;
}

.customer-card .card-row .value.days.warning {
    color: var(--warning);
}

.customer-card .card-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

/* View toggle button */
.view-toggle-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
}

.view-toggle-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.view-toggle-btn svg {
    width: 24px;
    height: 24px;
}

#viewLabel {
    font-size: 11px;
    font-weight: 500;
}

/* Bulk actions styling */
.bulk-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.bulk-actions .btn {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Bulk edit select styling */
#bulkEditField,
#bulkEditValue {
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
}

#bulkEditField:focus,
#bulkEditValue:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ============ BULK ACTION BUTTONS ============ */
.bulk-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 16px;
    min-width: 60px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 11px;
    font-weight: 500;
}

.bulk-action-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.bulk-action-btn svg {
    width: 18px;
    height: 18px;
}

.bulk-action-btn .btn-text {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bulk-action-btn.sync-btn:hover {
    background: var(--success);
    border-color: var(--success);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

/* Header actions container */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Send Report button styling */
.send-report-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--warning);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.send-report-btn:hover {
    background: #d97706;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.send-report-btn svg {
    width: 16px;
    height: 16px;
}

/* ============ MOBILE RESPONSIVE ============ */
@media (max-width: 1024px) {
    .main-content {
        margin-left: 0;
        padding: 20px 16px;
    }

    .sidebar {
        transform: translateX(-100%);
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .overlay.show {
        opacity: 1;
        visibility: visible;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .header h1 {
        font-size: 20px;
    }
}

@media (max-width: 768px) {

    /* Header adjustments */
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .header-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-actions .btn {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }

    /* Stats grid - 2 columns on tablet, 1 on phone */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 28px;
    }

    /* Toolbar adjustments */
    .toolbar {
        flex-direction: column;
        padding: 16px;
        gap: 12px;
    }

    .search-box {
        width: 100%;
        min-width: unset;
    }

    .filter-buttons {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .filter-btn {
        flex: 1;
        min-width: 70px;
        text-align: center;
        padding: 8px 12px;
    }

    .bulk-actions {
        width: 100%;
        justify-content: center;
    }

    /* Table horizontal scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Compact table for mobile - show all columns with scroll */
    .data-table {
        min-width: 700px;
    }

    .data-table th,
    .data-table td {
        padding: 8px 10px;
        font-size: 12px;
    }

    /* Force action buttons in a horizontal row using flex */
    .actions-cell {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        justify-content: center !important;
        align-items: center !important;
        min-width: 140px !important;
    }

    .action-btn {
        width: 26px !important;
        height: 26px !important;
        min-width: 26px !important;
        padding: 3px !important;
        flex-shrink: 0 !important;
    }

    .action-btn svg {
        width: 12px !important;
        height: 12px !important;
    }

    /* View toggle area */
    .view-toggle-btn {
        min-width: 80px;
        padding: 8px 12px;
    }

    /* Bulk action buttons */
    .bulk-action-btn {
        padding: 8px 12px;
        min-width: 50px;
    }

    /* Cards container */
    .cards-container {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }

    /* Modal adjustments */
    .modal {
        width: 95%;
        max-width: none;
        margin: 16px;
        padding: 20px;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* AI Chat panel */
    .ai-chat-panel {
        width: calc(100% - 32px);
        right: 16px;
        left: 16px;
        bottom: 90px;
        max-height: 60vh;
        z-index: 9999;
        background: var(--bg-secondary);
    }

    .ai-chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }
}

@media (max-width: 480px) {

    /* Very small screens */
    .header h1 {
        font-size: 18px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-value {
        font-size: 24px;
    }

    .stat-label {
        font-size: 12px;
    }

    .header-actions {
        gap: 6px;
    }

    .header-actions .btn {
        padding: 10px 14px;
        font-size: 12px;
    }

    .filter-btn {
        font-size: 11px;
        padding: 6px 10px;
    }

    /* Stack action buttons in table */
    .actions-cell {
        flex-direction: column;
        gap: 4px;
    }

    .action-btn {
        width: 100%;
        justify-content: center;
    }

    /* Customer card mobile */
    .customer-card {
        padding: 16px;
    }

    .customer-card .card-header h3 {
        font-size: 14px;
    }

    .customer-card .card-row {
        font-size: 12px;
    }

    .customer-card .card-actions {
        flex-direction: column;
        gap: 6px;
    }

    .customer-card .card-actions .btn {
        width: 100%;
    }

    /* Modal form */
    .form-group {
        margin-bottom: 16px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 12px 14px;
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    .modal-actions {
        flex-direction: column;
        gap: 8px;
    }

    .modal-actions .btn {
        width: 100%;
    }

    /* Bulk action buttons compact */
    .bulk-action-btn {
        padding: 6px 10px;
        min-width: 45px;
    }

    .bulk-action-btn svg {
        width: 16px;
        height: 16px;
    }

    .bulk-action-btn .btn-text {
        font-size: 9px;
    }
}

/* Mobile bottom navigation bar */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 8px 16px;
    z-index: 100;
    justify-content: space-around;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
}

@media (max-width: 768px) {
    .mobile-nav {
        display: flex;
    }

    .main-content {
        padding-bottom: 80px;
    }
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.mobile-nav-item.active {
    color: var(--accent);
    background: var(--accent-glow);
}

.mobile-nav-item svg {
    width: 20px;
    height: 20px;
}

/* Touch optimizations */
@media (hover: none) and (pointer: coarse) {
    .action-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .filter-btn {
        min-height: 44px;
    }

    .editable::after {
        display: none;
    }

    .data-table th[draggable="true"]::before {
        display: none;
    }
}

/* ============ ENHANCED MOBILE RESPONSIVENESS ============ */
/* Dashboard View Grid Fixes */
@media (max-width: 768px) {

    /* Dashboard panel credits widget */
    #view-dashboard>div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    /* Dashboard cards layout */
    #view-dashboard .dashboard-card {
        padding: 16px !important;
    }

    /* Quick actions buttons stack */
    #view-dashboard .dashboard-card div[style*="flex-direction: column"] {
        gap: 8px !important;
    }

    /* Revenue and expiring lists */
    #view-dashboard .dashboard-card div[style*="max-height: 300px"] {
        max-height: 200px !important;
    }

    /* AI Chat toggle - position above bottom nav */
    .ai-chat-toggle {
        bottom: 100px !important;
        right: 16px !important;
        width: 52px;
        height: 52px;
        z-index: 997;
    }

    .ai-chat-toggle svg {
        width: 24px;
        height: 24px;
    }
}

/* Payments View Mobile Optimization */
@media (max-width: 768px) {
    #view-payments>div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    #view-payments .dashboard-card {
        padding: 16px !important;
    }

    /* Payment input grid */
    #view-payments .dashboard-card div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    /* Payment result box responsive */
    #view-payments .dashboard-card div[style*="display: flex; gap: 8px"] {
        flex-direction: column;
    }

    #view-payments .dashboard-card div[style*="display: flex; gap: 8px"] input {
        width: 100% !important;
    }
}

/* WhatsApp View Mobile Optimization */
@media (max-width: 768px) {
    #view-whatsapp>div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    #view-whatsapp .dashboard-card {
        padding: 16px !important;
    }

    /* WhatsApp button container */
    #view-whatsapp .dashboard-card div[style*="display: flex; gap: 12px; flex-wrap: wrap"] {
        flex-direction: column;
    }

    #view-whatsapp .dashboard-card div[style*="display: flex; gap: 12px; flex-wrap: wrap"] .btn {
        width: 100%;
    }

    /* Header with connection status */
    #view-whatsapp .header {
        flex-direction: column;
        gap: 12px;
    }

    #waConnectionStatus {
        width: 100%;
        text-align: center;
    }
}

/* AI Import View Mobile */
@media (max-width: 768px) {
    #view-ai-import>div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    #view-ai-import .dashboard-card {
        padding: 16px !important;
    }

    /* Upload area adjustments */
    #uploadArea,
    #csvUploadArea {
        padding: 24px 16px !important;
    }

    /* Preview table scroll */
    #aiPreviewTable {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Import/Export View Mobile */
@media (max-width: 768px) {
    #view-import .dashboard-card {
        max-width: 100% !important;
        margin: 16px 0 !important;
        padding: 16px !important;
    }
}

/* Enhanced Modal Mobile Experience */
@media (max-width: 768px) {
    .modal-overlay.show {
        padding: 0 !important;
        align-items: flex-end;
    }

    .modal {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: 90vh !important;
        border-radius: 20px 20px 0 0 !important;
        padding: 20px !important;
        margin: 0 !important;
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: var(--bg-secondary);
        padding-bottom: 16px;
        margin-bottom: 16px;
        z-index: 10;
    }

    #customerForm {
        max-height: 60vh !important;
    }

    /* Modal form grid - single column */
    .modal form>div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Panel integration section responsive */
    .modal div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* Stats Grid Mobile Enhancement */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .stat-card {
        padding: 12px !important;
        border-radius: 12px !important;
    }

    .stat-value {
        font-size: 20px !important;
    }

    .stat-label {
        font-size: 10px !important;
    }
}

/* Header Mobile Enhancement */
@media (max-width: 480px) {
    .header {
        margin-bottom: 16px !important;
    }

    .header h1 {
        font-size: 18px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 200px;
    }

    .header-actions .btn {
        padding: 10px 12px !important;
        font-size: 12px !important;
    }

    .header-actions .btn svg {
        width: 16px;
        height: 16px;
    }

    /* Hide button text on very small screens */
    .header-actions .btn span:not(:only-child) {
        display: none;
    }
}

/* Toolbar Mobile Enhancement */
@media (max-width: 480px) {
    .toolbar {
        padding: 12px !important;
        gap: 10px !important;
        border-radius: 12px !important;
        margin-bottom: 16px !important;
    }

    .search-box input {
        padding: 10px 12px 10px 38px !important;
        font-size: 14px !important;
    }

    .filter-buttons {
        gap: 6px !important;
    }

    .filter-btn {
        padding: 8px 10px !important;
        font-size: 11px !important;
        border-radius: 6px !important;
    }
}

/* Bottom Navigation Enhancement */
@media (max-width: 480px) {
    .mobile-bottom-nav {
        padding: 6px 0 max(6px, env(safe-area-inset-bottom)) !important;
    }

    .mobile-nav-item {
        padding: 6px 8px !important;
        font-size: 9px !important;
    }

    .mobile-nav-item svg {
        width: 20px !important;
        height: 20px !important;
    }

    .mobile-add-btn {
        width: 50px !important;
        height: 50px !important;
        margin-top: -24px !important;
    }

    .mobile-add-btn svg {
        width: 24px !important;
        height: 24px !important;
    }
}

/* AI Chat Panel Mobile */
@media (max-width: 480px) {
    .ai-chat-panel {
        width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        max-height: 70vh !important;
        border-radius: 20px 20px 0 0 !important;
    }

    .ai-chat-toggle {
        bottom: 90px !important;
        right: 12px !important;
        width: 48px !important;
        height: 48px !important;
    }

    .ai-chat-header {
        padding: 16px !important;
    }

    .ai-chat-messages {
        padding: 16px !important;
        max-height: 40vh !important;
    }

    .ai-chat-input {
        padding: 12px 16px max(12px, env(safe-area-inset-bottom)) !important;
    }

    .ai-chat-input input {
        padding: 10px 14px !important;
    }
}

/* Toast Notifications Mobile */
@media (max-width: 480px) {
    .toast-container {
        top: 12px !important;
        right: 12px !important;
        left: 12px !important;
    }

    .toast {
        padding: 12px 16px !important;
        border-radius: 10px !important;
        font-size: 13px !important;
    }
}

/* Dashboard Cards Scrollable Lists */
@media (max-width: 480px) {

    #expiringSoonList,
    #expiredList,
    #recentCustomersWhatsApp,
    #expiringCustomersList {
        max-height: 150px !important;
    }
}

/* Form Inputs Mobile Enhancement */
@media (max-width: 480px) {

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px !important;
        /* Prevents iOS zoom */
        padding: 14px !important;
        border-radius: 10px !important;
    }

    .form-group label {
        font-size: 13px !important;
        margin-bottom: 6px !important;
    }
}

/* Landscape Mode Adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .modal {
        max-height: 85vh !important;
    }

    #customerForm {
        max-height: 50vh !important;
    }

    .ai-chat-panel {
        max-height: 60vh !important;
    }

    .ai-chat-messages {
        max-height: 25vh !important;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* Prevent Text Selection on Touch */
@media (hover: none) and (pointer: coarse) {

    .mobile-nav-item,
    .mobile-add-btn,
    .stat-card,
    .filter-btn,
    .action-btn {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        user-select: none;
    }
}