/**
 * Casino Dashboard - Dark Theme Stylesheet
 * Inspired by acebet.com color scheme
 * FULLY MOBILE RESPONSIVE
 */

/* ===== CSS Variables ===== */
:root {
    /* Background colors */
    --bg-primary: #0f1923;
    --bg-secondary: #141e2b;
    --bg-card: #1a2634;
    --bg-hover: #243344;
    
    /* Accent colors */
    --accent-green: #22c55e;
    --accent-green-hover: #16a34a;
    --accent-green-glow: rgba(34, 197, 94, 0.3);
    --accent-yellow: #facc15;
    --accent-yellow-hover: #eab308;
    --accent-red: #ef4444;
    --accent-red-hover: #dc2626;
    --accent-blue: #3b82f6;
    --accent-purple: #a855f7;
    
    /* Text colors */
    --text-primary: #ffffff;
    --text-secondary: #e2e8f0;
    --text-muted: #94a3b8;
    --text-dark: #64748b;
    
    /* Border colors */
    --border-color: #2d3a4d;
    --border-light: #3d4a5d;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-green-glow);
    
    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 70px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--accent-green);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-green-hover);
}

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

/* ===== Mobile Menu Button (Modern Hamburger) ===== */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    cursor: pointer;
    padding: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
    border-color: var(--accent-green);
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

/* Hamburger lines */
.mobile-menu-btn .hamburger-line {
    display: block;
    width: 24px;
    height: 3px;
    background: var(--accent-green);
    border-radius: 3px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

/* When menu is open - animate to X */
.mobile-menu-btn.active {
    background: var(--bg-hover);
    border-color: var(--accent-green);
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

.mobile-menu-btn.active .hamburger-line:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.mobile-menu-btn.active .hamburger-line:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.mobile-menu-btn.active .hamburger-line:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* ===== Sidebar Overlay ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

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

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform var(--transition-smooth);
}

/* Sidebar close button removed (was causing the white "X" bar issue) */
.sidebar-close {
    display: none !important;
}

.sidebar-logo {
    padding: 28px 24px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1) 0%, transparent 100%);
}

.sidebar-logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo span {
    font-size: 12px;
    color: var(--accent-green);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 28px;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    position: relative;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    padding-left: 32px;
}

.nav-link.active {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.15) 0%, transparent 100%);
    color: var(--accent-green);
    border-left-color: var(--accent-green);
}

.nav-link.active::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    background: var(--accent-green);
    border-radius: 4px 0 0 4px;
}

.nav-icon {
    font-size: 20px;
}

.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-muted);
    background: var(--bg-secondary);
}

.sidebar-footer strong {
    color: var(--accent-green);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px 40px;
    min-height: 100vh;
    transition: margin-left var(--transition-smooth);
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-green) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

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

.filter-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-filter {
    padding: 10px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-filter:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-filter.active {
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-hover));
    border-color: var(--accent-green);
    color: #000;
    box-shadow: 0 4px 12px var(--accent-green-glow);
}

.date-range-form {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.debug-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    transition: all var(--transition-fast);
}

.debug-toggle:hover {
    background: var(--bg-hover);
}

/* ===== KPI Cards ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

.kpi-card {
    display: flex;
    align-items: flex-start;
    gap: 18px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent-green), transparent);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-light);
}

.kpi-card:hover::before {
    opacity: 1;
}

.kpi-icon {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    font-size: 26px;
    flex-shrink: 0;
}

.kpi-icon.profit { background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(34, 197, 94, 0.1)); }
.kpi-icon.cpa { background: linear-gradient(135deg, rgba(250, 204, 21, 0.2), rgba(250, 204, 21, 0.1)); }
.kpi-icon.ftd { background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(59, 130, 246, 0.1)); }
.kpi-icon.casinos { background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(168, 85, 247, 0.1)); }

.kpi-content {
    flex: 1;
    min-width: 0;
}

.kpi-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-change {
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
}

.kpi-change.positive { 
    color: var(--accent-green); 
    background: rgba(34, 197, 94, 0.1);
}
.kpi-change.negative { 
    color: var(--accent-red); 
    background: rgba(239, 68, 68, 0.1);
}
.kpi-change.neutral { 
    color: var(--text-muted); 
    background: rgba(148, 163, 184, 0.1);
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    margin-bottom: 24px;
    overflow: hidden;
    transition: box-shadow var(--transition-fast);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(180deg, var(--bg-hover) 0%, transparent 100%);
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 24px;
}

/* Profit chart needs a fixed container height for Chart.js when maintainAspectRatio=false */
.chart-container {
    position: relative;
    height: 320px;
}

