@font-face {
    font-family: 'Vazir';
    src: url('../../fonts/font.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    /* Base spacing & radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --gap-sm: 8px;
    --gap-md: 16px;
    --gap-lg: 24px;

    /* Default Colors (Fallback) */
    --danger: #ff4d4d;
    --danger-glow: rgba(255, 77, 77, 0.15);
    --success: #00d488;
    --success-glow: rgba(0, 212, 136, 0.15);
    --warning: #ffaa00;
    --warning-glow: rgba(255, 170, 0, 0.15);
    --secondary: #6366f1;
}

/* Theme Variable System */
:root,
:root[data-theme="dark"] {
    /* Default (Dark) */
    --bg-main: #06080d;
    --bg-card: rgba(15, 18, 26, 0.75);
    --bg-elevated: rgba(30, 35, 51, 0.6);
    --bg-hover: rgba(45, 51, 74, 0.8);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    --glass-bg: rgba(15, 18, 26, 0.4);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    --header-bg: rgba(10, 12, 18, 0.8);
}

:root[data-theme="light"] {
    --bg-main: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.75);
    --bg-elevated: rgba(241, 245, 249, 0.9);
    --bg-hover: rgba(226, 232, 240, 1);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: rgba(0, 0, 0, 0.06);
    --border-light: rgba(0, 0, 0, 0.12);
    --glass-bg: rgba(255, 255, 255, 0.4);
    --glass-border: rgba(0, 0, 0, 0.06);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    --header-bg: rgba(255, 255, 255, 0.8);
}

