/* ============================================
   حلول AI - Dashboard Stylesheet
   Student / Teacher / Admin Dashboards
   ============================================ */

/* ============================================
   Dashboard Layout
   ============================================ */
.dashboard {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    transition: var(--transition-normal);
}

body[dir="ltr"] .sidebar {
    right: auto;
    left: 0;
    border-left: none;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.sidebar-close-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    margin-right: auto;
    transition: var(--transition-normal);
}

.sidebar-close-btn:hover {
    color: var(--text-primary);
    background: var(--bg-glass-hover);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.show {
    display: block;
}

.sidebar-header img {
    height: 70px;
    width: 70px;
    object-fit: contain;
    border-radius: 14px;
}

.sidebar-header span {
    font-size: 1.2rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.sidebar-section {
    margin-bottom: 24px;
}

/* ===== Featured section: tinted background grouping the whole section ===== */
.sidebar-section.feat-section {
    padding: 12px 10px 14px !important;
    margin-bottom: 18px !important;
    border-radius: 16px !important;
    border: 1.5px solid rgba(255,255,255,0.08) !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12), inset 0 1px 0 rgba(255,255,255,0.04) !important;
}

/* Blue — حسابي */
.sidebar-section.feat-section.feat-blue {
    background: linear-gradient(180deg, rgba(59,130,246,0.08) 0%, rgba(59,130,246,0.02) 100%) !important;
    border-color: rgba(59,130,246,0.18) !important;
    box-shadow: 0 2px 8px rgba(59,130,246,0.06) !important;
}
/* Green — الداعم النفسي */
.sidebar-section.feat-section.feat-green {
    background: linear-gradient(180deg, rgba(16,185,129,0.08) 0%, rgba(16,185,129,0.02) 100%) !important;
    border-color: rgba(16,185,129,0.18) !important;
    box-shadow: 0 2px 8px rgba(16,185,129,0.06) !important;
}
/* Pink — قسم التعلّم */
.sidebar-section.feat-section.feat-pink {
    background: linear-gradient(180deg, rgba(236,72,153,0.08) 0%, rgba(236,72,153,0.02) 100%) !important;
    border-color: rgba(236,72,153,0.18) !important;
    box-shadow: 0 2px 8px rgba(236,72,153,0.06) !important;
}
/* Purple — قسم الإنتاج */
.sidebar-section.feat-section.feat-purple {
    background: linear-gradient(180deg, rgba(139,92,246,0.08) 0%, rgba(139,92,246,0.02) 100%) !important;
    border-color: rgba(139,92,246,0.18) !important;
    box-shadow: 0 2px 8px rgba(139,92,246,0.06) !important;
}
/* Orange — أدوات التدريس */
.sidebar-section.feat-section.feat-orange {
    background: linear-gradient(180deg, rgba(245,158,11,0.08) 0%, rgba(245,158,11,0.02) 100%) !important;
    border-color: rgba(245,158,11,0.18) !important;
    box-shadow: 0 2px 8px rgba(245,158,11,0.06) !important;
}
/* Cyan — صفحاتي */
.sidebar-section.feat-section.feat-cyan {
    background: linear-gradient(180deg, rgba(6,182,212,0.08) 0%, rgba(6,182,212,0.02) 100%) !important;
    border-color: rgba(6,182,212,0.18) !important;
    box-shadow: 0 2px 8px rgba(6,182,212,0.06) !important;
}

.sidebar-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    padding: 0 12px;
    margin-bottom: 8px;
}

