/*
 * Sameem v4 — Design System (Light Theme)
 */

html {
    scroll-behavior: smooth;
}
:root {
    /* Colors */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --bg-main: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --info: #0284c7;
    --info-bg: #f0f9ff;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Radius */
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    /* Typography */
    --font-en: 'Inter', system-ui, sans-serif;
    --font-ar: 'Tajawal', system-ui, sans-serif;
}

/* Segmented Control Buttons */
.segmented-control {
    display: flex;
    background-color: #f1f5f9;
    padding: 0.25rem;
    border-radius: 0.5rem;
    gap: 0.25rem;
}
.period-btn {
    padding: 0.375rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 700;
    color: #475569;
    transition: all 0.2s;
    border: none;
    background: transparent;
    cursor: pointer;
}
.period-btn:hover {
    color: #0f172a;
}
.period-btn.active {
    background-color: white !important;
    color: var(--primary) !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
    transition: background-color 0.3s;
}

html[dir="rtl"] body {
    font-family: var(--font-ar);
}
html[dir="ltr"] body {
    font-family: var(--font-en);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover {
    color: var(--primary-dark);
}

/* Layout Utilities */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }

.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.col-span-1 { grid-column: span 1 / span 1; }
.col-span-2 { grid-column: span 2 / span 2; }
.col-span-3 { grid-column: span 3 / span 3; }
@media (min-width: 768px) {
    .md-grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .md-grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
    .lg-grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .lg-grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .lg-grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .lg\:col-span-2 { grid-column: span 2 / span 2; }
}

.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }

.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.pb-2 { padding-bottom: 0.5rem; }
.pb-4 { padding-bottom: 1rem; }
.pt-6 { padding-top: 1.5rem; }

.text-center { text-align: center; }
.text-sm { font-size: 0.875rem; }
.text-md { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--text-muted); }
.text-indigo-600 { color: #4f46e5; }
.text-slate-500 { color: #64748b; }
.text-slate-800 { color: #1e293b; }
.hover\:text-slate-800:hover { color: #1e293b; }
.border-b-2 { border-bottom-width: 2px; }
.border-indigo-600 { border-color: #4f46e5; }
.border-slate-200 { border-color: #e2e8f0; }
.border-b { border-bottom-width: 1px; }
.border-t { border-top-width: 1px; }
.space-y-4 > * + * { margin-top: 1rem; }

/* Components */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    font-family: inherit;
}

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

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

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: #b91c1c;
}

.btn-block {
    width: 100%;
}

.btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}
.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-main);
}
.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-main);
    background-color: var(--surface);
    background-clip: padding-box;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    font-family: inherit;
}
.form-control:focus {
    color: var(--text-main);
    background-color: var(--surface);
    border-color: var(--primary);
    outline: 0;
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Alerts / Toasts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.alert-error {
    background-color: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
}
.alert-success {
    background-color: var(--success-bg);
    color: var(--success);
    border: 1px solid #bbf7d0;
}
.hidden {
    display: none !important;
}

/* Spinner */
.spinner {
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top: 2px solid white;
    width: 1rem;
    height: 1rem;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Animations */
.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Layout Shell (App) */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 40;
}
html[dir="rtl"] .sidebar {
    border-right: none;
    border-left: 1px solid var(--border);
    right: 0;
}
html[dir="ltr"] .sidebar {
    left: 0;
}

.main-content {
    flex: 1;
    margin-right: 260px; /* RTL default */
    padding: 2rem;
}
html[dir="ltr"] .main-content {
    margin-right: 0;
    margin-left: 260px;
}

/* Sidebar Nav */
.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.nav-link:hover {
    background: var(--bg-main);
    color: var(--text-main);
}
.nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
}

/* Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

/* Badges */
.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-secondary { background: var(--bg-main); color: var(--text-muted); }

/* Table */
.table-container {
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
}
html[dir="ltr"] .table {
    text-align: left;
}
.table th, .table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}
.table th {
    background: var(--bg-main);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.875rem;
}
.table tr:last-child td {
    border-bottom: none;
}
.table tbody tr:hover {
    background-color: #fcfcfc;
}

/* Auth Page specific */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background-image: radial-gradient(var(--border) 1px, transparent 1px);
    background-size: 30px 30px;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
}