/* Color Presets */
:root[data-color="purple"],
:root {
    --primary: #a855f7;
    --primary-dark: #9333ea;
    --primary-glow: rgba(168, 85, 247, 0.2);
    --gradient: linear-gradient(135deg, #a855f7, #7c3aed);
}

:root[data-color="blue"] {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.2);
    --gradient: linear-gradient(135deg, #3b82f6, #1d4ed8);
}

:root[data-color="red"] {
    --primary: #ef4444;
    --primary-dark: #dc2626;
    --primary-glow: rgba(239, 68, 68, 0.2);
    --gradient: linear-gradient(135deg, #ef4444, #b91c1c);
}

:root[data-color="orange"] {
    --primary: #f97316;
    --primary-dark: #ea580c;
    --primary-glow: rgba(249, 115, 22, 0.2);
    --gradient: linear-gradient(135deg, #f97316, #c2410c);
}

:root[data-color="yellow"] {
    --primary: #eab308;
    --primary-dark: #ca8a04;
    --primary-glow: rgba(234, 179, 8, 0.2);
    --gradient: linear-gradient(135deg, #eab308, #a16207);
}

:root[data-color="green"] {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-glow: rgba(16, 185, 129, 0.2);
    --gradient: linear-gradient(135deg, #10b981, #047857);
}

/* Cross-browser reset & base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    /* Use full dynamic viewport on supported browsers (handles mobile URL bars) */
    height: 100%;
}

body,
button,
input,
textarea,
select {
    font-family: 'Vazir', Tahoma, sans-serif !important;
}

/* Prevent iOS zoom on input focus by ensuring font-size >= 16px on mobile.
   Desktop overrides via .form-input rules below. */
@media (max-width: 768px) {
    input,
    textarea,
    select {
        font-size: 16px;
    }
}

button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    border: none;
    background: none;
    font: inherit;
    color: inherit;
}

img,
svg,
video {
    max-width: 100%;
    height: auto;
    display: block;
}

a {
    color: inherit;
    text-decoration: none;
}

body {
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    /* Use safe-area for notch devices */
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    /* iOS safari momentum scroll */
    -webkit-overflow-scrolling: touch;
}

/* Firefox scrollbar */
html {
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) var(--bg-main);
}

/* Webkit scrollbar (Chrome/Safari/Edge) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    animation: fadeIn 0.5s ease;
}

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

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

/* Glass Effect Card */
.glass-pane {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

/* Header */
.header {
    background: var(--header-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    margin-bottom: 30px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    box-shadow: var(--shadow);
}

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

.logo-icon {
    width: 44px;
    height: 44px;
    background: var(--gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(-5deg);
    box-shadow: 0 5px 15px var(--primary-glow);
}

.logo-icon i {
    font-size: 20px;
    color: #fff;
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.header-title p {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Theme / Color Controls */
.theme-controls {
    display: flex;
    gap: 8px;
    background: var(--bg-elevated);
    padding: 5px;
    border-radius: 30px;
    border: 1px solid var(--border);
}

.control-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-secondary);
}

.control-btn:hover {
    color: var(--primary);
    background: var(--bg-hover);
}

.control-btn.active {
    background: var(--primary);
    color: #fff;
}

.color-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid transparent;
}

.color-dot.active {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 700;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    font-size: 0.9rem;
}

.btn i {
    font-size: 1.1rem;
}

.btn-primary {
    background: var(--gradient);
    color: #fff;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow);
}

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

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

.btn-danger {
    border-color: var(--danger);
    color: var(--danger);
    background: transparent;
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 4px 15px var(--danger-glow);
}

.btn-success {
    background: var(--success);
    color: #fff;
    box-shadow: 0 4px 15px var(--success-glow);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--success-glow);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.8rem;
}

/* Alert */
.alert {
    padding: 16px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    border: 1px solid transparent;
    animation: slideIn 0.4s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

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

.alert i {
    font-size: 1.25rem;
}

.alert.success {
    background: var(--success-glow);
    border-color: var(--success);
    color: var(--success);
}

.alert.error {
    background: var(--danger-glow);
    border-color: var(--danger);
    color: var(--danger);
}

/* Navigation Grid */
.nav-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.nav-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 16px;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--gradient);
    opacity: 0;
    transition: opacity 0.3s;
}

.nav-item:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
}

.nav-item:hover::before {
    opacity: 1;
}

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

.nav-item.active::before {
    opacity: 1;
}

.nav-item .icon-box {
    width: 60px;
    height: 60px;
    background: var(--bg-elevated);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
}

.nav-item.active .icon-box {
    background: var(--gradient);
}

.nav-item .icon-box i {
    font-size: 26px;
    color: var(--primary);
}

.nav-item.active .icon-box i {
    color: #fff;
}

.nav-item span {
    font-size: 1rem;
    font-weight: 700;
}

.nav-item small {
    padding: 2px 8px;
    background: var(--bg-elevated);
    border-radius: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

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

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.stat-card::after {
    content: '';
    position: absolute;
    bottom: -20px;
    right: -20px;
    width: 80px;
    height: 80px;
    background: var(--primary);
    filter: blur(60px);
    opacity: 0.2;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    background: var(--bg-elevated);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.stat-card .stat-icon i {
    font-size: 22px;
    color: var(--primary);
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 900;
    color: var(--text-primary);
    letter-spacing: -1px;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 600;
}

.stat-card.danger i {
    color: var(--danger);
}

.stat-card.success i {
    color: var(--success);
}

.stat-card.warning i {
    color: var(--warning);
}

/* Status Bar */
.bot-status {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.bot-status-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    position: relative;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 15px var(--success);
}

.status-dot.offline {
    background: var(--danger);
    box-shadow: 0 0 15px var(--danger);
}

.status-dot::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid currentColor;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }

    100% {
        transform: scale(2.5);
        opacity: 0;
    }
}

.bot-status-text h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.bot-status-text span {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Cards & Sections */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.card-header {
    padding: 20px 28px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-elevated);
    gap: 16px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 800;
}

.card-title i {
    font-size: 1.4rem;
    color: var(--primary);
}

.card-body {
    padding: 28px;
}

/* Modern Table */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

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

th {
    background: var(--bg-elevated);
    padding: 16px 20px;
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    border-bottom: 2px solid var(--border);
}

td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

tr:hover td {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Form Controls */
.form-group {
    margin-bottom: 20px;
}

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

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.3s;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    background: var(--bg-card);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

/* Badge */
.badge {
    padding: 6px 12px;
    border-radius: 30px;
    font-size: 0.75rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.badge-success {
    background: var(--success-glow);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-glow);
    color: var(--danger);
}

.badge-warning {
    background: var(--warning-glow);
    color: var(--warning);
}

.badge-info {
    background: rgba(99, 102, 241, 0.15);
    color: #6366f1;
}

/* Charts */
.chart-container {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    height: 240px;
    padding: 30px 0 10px;
}

.chart-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.chart-bar {
    width: 100%;
    max-width: 45px;
    background: var(--gradient);
    border-radius: 8px 8px 2px 2px;
    position: relative;
    cursor: pointer;
}

.chart-bar:hover {
    filter: brightness(1.1);
}

.chart-bar-value {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    font-weight: 800;
    opacity: 0;
    transition: 0.3s;
}

.chart-bar:hover .chart-bar-value {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 30px;
}

.page-link {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 700;
}

.page-link:hover,
.page-link.active {
    background: var(--gradient);
    color: #fff;
    border-color: transparent;
}

/* Modals - Fully Refined */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.modal.active {
    display: flex;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--bg-main);
    width: 100%;
    max-width: 600px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalSlideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

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

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-main);
    z-index: 10;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 800;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
}