/* ===== Featured sidebar section titles (highlight major groups) ===== */
.sidebar-section-title-feat {
    --feat-color: #3b82f6;
    font-size: 0.92rem;
    font-weight: 800;
    text-transform: none;
    letter-spacing: 0.3px;
    color: var(--text-primary);
    padding: 9px 14px;
    margin: 4px 0 12px;
    position: relative;
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--feat-color) 16%, transparent),
        color-mix(in srgb, var(--feat-color) 5%, transparent));
    border: 1px solid color-mix(in srgb, var(--feat-color) 28%, transparent);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 9px;
    overflow: hidden;
}
.sidebar-section-title-feat::before {
    content: '';
    flex-shrink: 0;
    width: 4px;
    height: 20px;
    background: var(--feat-color);
    border-radius: 4px;
    box-shadow: 0 0 10px color-mix(in srgb, var(--feat-color) 60%, transparent);
}
.sidebar-section-title-feat i.feat-ico {
    color: var(--feat-color);
    font-size: 0.95rem;
    filter: drop-shadow(0 1px 3px color-mix(in srgb, var(--feat-color) 40%, transparent));
}
.sidebar-section-title-feat::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 100% 0%,
        color-mix(in srgb, var(--feat-color) 18%, transparent),
        transparent 60%);
    pointer-events: none;
    opacity: 0.7;
}
/* RTL: keep accent bar on the right */
body[dir="rtl"] .sidebar-section-title-feat::before {
    order: -1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition-normal);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: start;
    font-family: inherit;
}

.sidebar-link:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
}

.sidebar-link.active {
    background: rgba(14, 165, 233, 0.1);
    color: var(--accent-blue);
    font-weight: 600;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-link .badge {
    margin-right: auto;
    background: var(--accent-blue);
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: var(--radius-xl);
    font-weight: 700;
}

body[dir="ltr"] .sidebar-link .badge {
    margin-right: 0;
    margin-left: auto;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border-color);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-info .name {
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-info .role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    flex: 1;
    margin-right: 280px;
    min-height: 100vh;
    overflow-x: hidden;
    min-width: 0;
}

body[dir="ltr"] .main-content {
    margin-right: 0;
    margin-left: 280px;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
}

/* Top Bar */
.topbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

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

.topbar-title h1 {
    font-size: 1.3rem;
    font-weight: 700;
}

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

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

.topbar-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-normal);
    position: relative;
    font-size: 1rem;
}

.topbar-btn:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
    border-color: var(--border-glow);
}

.topbar-btn .notification-dot {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 8px;
    height: 8px;
    background: var(--accent-red);
    border-radius: 50%;
}

body[dir="ltr"] .topbar-btn .notification-dot {
    left: auto;
    right: 8px;
}

.topbar-search {
    position: relative;
}

.topbar-search input {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    padding-right: 40px;
    font-family: inherit;
    font-size: 0.88rem;
    color: var(--text-primary);
    width: 280px;
    outline: none;
    transition: var(--transition-normal);
}

body[dir="ltr"] .topbar-search input {
    padding-right: 16px;
    padding-left: 40px;
}

.topbar-search input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.topbar-search i {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

body[dir="ltr"] .topbar-search i {
    right: auto;
    left: 14px;
}

/* Dashboard Content */
.dash-content {
    padding: 32px;
}

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

.dash-stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: var(--transition-normal);
}

.dash-stat-card:hover {
    transform: translateY(-3px);
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.dash-stat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

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

.dash-stat-change {
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-xl);
}

.dash-stat-change.up {
    color: var(--accent-green);
    background: rgba(16, 185, 129, 0.1);
}

.dash-stat-change.down {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.1);
}

.dash-stat-value {
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 4px;
}

.dash-stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ============================================
   Dashboard Grid
   ============================================ */
.dash-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

.dash-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.dash-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.dash-card-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.dash-card-header .more-btn {
    font-size: 0.8rem;
    color: var(--accent-blue);
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    font-weight: 600;
}

/* ============================================
   Chat Interface
   ============================================ */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-message {
    display: flex;
    gap: 12px;
    max-width: 80%;
    min-width: 0;
    overflow: hidden;
    animation: fadeInUp 0.3s ease;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

body[dir="ltr"] .chat-message.user {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.chat-message.bot .chat-avatar {
    background: var(--gradient-primary);
}

.chat-message.user .chat-avatar {
    background: var(--gradient-secondary);
}

.chat-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    font-size: 0.9rem;
    line-height: 1.7;
    min-width: 0;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-message.user .chat-bubble {
    background: rgba(14, 165, 233, 0.1);
    border-color: rgba(14, 165, 233, 0.2);
}

.chat-bubble .time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 8px;
    display: block;
}

.chat-input-area {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-input-area input {
    flex: 1;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    outline: none;
    transition: var(--transition-normal);
}

.chat-input-area input:focus {
    border-color: var(--accent-blue);
}

.chat-input-area .send-btn {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    background: var(--gradient-primary);
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-input-area .send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.4);
}

.chat-input-actions {
    display: flex;
    gap: 8px;
}

.chat-action-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.chat-action-btn:hover {
    color: var(--accent-blue);
    border-color: var(--border-glow);
}

/* ============================================
   Quick Actions
   ============================================ */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.quick-action {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-normal);
    border: none;
    font-family: inherit;
    color: var(--text-secondary);
    text-align: start;
    width: 100%;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
}

