@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800;900&display=swap');

:root {
    /* Brand Colors */
    --brand-primary: #7c3aed;
    --brand-secondary: #2563eb;
    --brand-accent: #06b6d4;
    --brand-gradient: linear-gradient(135deg, #7c3aed 0%, #2563eb 50%, #06b6d4 100%);

    /* Semantic Colors */
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Background System */
    --bg-body: #0a0a1a;
    --bg-sidebar: #0f0f23;
    --bg-card: #141428;
    --bg-card-hover: #1a1a35;
    --bg-input: #0d0d1f;
    --bg-elevated: #1e1e3a;

    /* Border System */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --border-brand: rgba(124, 58, 237, 0.4);

    /* Text System */
    --text-white: #ffffff;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-brand: #a78bfa;

    /* Layout */
    --sidebar-w: 260px;
    --sidebar-collapsed-w: 72px;
    --topbar-h: 64px;

    /* Radii */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 20px;
    --r-2xl: 24px;
    --r-full: 9999px;

    /* Shadows */
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-brand: 0 8px 32px rgba(124, 58, 237, 0.2);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ═══════════════════════════
   RESET & BASE
   ═══════════════════════════ */
*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
}

html { scroll-behavior: smooth; }

body {
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: 'Tajawal', sans-serif;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    line-height: 1.7;
    font-size: 15px;
    background-image:
        radial-gradient(ellipse at 15% 5%, rgba(124, 58, 237, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 95%, rgba(6, 182, 212, 0.04) 0%, transparent 50%);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

/* ═══════════════════════════
   SIDEBAR
   ═══════════════════════════ */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-subtle);
    height: 100vh;
    position: fixed;
    right: 0; top: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width 0.3s var(--ease), transform 0.3s var(--ease);
    overflow: hidden;
}

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

/* Brand Header */
.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-h);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.logo-text {
    font-weight: 900;
    font-size: 1.1rem;
    color: var(--text-white);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-text::before {
    content: '';
    width: 32px; height: 32px;
    background: var(--brand-gradient);
    border-radius: var(--r-sm);
    flex-shrink: 0;
    display: block;
}

.sidebar.collapsed .logo-text span { display: none; }
.sidebar.collapsed .logo-text::before { width: 36px; height: 36px; }

.menu-toggle {
    background: transparent;
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    width: 36px; height: 36px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.menu-toggle:hover {
    color: var(--text-white);
    background: rgba(255, 255, 255, 0.06);
}

/* Nav Section */
.nav-links {
    flex: 1;
    list-style: none;
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-links::-webkit-scrollbar { width: 3px; }
.nav-links::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 10px; }

.nav-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 16px 14px 6px;
    list-style: none;
}

.sidebar.collapsed .nav-section-title { display: none; }

.nav-item { position: relative; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-secondary);
    border-radius: var(--r-md);
    transition: all 0.2s;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    position: relative;
}

.nav-link i:first-child {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.nav-link.active {
    background: rgba(124, 58, 237, 0.12);
    color: var(--text-brand);
    font-weight: 700;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    left: -12px;
    top: 50%; transform: translateY(-50%);
    width: 3px; height: 20px;
    background: var(--brand-primary);
    border-radius: 0 4px 4px 0;
}

.sidebar.collapsed .nav-link { justify-content: center; padding: 10px; }
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .submenu-arrow { display: none; }

/* Submenu */
.sub-nav {
    list-style: none;
    padding-right: 20px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s var(--ease);
}

.nav-item.open .sub-nav {
    max-height: 250px;
    padding: 2px 0 6px 0;
    padding-right: 20px;
}

.sub-nav li a {
    display: block;
    padding: 8px 14px 8px 14px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--r-sm);
    transition: all 0.2s;
    border-right: 2px solid transparent;
    margin-bottom: 1px;
}

.sub-nav li a:hover,
.sub-nav li a.active {
    color: var(--text-brand);
    background: rgba(124, 58, 237, 0.06);
    border-right-color: var(--brand-primary);
}

.submenu-arrow {
    margin-right: auto !important;
    font-size: 0.65rem !important;
    transition: transform 0.3s;
    opacity: 0.4;
}

.nav-item.open .submenu-arrow { transform: rotate(180deg); opacity: 0.8; }
.nav-item.open > .nav-link { color: var(--text-primary); }

/* Logout */
.logout-item { margin-top: auto !important; padding-top: 8px; border-top: 1px solid var(--border-subtle); }
.logout-btn { font-family: 'Tajawal', sans-serif; font-size: 0.9rem; font-weight: 600; }
.logout-btn:hover { background: rgba(239, 68, 68, 0.06) !important; }

/* ═══════════════════════════
   MAIN CONTENT
   ═══════════════════════════ */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-w);
    padding: 28px 32px;
    transition: margin-right 0.3s var(--ease);
    min-height: 100vh;
}

.sidebar.collapsed + .main-content { margin-right: var(--sidebar-collapsed-w); }

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

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-white);
}

/* ═══════════════════════════
   STAT CARDS
   ═══════════════════════════ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: 22px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.25s;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 60%; height: 100%;
    background: var(--stat-color, rgba(124, 58, 237, 0.04));
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

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

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

.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--r-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    z-index: 1;
}

.stat-info { z-index: 1; }
.stat-info .stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 2px;
}
.stat-info .stat-value {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--text-white);
    line-height: 1.2;
}

/* ═══════════════════════════
   CARDS
   ═══════════════════════════ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: 24px;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.card:hover { border-color: var(--border-default); }

.card-header {
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-subtle);
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-white);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title i { color: var(--text-brand); font-size: 0.9rem; }
.card-body { color: var(--text-secondary); }

/* ═══════════════════════════
   BUTTONS
   ═══════════════════════════ */