.modal-close:hover {
    background: var(--danger);
    color: #fff;
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px;
}

/* Responsive Grid Adjustments */
@media (max-width: 1024px) {
    .nav-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .grid-2 {
        grid-template-columns: 1fr !important;
    }

    .container {
        padding: 12px;
    }

    .header {
        padding: 12px 16px;
        border-radius: 0 0 var(--radius-md) var(--radius-md);
        margin-bottom: 15px;
        flex-direction: column;
        gap: 12px;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
    }

    .header-left {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        background: transparent;
        padding: 0;
        gap: 10px;
        border-radius: 0;
    }

    .header-left .theme-controls {
        flex: 1;
        justify-content: center;
        min-width: 120px;
    }

    .header-left .btn-danger {
        width: 100%;
        justify-content: center;
    }


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

    .nav-item {
        padding: 16px 12px;
        gap: 8px;
    }

    .nav-item .icon-box {
        width: 50px;
        height: 50px;
        border-radius: 14px;
    }

    .nav-item .icon-box i {
        font-size: 22px;
    }

    .nav-item span {
        font-size: 0.9rem;
    }

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

    .stat-card {
        padding: 16px;
    }

    .stat-card .stat-value {
        font-size: 1.4rem;
    }

    .stat-card .stat-icon {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    .card-header {
        padding: 16px 20px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .card-header .actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-start;
    }

    .card-header form {
        width: 100%;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px;
    }

    .card-header form .form-input,
    .card-header form .form-select,
    .card-header form .btn {
        width: 100% !important;
        max-width: none !important;
    }

    .card-body {
        padding: 16px;
    }

    .btn {
        justify-content: center;
    }

    td .actions {
        justify-content: flex-start !important;
        flex-wrap: wrap;
        gap: 8px;
    }

    td .actions .btn {
        flex: 1;
        min-width: 35px;
        padding: 8px;
    }

    .table-wrapper {
        border-radius: var(--radius-sm);
    }

    th,
    td {
        padding: 12px 15px;
        font-size: 0.85rem;
    }

    .modal-content {
        width: calc(100% - 24px);
        margin: 12px;
        border-radius: var(--radius-lg);
        max-height: 85vh;
    }
}

@media (max-width: 480px) {
    .nav-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .header-title h1 {
        font-size: 1.05rem;
    }

    .header-title p {
        font-size: 0.75rem;
    }

    .logo-icon {
        width: 38px;
        height: 38px;
    }
}

/* RTL Support for Table Scroll */
[dir="rtl"] .table-wrapper {
    scrollbar-width: thin;
}

/* Evidence Preview Responsive */
.evidence-preview {
    height: 80px;
    width: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex-shrink: 0;
}
/* ================================================================
   Extra responsive & cross-browser improvements
   ================================================================ */

/* Glass effect fallback for browsers without backdrop-filter
   (older Firefox, some embedded browsers) */
@supports not ((backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px))) {
    .glass-pane,
    .header,
    .modal {
        background: var(--bg-card);
    }
    :root[data-theme="dark"] .glass-pane,
    :root[data-theme="dark"] .header {
        background: rgba(15, 18, 26, 0.95);
    }
    :root[data-theme="light"] .glass-pane,
    :root[data-theme="light"] .header {
        background: rgba(255, 255, 255, 0.97);
    }
    .modal {
        background: rgba(0, 0, 0, 0.85);
    }
}