.quick-action:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-glow);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.quick-action i {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

/* ============================================
   Activity List
   ============================================ */
.activity-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    transition: var(--transition-normal);
}

.activity-item:hover {
    background: var(--bg-glass-hover);
}

.activity-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.activity-info {
    flex: 1;
}

.activity-info .title {
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.activity-info .time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ============================================
   Data Table
   ============================================ */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: start;
    padding: 14px 16px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 14px 16px;
    font-size: 0.88rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.data-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.data-table .user-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.data-table .user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.data-table .user-name {
    font-weight: 600;
}

.data-table .user-email {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-xl);
    font-size: 0.75rem;
    font-weight: 700;
}

.status-badge.active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-green);
}

.status-badge.inactive {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-red);
}

.status-badge.pending {
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent-orange);
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Role Badge */
.role-badge {
    display: inline-flex;
    padding: 4px 12px;
    border-radius: var(--radius-xl);
    font-size: 0.75rem;
    font-weight: 700;
}

.role-badge.student {
    background: rgba(14, 165, 233, 0.1);
    color: var(--accent-blue);
}

.role-badge.teacher {
    background: rgba(139, 92, 246, 0.1);
    color: var(--accent-purple);
}

.role-badge.admin {
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent-orange);
}

/* Action Buttons */
.action-btns {
    display: flex;
    gap: 6px;
}

.action-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

.action-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-glow);
}

.action-btn.edit:hover {
    color: var(--accent-blue);
}

.action-btn.delete:hover {
    color: var(--accent-red);
}

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

.pagination button {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-normal);
    font-family: inherit;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pagination button:hover,
.pagination button.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
    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);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: fadeInUp 0.3s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

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

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-normal);
}