.btn {
    padding: 9px 18px;
    border-radius: var(--r-md);
    border: none;
    cursor: pointer;
    font-weight: 700;
    font-family: 'Tajawal', sans-serif;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    text-decoration: none;
    font-size: 0.88rem;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--brand-primary);
    color: white;
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.25);
}
.btn-primary:hover {
    background: #6d28d9;
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(124, 58, 237, 0.35);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover { background: var(--danger); color: white; border-color: var(--danger); }

.btn-success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
}
.btn-success:hover { background: var(--success); color: white; }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: var(--r-sm); }
.btn-lg { padding: 13px 26px; font-size: 0.95rem; }

/* ═══════════════════════════
   FORMS
   ═══════════════════════════ */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 7px;
}

.form-control {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    padding: 11px 14px;
    border-radius: var(--r-md);
    color: var(--text-primary);
    font-family: 'Tajawal', sans-serif;
    font-size: 0.92rem;
    transition: all 0.2s;
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
    padding-left: 32px;
}

textarea.form-control { resize: vertical; min-height: 80px; }

.form-actions { margin-top: 24px; display: flex; gap: 10px; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

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

/* ═══════════════════════════
   TABLES
   ═══════════════════════════ */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--r-lg);
    border: 1px solid var(--border-subtle);
}

table { width: 100%; border-collapse: collapse; }

th {
    padding: 12px 16px;
    text-align: right;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.88rem;
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.015); }

/* ═══════════════════════════
   BADGES
   ═══════════════════════════ */
.badge {
    padding: 4px 10px;
    border-radius: var(--r-full);
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.badge-success { background: rgba(34, 197, 94, 0.12); color: var(--success); }
.badge-warning { background: rgba(234, 179, 8, 0.12); color: var(--warning); }
.badge-danger  { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.badge-info    { background: rgba(59, 130, 246, 0.12); color: var(--info); }

/* ═══════════════════════════
   ALERTS
   ═══════════════════════════ */
.alert {
    padding: 13px 16px;
    border-radius: var(--r-md);
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    font-weight: 600;
}
.alert-success { background: rgba(34, 197, 94, 0.08); color: var(--success); border: 1px solid rgba(34, 197, 94, 0.15); }
.alert-error   { background: rgba(239, 68, 68, 0.08); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.15); }

/* ═══════════════════════════
   UPLOAD / DROPZONE
   ═══════════════════════════ */
.upload-container { margin-bottom: 1.8rem; }
.upload-label-wrapper { margin-bottom: 1rem; }
.upload-title { font-size: 1rem; font-weight: 700; color: var(--text-white); margin-bottom: 3px; display: block; }
.upload-subtitle { font-size: 0.82rem; color: var(--text-muted); display: block; }

.dropzone-area {
    background: var(--bg-input);
    border: 2px dashed var(--border-default);
    border-radius: var(--r-xl);
    height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    gap: 10px;
}
.dropzone-area:hover, .dropzone-area.dragover {
    border-color: var(--brand-primary);
    background: rgba(124, 58, 237, 0.04);
}
.dropzone-area i { font-size: 1.8rem; color: var(--text-brand); transition: transform 0.2s; }
.dropzone-area:hover i { transform: translateY(-3px); }
.dropzone-text { color: var(--text-muted); font-size: 0.88rem; font-weight: 600; pointer-events: none; }
.ipa-dropzone { height: 240px; }
.file-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; z-index: 10; }

/* ═══════════════════════════
   TABS
   ═══════════════════════════ */
.tab-btn {
    padding: 12px 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    font-family: 'Tajawal', sans-serif;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active { color: var(--text-brand); border-bottom-color: var(--brand-primary); }

.tab-content { display: none; animation: fadeUp 0.25s var(--ease); }
.tab-content.active { display: block; }

/* ═══════════════════════════
   ANIMATIONS
   ═══════════════════════════ */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════
   EMPTY STATE
   ═══════════════════════════ */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; opacity: 0.12; margin-bottom: 14px; display: block; }
.empty-state p { margin-bottom: 16px; }

/* ═══════════════════════════
   MOBILE TOPBAR
   ═══════════════════════════ */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0; right: 0; left: 0;
    height: var(--topbar-h);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 999;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
}
.mobile-topbar .logo-text { font-size: 0.95rem; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    backdrop-filter: blur(4px);
}

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

@media (max-width: 1024px) {
    .mobile-topbar { display: flex; }
    .sidebar-overlay.active { display: block; }
    .main-content { margin-right: 0 !important; margin-top: var(--topbar-h); padding: 20px; }
    .sidebar { transform: translateX(100%); }
    .sidebar.active { transform: translateX(0); box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5); }
    .row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 16px; flex-direction: column; text-align: center; gap: 10px; }
    .stat-info .stat-value { font-size: 1.25rem; }
    .page-header h1 { font-size: 1.2rem; }
    .card { padding: 18px; }
    .apps-grid { grid-template-columns: 1fr; }
    .main-content { padding: 16px 12px; }
}

@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr; }
}