.chart-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    background: rgba(20, 30, 43, 0.4);
}

/* ===== Tables ===== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: -24px;
    padding: 24px;
    position: relative;
}

/* Shadow hints for scroll */
.table-responsive::before,
.table-responsive::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    z-index: 1;
}

.table-responsive::before {
    left: 0;
    background: linear-gradient(90deg, var(--bg-card), transparent);
}

.table-responsive::after {
    right: 0;
    background: linear-gradient(-90deg, var(--bg-card), transparent);
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 700px;
}

.table th,
.table td {
    padding: 16px 18px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table th {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
}

.table td {
    font-size: 14px;
    color: var(--text-secondary);
}

.table tbody tr {
    transition: background var(--transition-fast);
}

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

.table .text-right {
    text-align: right;
}

.table tfoot .totals-row {
    background: linear-gradient(90deg, var(--bg-secondary), var(--bg-card));
    font-weight: 600;
}

.table tfoot .totals-row td {
    border-bottom: none;
    color: var(--text-primary);
    font-size: 15px;
}

.debug-row {
    background: var(--bg-secondary);
}

.debug-row pre {
    font-size: 11px;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-all;
    max-width: 100%;
    overflow-x: auto;
}

/* ===== Text Colors ===== */
.text-profit { color: var(--accent-green) !important; }
.text-loss { color: var(--accent-red) !important; }
.text-cpa { color: var(--accent-yellow) !important; }
.text-muted { color: var(--text-muted) !important; }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-affilka { 
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.25), rgba(59, 130, 246, 0.1)); 
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}
.badge-cellxpert { 
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.25), rgba(168, 85, 247, 0.1)); 
    color: #c084fc;
    border: 1px solid rgba(168, 85, 247, 0.3);
}
.badge-afflines { 
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.25), rgba(236, 72, 153, 0.1)); 
    color: #f472b6;
    border: 1px solid rgba(236, 72, 153, 0.3);
}

/* ===== Status Badges ===== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
}

.status-badge.success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.status-badge.error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.status-badge.inactive {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.3);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-hover));
    color: #000;
    box-shadow: 0 4px 14px var(--accent-green-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-green-glow);
    color: #000;
}

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

.btn-secondary:hover {
    background: var(--border-color);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: var(--accent-red);
    color: #fff;
    transform: translateY(-1px);
}

.btn-warning {
    background: rgba(250, 204, 21, 0.15);
    color: var(--accent-yellow);
    border: 1px solid rgba(250, 204, 21, 0.3);
}

.btn-warning:hover {
    background: var(--accent-yellow);
    color: #000;
    transform: translateY(-1px);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 12px;
    border-radius: 8px;
}

.btn-block {
    width: 100%;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-control {
    width: 100%;
    padding: 14px 18px;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    transition: all var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 0 4px var(--accent-green-glow);
}

.form-control::placeholder {
    color: var(--text-dark);
}

.form-control-sm {
    padding: 10px 14px;
    font-size: 13px;
}

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

.form-help {
    font-size: 12px;
    color: var(--text-dark);
    margin-top: 8px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.form-group-full {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 28px;
    flex-wrap: wrap;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 10px 0;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-green);
    cursor: pointer;
}

/* ===== Alerts ===== */
.alert {
    padding: 18px 22px;
    border-radius: 12px;
    margin-bottom: 24px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: var(--accent-green);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--accent-red);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--accent-blue);
}

.alert-warning {
    background: rgba(250, 204, 21, 0.1);
    border: 1px solid rgba(250, 204, 21, 0.3);
    color: var(--accent-yellow);
}

/* ===== Info Box ===== */
.info-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 18px 22px;
    margin: 24px 0;
}

.info-box p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.info-box p:last-child {
    margin-bottom: 0;
}

.info-box strong {
    color: var(--text-primary);
}

/* ===== Page Footer ===== */
.page-footer {
    padding-top: 32px;
    margin-top: 32px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-dark);
}

/* ===== Login Page ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.login-box {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 32px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.login-logo p {
    color: var(--text-muted);
    font-size: 14px;
}

/* ===== Loading Spinner ===== */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Large tablets and small desktops */
@media (max-width: 1200px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .main-content {
        padding: 24px 28px;
    }
}

/* Tablets */
@media (max-width: 1024px) {
    .mobile-menu-btn {
        display: flex;
    }
    
    .sidebar-overlay {
        display: block;
    }
    
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    /* close button removed */

    .main-content {
        margin-left: 0;
        padding: 80px 24px 24px;
    }
    
    .page-header h1 {
        font-size: 26px;
    }
}