.modal-close:hover {
    color: var(--accent-red);
    border-color: rgba(239, 68, 68, 0.3);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

/* ============================================
   Dashboard Page Sections
   ============================================ */
.dash-page {
    display: none;
    content-visibility: hidden;
}

.dash-page.active {
    display: block;
    content-visibility: visible;
}

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

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

@media (max-width: 768px) {

    /* ===== Global Mobile Overflow Fix ===== */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* ===== Sidebar ===== */
    .sidebar {
        width: 100%;
        max-width: 100vw;
        transform: translateX(100%);
    }

    body[dir="ltr"] .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    body[dir="ltr"] .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-right: 0;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    body[dir="ltr"] .main-content {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-close-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ===== Topbar ===== */
    .topbar {
        padding: 10px 14px;
        gap: 8px;
        flex-wrap: nowrap;
    }

    /* Hide search on mobile - takes too much space */
    .topbar-search {
        display: none;
    }

    .topbar-title h1 {
        font-size: 1rem;
    }

    .topbar-title p {
        display: none;
    }

    .topbar-right {
        gap: 8px;
    }

    .topbar-left {
        gap: 8px;
    }

    /* ===== Dashboard Content ===== */
    .dash-content {
        padding: 14px;
        overflow-x: hidden;
        max-width: 100%;
    }

    .dash-stats {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }

    .dash-stat-card {
        padding: 16px;
    }

    .dash-stat-value {
        font-size: 1.6rem;
    }

    .quick-actions {
        grid-template-columns: 1fr;
    }

    .chat-message {
        max-width: 95%;
    }

    /* ===== Chat Input on Mobile ===== */
    .chat-input-area {
        padding: 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .chat-input-actions {
        order: 3;
    }

    /* ===== Dash Card ===== */
    .dash-card {
        padding: 16px;
        overflow-x: hidden;
        max-width: 100%;
    }

    .dash-card-header {
        margin-bottom: 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .dash-card-header h3 {
        font-size: 0.95rem;
    }

    /* ===== Form Elements ===== */
    .dash-content .form-group,
    .dash-content .auth-form {
        max-width: 100% !important;
        width: 100% !important;
    }

    .dash-content textarea,
    .dash-content input[type="text"],
    .dash-content input[type="email"],
    .dash-content input[type="number"],
    .dash-content input[type="url"],
    .dash-content select,
    .dash-content .form-input {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ===== Video / Image / Media ===== */
    .dash-content video,
    .dash-content img,
    .dash-content canvas {
        max-width: 100% !important;
        height: auto !important;
    }

    .dash-content video {
        width: 100% !important;
    }

    /* ===== Flex/Grid overflow protection ===== */
    .dash-content [style*="display:flex"],
    .dash-content [style*="display: flex"] {
        flex-wrap: wrap;
    }

    .dash-content [style*="display:grid"],
    .dash-content [style*="display: grid"] {
        max-width: 100%;
    }

    /* ===== Buttons row on mobile ===== */
    .dash-content [style*="gap:8px"],
    .dash-content [style*="gap: 8px"] {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .topbar {
        padding: 10px 12px;
    }

    .dash-content {
        padding: 10px;
    }

    .dash-stats {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .dash-card {
        padding: 12px;
    }

    .dash-card-header h3 {
        font-size: 0.9rem;
    }

    .topbar-title h1 {
        font-size: 0.9rem;
    }

    /* Make buttons full-width on very small screens */
    .dash-content .btn {
        width: 100%;
        justify-content: center;
    }

    /* Fix stat cards to single column */
    .dash-stat-value {
        font-size: 1.4rem;
    }

    .sidebar-header span {
        font-size: 1rem;
    }

    /* ===== Additional small screen fixes ===== */
    .dash-content [style*="max-width:300px"],
    .dash-content [style*="max-width: 300px"] {
        max-width: 100% !important;
    }

    .dash-content label[style*="padding:40px"],
    .dash-content label[style*="padding: 40px"] {
        padding: 20px !important;
    }

    /* Fix inline grids that may overflow */
    .dash-content [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}
/* ── Study Assistant Responsive Grid ── */
.sc-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
}
@media (max-width: 768px) {
    .sc-grid {
        grid-template-columns: 1fr !important;
    }
    #page-study .dash-card {
        margin-bottom: 12px;
    }
    #scMessages {
        height: 320px !important;
        min-height: 220px;
    }
    /* Fix chat input area on mobile */
    #page-study textarea#scInput {
        font-size: 0.85rem;
    }
    /* Fix history cards wrapping */
    #scHistoryContainer .sessions-grid {
        grid-template-columns: 1fr !important;
    }
}
@media (max-width: 480px) {
    .sc-grid {
        gap: 10px !important;
    }
    #scMessages {
        height: 260px !important;
    }
}

/* ── TTS Voice Pages Responsive ── */
@media (max-width: 768px) {
    #page-voicegen .sc-grid,
    #page-voicegen2 .sc-grid {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    #page-voicegen .sc-grid > div,
    #page-voicegen2 .sc-grid > div {
        width: 100% !important;
        min-width: 0 !important;
        display: block !important;
    }

    #page-voicegen .dash-card,
    #page-voicegen2 .dash-card {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    #page-voicegen .dash-card-header,
    #page-voicegen2 .dash-card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 6px;
    }

    #page-voicegen .dash-card-header .badge,
    #page-voicegen2 .dash-card-header .badge {
        align-self: flex-start;
        font-size: 0.7rem;
    }

    #page-voicegen p,
    #page-voicegen2 p {
        font-size: 0.82rem !important;
        line-height: 1.6;
    }

    #page-voicegen [style*="grid-template-columns:1fr 1fr"],
    #page-voicegen [style*="grid-template-columns: 1fr 1fr"],
    #page-voicegen2 [style*="grid-template-columns:1fr 1fr"],
    #page-voicegen2 [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    #page-voicegen textarea,
    #page-voicegen input[type="text"],
    #page-voicegen select,
    #page-voicegen2 textarea,
    #page-voicegen2 input[type="text"],
    #page-voicegen2 select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 0.88rem !important;
    }

    #page-voicegen input[type="range"],
    #page-voicegen2 input[type="range"] {
        width: 100% !important;
    }

    #page-voicegen audio,
    #page-voicegen2 audio {
        width: 100% !important;
        max-width: 100% !important;
    }

    #page-voicegen [style*="padding:24px"],
    #page-voicegen [style*="padding: 24px"],
    #page-voicegen2 [style*="padding:24px"],
    #page-voicegen2 [style*="padding: 24px"] {
        padding: 14px !important;
    }

    #page-voicegen #ttsResultState [style*="display:flex"][style*="gap:10px"],
    #page-voicegen2 #tts2ResultState [style*="display:flex"][style*="gap:10px"] {
        flex-direction: column;
    }

    #page-voicegen #ttsResultState [style*="display:flex"][style*="gap:10px"] button,
    #page-voicegen2 #tts2ResultState [style*="display:flex"][style*="gap:10px"] button {
        width: 100%;
    }

    #page-voicegen button[id$="GenerateBtn"],
    #page-voicegen2 button[id$="GenerateBtn"] {
        padding: 12px !important;
        font-size: 0.92rem !important;
    }
}