/* Touch-friendly tap targets — minimum 44x44 per Apple HIG / 48x48 per Material */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .control-btn,
    .nav-item,
    .page-link,
    .modal-close {
        min-height: 44px;
    }
    .btn-sm {
        min-height: 38px;
    }
    /* Disable hover transforms on touch devices to prevent sticky-hover state */
    .nav-item:hover,
    .btn-primary:hover,
    .btn-success:hover {
        transform: none;
    }
}

/* Tables: horizontal scroll cue on mobile */
.table-wrapper {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

/* Image evidence preview — use logical properties */
.evidence-preview {
    max-width: 100%;
}

/* Form inputs — better mobile UX */
.form-input,
.form-textarea,
.form-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    /* Fix Firefox: remove inner border */
    background-clip: padding-box;
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
    line-height: 1.6;
}

/* Buttons: ensure no outline conflict on all browsers */
.btn:focus-visible,
.control-btn:focus-visible,
.form-input:focus-visible,
.form-textarea:focus-visible,
.form-select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Remove default focus outline only when focus-visible is supported */
.btn:focus:not(:focus-visible),
.control-btn:focus:not(:focus-visible) {
    outline: none;
}

/* Prevent text selection on UI controls (better touch experience) */
.btn,
.control-btn,
.nav-item,
.page-link,
.modal-close,
.theme-controls {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow selection in content areas */
.card-body,
.card-body p,
td,
.modal-body,
input,
textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Long content / RTL safety for Persian text */
td,
.card-body,
.modal-body {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Tablet — 992px breakpoint */
@media (max-width: 992px) {
    .container {
        padding: 16px;
    }
    .header {
        padding: 14px 20px;
    }
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
}

/* Very small phones (Galaxy Fold, iPhone SE etc., < 360px) */
@media (max-width: 360px) {
    .container {
        padding: 8px;
    }
    .header {
        padding: 10px 12px;
    }
    .header-title h1 {
        font-size: 0.95rem;
    }
    .header-title p {
        font-size: 0.7rem;
    }
    .logo-icon {
        width: 36px;
        height: 36px;
    }
    .logo-icon i {
        font-size: 16px;
    }
    .nav-item {
        padding: 12px 8px;
    }
    .nav-item .icon-box {
        width: 42px;
        height: 42px;
    }
    .nav-item .icon-box i {
        font-size: 18px;
    }
    .nav-item span {
        font-size: 0.8rem;
    }
    .stat-card {
        padding: 14px;
    }
    .stat-card .stat-value {
        font-size: 1.2rem;
    }
    .btn {
        padding: 10px 16px;
        font-size: 0.85rem;
    }
    .btn-sm {
        padding: 7px 12px;
        font-size: 0.75rem;
    }
    .card-header {
        padding: 14px 16px;
    }
    .card-body {
        padding: 14px;
    }
    .modal-content {
        margin: 8px;
        width: calc(100% - 16px);
    }
    .modal-header {
        padding: 14px 16px;
    }
    .modal-body {
        padding: 16px;
    }
    th,
    td {
        padding: 10px 12px;
        font-size: 0.8rem;
    }
}

/* Landscape orientation on short-height devices */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 10px 20px;
        margin-bottom: 12px;
    }
    .nav-grid {
        margin-bottom: 16px;
    }
    .modal-content {
        max-height: 92vh;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Print styles — clean printable output for reports */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
    }
    .header,
    .nav-grid,
    .btn,
    .modal,
    .actions,
    .pagination,
    form {
        display: none !important;
    }
    .card,
    .glass-pane {
        background: #fff !important;
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        page-break-inside: avoid;
    }
    table {
        border-collapse: collapse;
    }
    th,
    td {
        border: 1px solid #999;
        color: #000 !important;
    }
}

/* Dark mode preference fallback (when no explicit data-theme is set) */
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg-main: #f1f5f9;
        --bg-card: rgba(255, 255, 255, 0.75);
        --bg-elevated: rgba(241, 245, 249, 0.9);
        --bg-hover: rgba(226, 232, 240, 1);
        --text-primary: #0f172a;
        --text-secondary: #475569;
        --text-muted: #94a3b8;
        --border: rgba(0, 0, 0, 0.06);
        --border-light: rgba(0, 0, 0, 0.12);
        --glass-bg: rgba(255, 255, 255, 0.4);
        --glass-border: rgba(0, 0, 0, 0.06);
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
        --header-bg: rgba(255, 255, 255, 0.8);
    }
}