/* Large phones / Small tablets */
@media (max-width: 768px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .kpi-card {
        padding: 18px;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
    }
    
    .kpi-icon {
        width: 48px;
        height: 48px;
        font-size: 22px;
    }
    
    .kpi-value {
        font-size: 24px;
    }
    
    .kpi-label {
        font-size: 11px;
    }
    
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
    }
    
    .filter-buttons {
        justify-content: center;
    }
    
    .btn-filter {
        padding: 8px 12px;
        font-size: 12px;
        flex: 1;
        min-width: 0;
        justify-content: center;
    }
    
    .date-range-form {
        flex-direction: column;
        align-items: stretch;
    }
    
    .date-range-form input[type="date"] {
        width: 100%;
    }
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    
    .header-actions {
        width: 100%;
    }
    
    .header-actions .btn {
        flex: 1;
    }
    
    .card-header {
        padding: 16px 18px;
        flex-direction: column;
        align-items: flex-start;
    }
    
    .card-body {
        padding: 18px;
    }

    .chart-container {
        height: 240px;
    }

    .table-responsive {
        margin: -18px;
        padding: 18px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
    }
    
    .login-box {
        padding: 28px 24px;
    }
}

/* Phones: turn tables into stacked cards */
@media (max-width: 640px) {
    .table-responsive {
        margin: -16px;
        padding: 16px;
    }

    .table.table-cards {
        min-width: 0;
    }

    .table.table-cards thead,
    .table.table-cards tfoot {
        display: none;
    }

    .table.table-cards,
    .table.table-cards tbody,
    .table.table-cards tr,
    .table.table-cards td {
        display: block;
        width: 100%;
    }

    .table.table-cards tbody tr {
        border: 1px solid var(--border-color);
        border-radius: 14px;
        background: rgba(20, 30, 43, 0.35);
        margin-bottom: 12px;
        overflow: hidden;
    }

    .table.table-cards tbody tr:hover {
        background: rgba(36, 51, 68, 0.4);
    }

    .table.table-cards td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 14px;
        padding: 12px 14px;
        border-bottom: 1px solid var(--border-color);
        white-space: normal;
    }

    .table.table-cards td:last-child {
        border-bottom: 0;
    }

    .table.table-cards td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 700;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.6px;
        flex: 0 0 auto;
        max-width: 45%;
    }

    .table.table-cards td > * {
        min-width: 0;
    }

    .table.table-cards td strong {
        display: inline-block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .main-content {
        padding: 72px 16px 16px;
    }
    
    .mobile-menu-btn {
        top: 12px;
        left: 12px;
        width: 44px;
        height: 44px;
    }
    
    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .kpi-card {
        flex-direction: row;
        text-align: left;
        padding: 16px;
    }
    
    .kpi-icon {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
    
    .kpi-value {
        font-size: 22px;
    }
    
    .page-header h1 {
        font-size: 22px;
    }
    
    .filter-buttons {
        flex-wrap: wrap;
    }
    
    .btn-filter {
        flex: 0 0 calc(50% - 4px);
    }
    
    .card-header h2 {
        font-size: 16px;
    }
    
    .table th,
    .table td {
        padding: 12px 14px;
        font-size: 13px;
    }
    
    .badge {
        padding: 4px 8px;
        font-size: 10px;
    }
    
    .status-badge {
        padding: 4px 8px;
        font-size: 11px;
    }
    
    .btn {
        padding: 10px 18px;
        font-size: 13px;
    }
    
    .btn-sm {
        padding: 6px 12px;
        font-size: 11px;
    }
    
    .alert {
        padding: 14px 16px;
        font-size: 13px;
    }
}

/* Extra small phones */
@media (max-width: 360px) {
    .btn-filter {
        flex: 0 0 100%;
    }
    
    .kpi-value {
        font-size: 20px;
    }
}

/* Landscape mode on phones */
@media (max-height: 500px) and (orientation: landscape) {
    .main-content {
        padding: 60px 20px 20px;
    }
    
    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .kpi-card {
        padding: 14px;
    }
    
    .kpi-value {
        font-size: 20px;
    }
}

/* Touch-friendly improvements */
@media (pointer: coarse) {
    .btn, .btn-filter, .nav-link, .checkbox-label {
        min-height: 44px;
    }
    
    .form-control {
        min-height: 48px;
    }
}

/* Print styles */
@media print {
    .sidebar, .mobile-menu-btn, .header-actions, .filters-bar {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0;
        padding: 0;
    }
    
    .card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