@media (max-width: 480px) {
    #page-voicegen .dash-card,
    #page-voicegen2 .dash-card {
        padding: 10px !important;
    }

    #page-voicegen textarea,
    #page-voicegen2 textarea {
        padding: 10px !important;
        font-size: 0.85rem !important;
        max-height: 120px;
    }

    #page-voicegen [style*="padding:50px"],
    #page-voicegen [style*="padding: 50px"],
    #page-voicegen2 [style*="padding:50px"],
    #page-voicegen2 [style*="padding: 50px"] {
        padding: 24px 12px !important;
    }

    #page-voicegen [style*="gap:5px"] button,
    #page-voicegen2 [style*="gap:5px"] button {
        font-size: 0.68rem !important;
        padding: 3px 7px !important;
    }

    #page-voicegen p,
    #page-voicegen2 p {
        font-size: 0.78rem !important;
    }

    #page-voicegen .dash-card-header h3,
    #page-voicegen2 .dash-card-header h3 {
        font-size: 0.88rem;
    }
}

/* ============================================
   Light Theme Overrides
   ============================================ */
/* ============================================
   LTR (English) Layout Fixes
   ============================================ */
body[dir="ltr"] .sidebar-close-btn {
    margin-right: 0;
    margin-left: auto;
}

body[dir="ltr"] .sidebar-link i,
body[dir="ltr"] .sidebar-section-title i {
    margin-left: 0;
    margin-right: 8px;
}

body[dir="ltr"] .dash-card-header h3 i {
    margin-left: 0 !important;
    margin-right: 8px !important;
}

body[dir="ltr"] .dash-stat-change i {
    margin-left: 0;
    margin-right: 4px;
}

body[dir="ltr"] .sidebar-user-avatar {
    margin-left: 0;
    margin-right: 0;
}

body[dir="ltr"] .sidebar-footer .fa-sign-out-alt {
    transform: scaleX(-1);
}

body[dir="ltr"] .chat-input-area {
    direction: ltr;
}

body[dir="ltr"] .form-group label i {
    margin-left: 0 !important;
    margin-right: 6px !important;
}

body[dir="ltr"] .topbar-right,
body[dir="ltr"] .topbar-left {
    direction: ltr;
}

body[dir="ltr"] .users-table th {
    text-align: left;
}

body[dir="ltr"] .bulk-bar .bulk-actions {
    margin-right: 0;
    margin-left: auto;
}

body[dir="ltr"] .filter-btn .count {
    margin-right: 0;
    margin-left: 4px;
}

body[dir="ltr"] .activity-info {
    text-align: left;
}

body[dir="ltr"] .sidebar-user {
    direction: ltr;
}