/* Dropdowns */
.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 320px;
    z-index: 50;
    display: none;
    overflow: hidden;
}
html[dir="ltr"] .dropdown-menu {
    right: auto;
    left: 0;
}
.dropdown-menu-end {
    right: auto !important;
    left: 0 !important;
}
html[dir="ltr"] .dropdown-menu-end {
    right: 0 !important;
    left: auto !important;
}
.dropdown.show .dropdown-menu {
    display: block;
    animation: fadeIn 0.2s ease-in-out;
}
.dropdown-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: block;
    transition: background 0.2s;
    color: var(--text-main);
}
.dropdown-item:last-child {
    border-bottom: none;
}
.dropdown-item:hover {
    background: var(--bg-main);
}
.dropdown-item.unread {
    background: var(--primary-light);
}
.dropdown-item.unread:hover {
    background: #e0e7ff;
}
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    border-radius: 50%;
    padding: 0.15rem 0.4rem;
    min-width: 18px;
    text-align: center;
}

/* Image / Avatar Utilities */
.w-6 { width: 1.5rem; }
.w-8 { width: 2rem; }
.h-8 { height: 2rem; }
.w-10 { width: 2.5rem; }
.h-10 { height: 2.5rem; }
.w-24 { width: 6rem; }
.w-28 { width: 7rem; }
.h-28 { height: 7rem; }
.w-32 { width: 8rem; }
.w-40 { width: 10rem; }
.max-w-xs { max-width: 20rem; }
.max-w-sm { max-width: 24rem; }
.max-w-md { max-width: 28rem; }
.max-w-lg { max-width: 32rem; }
.max-w-xl { max-width: 36rem; }
.max-w-2xl { max-width: 42rem; }
.rounded-full { border-radius: 9999px; }
.object-cover { object-fit: cover; }
.mx-auto { margin-left: auto; margin-right: auto; }
.border-4 { border-width: 4px; }
.inline-block { display: inline-block; }
.block { display: block; }
.relative { position: relative; }
.overflow-x-auto { overflow-x: auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =============================================
   MOBILE RESPONSIVE — Admin Panel
   ============================================= */

/* Hamburger Menu Button (hidden on desktop) */
.hamburger-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-main);
    transition: all 0.2s;
    flex-shrink: 0;
}
.hamburger-btn:hover {
    background: var(--bg-main);
}

/* Sidebar overlay backdrop */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 35;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {
    /* Show hamburger */
    .hamburger-btn {
        display: flex;
    }

    /* Sidebar becomes an off-canvas drawer */
    .sidebar {
        transform: translateX(100%); /* RTL: slides in from right */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 40;
        width: 280px;
        box-shadow: var(--shadow-lg);
    }
    html[dir="ltr"] .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    /* Main content takes full width */
    .main-content {
        margin-right: 0 !important;
        margin-left: 0 !important;
        padding: 1rem;
    }

    /* Top header adjustments */
    .top-header {
        padding: 0.75rem 1rem;
        margin-bottom: 1rem;
        gap: 0.5rem;
    }
    .top-header .flex {
        gap: 0.5rem;
    }

    /* Hide date on mobile */
    .top-header .font-mono {
        display: none;
    }

    /* Cards full width */
    .card {
        padding: 1rem;
    }

    /* Grid: stack columns on mobile */
    .grid-cols-2,
    .grid-cols-3 {
        grid-template-columns: 1fr !important;
    }

    /* Stats grid: 2 columns on mobile */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Auth card full screen */
    .auth-card {
        padding: 1.5rem;
    }

    /* Notification dropdown on mobile: wider, right-anchored */
    .dropdown-menu {
        width: min(320px, 90vw);
        right: 0;
        left: auto;
    }
    html[dir="ltr"] .dropdown-menu {
        left: 0;
        right: auto;
    }

    /* Forms */
    .form-control {
        font-size: 16px; /* prevent iOS zoom on focus */
    }

    /* Buttons smaller */
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.825rem;
    }

    /* Table horizontal scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.75rem;
    }
    .top-header {
        padding: 0.625rem 0.75rem;
    }
}

/* Global Avatar Fix: Ensure perfect circles without distortion */
img.rounded-full, 
img.chat-avatar, 
img.user-avatar-circle, 
img[src*="avatar"] {
    object-fit: cover !important;
    aspect-ratio: 1 / 1 !important;
}

/* Print Styles */
@media print {
    .sidebar, .top-header, .no-print {
        display: none !important;
    }
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
    body {
        background: white !important;
    }
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