[data-theme="light"] .data-table td {
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .data-table tr:hover td {
    background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .dash-stat-card {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .dash-card {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .chat-bubble {
    background: rgba(255, 255, 255, 0.9);
}

[data-theme="light"] .sidebar {
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .topbar {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .modal-overlay {
    background: rgba(0, 0, 0, 0.4);
}

[data-theme="light"] #themeToggleBtn {
    color: var(--accent-orange);
}

[data-theme="light"] #themeToggleBtn:hover {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.3);
}


/* ===== GPT Services Chat UI ===== */
.gpt-chat-grid {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 16px;
    min-height: 600px;
}
@media (max-width: 900px) {
    .gpt-chat-grid { grid-template-columns: 1fr; }
    .gpt-sessions-card { max-height: 200px; }
}
.gpt-sessions-card {
    max-height: 600px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.gpt-sessions-list {
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}
.gpt-session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}
.gpt-session-item:hover {
    background: rgba(16, 185, 129, 0.08);
    color: var(--text-primary);
}
.gpt-session-item.active {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    font-weight: 600;
}
.gpt-session-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gpt-session-del {
    opacity: 0;
    padding: 2px 6px;
    border-radius: 4px;
    color: #ef4444;
    font-size: 0.75rem;
    transition: opacity 0.2s;
}
.gpt-session-item:hover .gpt-session-del { opacity: 1; }
.gpt-chat-card {
    display: flex;
    flex-direction: column;
    min-height: 600px;
    max-height: 80vh;
}
.gpt-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.gpt-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    padding: 40px 20px;
    text-align: center;
}
.gpt-empty i { font-size: 3rem; margin-bottom: 12px; opacity: 0.3; }
.gpt-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.7;
    font-size: 0.92rem;
    word-wrap: break-word;
}
.gpt-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    border-bottom-right-radius: 4px;
}
[dir="rtl"] .gpt-msg.user, body.rtl .gpt-msg.user {
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}
.gpt-msg.assistant {
    align-self: flex-start;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.gpt-msg.typing {
    background: var(--bg-glass);
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
    font-style: italic;
}
.gpt-msg pre {
    background: rgba(0,0,0,0.25);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 0.85rem;
}
.gpt-msg code {
    background: rgba(0,0,0,0.15);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
}
.gpt-msg pre code { background: transparent; padding: 0; }
.gpt-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-color);
    align-items: flex-end;
}
.gpt-input-bar textarea {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 160px;
}
.gpt-input-bar .btn {
    min-width: 52px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}


/* ============================================
   Option-card rows (fix uneven & overstretched cards)
   Switches the inline flex containers to a flex layout
   with a SENSIBLE max-width per option so cards don't
   stretch across half the screen.
   ============================================ */
.dash-content .form-group > div[style*="flex-wrap: wrap"],
.dash-content .form-group > div[style*="flex-wrap:wrap"] {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 12px !important;
    justify-content: flex-start !important;
    align-items: stretch !important;
}
.dash-content .form-group > div[style*="flex-wrap: wrap"] > label,
.dash-content .form-group > div[style*="flex-wrap:wrap"] > label {
    flex: 1 1 160px !important;
    max-width: 220px !important;
    min-width: 140px !important;
    width: auto !important;
    display: block !important;
    box-sizing: border-box !important;
}
.dash-content .form-group > div[style*="flex-wrap: wrap"] > label > div,
.dash-content .form-group > div[style*="flex-wrap:wrap"] > label > div {
    height: 100%;
    box-sizing: border-box;
}

/* Wider rows (e.g. the 5-options style picker) can use slightly tighter cards */
.dash-content .form-group > div[style*="flex-wrap: wrap"] > label:nth-child(n+5),
.dash-content .form-group > div[style*="flex-wrap:wrap"] > label:nth-child(n+5) {
    flex-basis: 130px !important;
}

@media (max-width: 600px) {
    .dash-content .form-group > div[style*="flex-wrap: wrap"] > label,
    .dash-content .form-group > div[style*="flex-wrap:wrap"] > label {
        flex: 1 1 calc(50% - 6px) !important;
        max-width: none !important;
        min-width: 0 !important;
    }
}
