/* Smart Water Dashboard - Main Stylesheet */
/* Google Font Cairo for Arabic */
:root {
    --primary: #2563eb; --primary-light: #3b82f6; --primary-dark: #1d4ed8;
    --bg: #f0f4f8; --bg-card: #ffffff; --bg-sidebar: #0f172a;
    --text: #1e293b; --text-secondary: #64748b; --text-light: #94a3b8;
    --border: #e2e8f0; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1); --shadow-lg: 0 10px 25px rgba(0,0,0,.12);
    --radius: 12px; --radius-sm: 8px;
    --success: #10b981; --warning: #f59e0b; --danger: #ef4444;
    --sidebar-w: 260px; --topbar-h: 64px; --mobile-nav-h: 64px;
    --font-ar: 'Cairo', sans-serif; --font-en: 'Inter', sans-serif;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font-ar); background: var(--bg); color: var(--text); line-height: 1.6; overflow-x: hidden; }
html[dir="ltr"] body { font-family: var(--font-en); }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: .95rem; max-width: 100%; }
img, canvas, svg { max-width: 100%; }

/* ── Auth Screen ── */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #2563eb 100%); padding: 20px; position: relative; overflow: hidden; }
.auth-screen::before { content: ''; position: absolute; width: 400px; height: 400px; border-radius: 50%; background: rgba(37,99,235,.15); top: -100px; right: -100px; }
.auth-screen::after { content: ''; position: absolute; width: 300px; height: 300px; border-radius: 50%; background: rgba(37,99,235,.1); bottom: -80px; left: -80px; }
.auth-container { background: rgba(255,255,255,.05); backdrop-filter: blur(20px); border: 1px solid rgba(255,255,255,.1); border-radius: 20px; padding: 40px; width: 100%; max-width: 420px; position: relative; z-index: 1; }
.auth-lang-switcher { position: absolute; top: 16px; right: 16px; }
html[dir="ltr"] .auth-lang-switcher { right: auto; left: 16px; }
.auth-header { text-align: center; margin-bottom: 32px; }
.auth-logo { width: 64px; height: 64px; border-radius: 16px; background: linear-gradient(135deg, var(--primary), #60a5fa); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; font-size: 28px; color: #fff; box-shadow: 0 8px 24px rgba(37,99,235,.3); }
.auth-header h1 { color: #fff; font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.auth-header p { color: rgba(255,255,255,.6); font-size: .85rem; }
.auth-form .form-group { margin-bottom: 18px; }
.auth-form label { display: block; color: rgba(255,255,255,.8); font-size: .85rem; font-weight: 500; margin-bottom: 6px; }
.input-icon { position: relative; }
.input-icon i { position: absolute; top: 50%; transform: translateY(-50%); color: var(--text-light); font-size: .9rem; }
html[dir="rtl"] .input-icon i { right: 14px; }
html[dir="ltr"] .input-icon i { left: 14px; }
.input-icon input, .input-icon select { width: 100%; padding: 12px 14px 12px 42px; border: 1px solid rgba(255,255,255,.15); border-radius: var(--radius-sm); background: rgba(255,255,255,.08); color: #fff; transition: all .3s; }
html[dir="rtl"] .input-icon input, html[dir="rtl"] .input-icon select { padding: 12px 42px 12px 14px; }
.input-icon input:focus, .input-icon select:focus { outline: none; border-color: var(--primary); background: rgba(255,255,255,.12); box-shadow: 0 0 0 3px rgba(37,99,235,.2); }
.input-icon input::placeholder { color: rgba(255,255,255,.3); }
.input-icon select option { background: var(--bg-sidebar); color: #fff; }
.btn { padding: 12px 24px; border-radius: var(--radius-sm); font-weight: 600; font-size: .95rem; transition: all .3s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,.3); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(37,99,235,.4); }
.btn-full { width: 100%; }
.auth-switch { text-align: center; color: rgba(255,255,255,.6); font-size: .85rem; margin-top: 16px; }
.auth-switch a { color: var(--primary-light); font-weight: 600; }
.auth-error { background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; padding: 10px 14px; border-radius: var(--radius-sm); text-align: center; font-size: .85rem; margin-top: 12px; }

/* ── App Layout ── */
.app-screen { display: flex; min-height: 100vh; min-width: 0; }
.sidebar { width: var(--sidebar-w); background: var(--bg-sidebar); color: #fff; position: fixed; top: 0; bottom: 0; z-index: 100; display: flex; flex-direction: column; transition: transform .3s, left .3s ease, right .3s ease; overflow-y: auto; }
html[dir="rtl"] .sidebar { right: 0 !important; left: auto !important; }
html[dir="ltr"] .sidebar { left: 0 !important; right: auto !important; }
.sidebar-header { padding: 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-logo { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, var(--primary), #60a5fa); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.sidebar-brand span { font-size: .95rem; font-weight: 700; display: block; }
.sidebar-brand small { font-size: .7rem; color: var(--text-light); }
.sidebar-nav { flex: 1; padding: 12px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: var(--radius-sm); color: var(--text-light); font-size: .9rem; font-weight: 500; margin-bottom: 4px; transition: all .2s; position: relative; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,.3); }
.nav-item i { width: 20px; text-align: center; font-size: .95rem; }
.nav-badge { background: var(--danger); color: #fff; font-size: .7rem; padding: 2px 7px; border-radius: 10px; margin-inline-start: auto; }
.nav-logout { margin-top: auto; }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 10px; }
.lang-switcher select { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.15); border-radius: 6px; padding: 6px 10px; font-size: .8rem; font-weight: 600; }
.lang-switcher select option { background: var(--bg-sidebar); color: #fff; }
.btn-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--text-light); transition: all .2s; font-size: .95rem; }
.btn-icon:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ── Main Content ── */
.main-content { flex: 1; display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }
html[dir="rtl"] .main-content { margin-right: var(--sidebar-w); margin-left: 0; }
html[dir="ltr"] .main-content { margin-left: var(--sidebar-w); margin-right: 0; }
.topbar { height: var(--topbar-h); background: var(--bg-card); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow); min-width: 0; }
.page-title { font-size: 1.15rem; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { display: none; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; margin-inline-start: auto; }
.notification-btn { position: relative; }
.notif-badge { position: absolute; top: 2px; right: 2px; background: var(--danger); color: #fff; font-size: .65rem; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; }
html[dir="rtl"] .notif-badge { right: auto; left: 2px; }
.user-menu { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer; transition: background .2s; min-width: 0; }
.user-menu:hover { background: var(--bg); }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), #60a5fa); display: flex; align-items: center; justify-content: center; color: #fff; font-size: .85rem; }
.user-name { font-size: .85rem; font-weight: 600; display: block; }
.user-email { font-size: .75rem; color: var(--text-secondary); }
.user-dropdown { position: absolute; top: calc(var(--topbar-h) - 4px); background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); min-width: 180px; z-index: 60; overflow: hidden; }
html[dir="rtl"] .user-dropdown { left: 24px; }
html[dir="ltr"] .user-dropdown { right: 24px; }
.user-dropdown a { display: flex; align-items: center; gap: 10px; padding: 10px 16px; font-size: .85rem; transition: background .2s; }
.user-dropdown a:hover { background: var(--bg); }

/* ── Page Container ── */
.page-container { padding: 24px; flex: 1; min-width: 0; width: 100%; }
.page { display: none; animation: fadeIn .3s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Dashboard Cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg-card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); transition: transform .2s, box-shadow .2s; position: relative; overflow: hidden; min-width: 0; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.stat-card-title { font-size: .8rem; color: var(--text-secondary); font-weight: 500; min-width: 0; }
.stat-card-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1rem; }
.icon-blue { background: rgba(37,99,235,.1); color: var(--primary); }
.icon-green { background: rgba(16,185,129,.1); color: var(--success); }
.icon-orange { background: rgba(245,158,11,.1); color: var(--warning); }
.icon-red { background: rgba(239,68,68,.1); color: var(--danger); }
.stat-card-value { font-size: 1.8rem; font-weight: 700; margin-bottom: 4px; overflow-wrap: anywhere; }
.stat-card-unit { font-size: .85rem; color: var(--text-secondary); font-weight: 400; }
.stat-card-change { font-size: .78rem; font-weight: 500; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.stat-card-change.positive { color: var(--success); }
.stat-card-change.negative { color: var(--danger); }
.stat-card-subtitle { font-size: .75rem; color: var(--text-light); }

/* ── Charts & Content Grid ── */
.content-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; margin-bottom: 24px; }
.card { background: var(--bg-card); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); min-width: 0; }
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-title i { color: var(--primary); }
.chart-container { position: relative; height: 260px; }

/* ── Recommendations ── */
.rec-list { list-style: none; }
.rec-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: .88rem; line-height: 1.5; }
.rec-item:last-child { border-bottom: none; }
.rec-item i { color: var(--primary); margin-top: 3px; flex-shrink: 0; }
.view-all-link { display: inline-block; margin-top: 12px; color: var(--primary); font-size: .85rem; font-weight: 600; }
.view-all-link:hover { text-decoration: underline; }

/* ── Alerts Card ── */
.alert-item { padding: 12px; border-radius: var(--radius-sm); margin-bottom: 8px; font-size: .85rem; display: flex; gap: 10px; align-items: flex-start; }
.alert-item.warning { background: rgba(245,158,11,.08); border-left: 3px solid var(--warning); }
.alert-item.critical { background: rgba(239,68,68,.08); border-left: 3px solid var(--danger); }
.alert-item.info { background: rgba(37,99,235,.08); border-left: 3px solid var(--primary); }
html[dir="rtl"] .alert-item { border-left: none; }
html[dir="rtl"] .alert-item.warning { border-right: 3px solid var(--warning); }
html[dir="rtl"] .alert-item.critical { border-right: 3px solid var(--danger); }
html[dir="rtl"] .alert-item.info { border-right: 3px solid var(--primary); }
.alert-icon { font-size: 1rem; flex-shrink: 0; margin-top: 2px; }
.alert-item.warning .alert-icon { color: var(--warning); }
.alert-item.critical .alert-icon { color: var(--danger); }
.alert-item.info .alert-icon { color: var(--primary); }
.alert-time { font-size: .75rem; color: var(--text-light); margin-top: 4px; }

/* ── Monthly Card ── */
.monthly-card { display: flex; align-items: center; gap: 20px; min-width: 0; }
.monthly-value { font-size: 2rem; font-weight: 700; overflow-wrap: anywhere; }
.monthly-unit { font-size: .9rem; color: var(--text-secondary); }
.monthly-icon { font-size: 2.5rem; color: var(--primary); opacity: .3; }

/* ── Bottom Grid ── */
.bottom-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }

/* ── Status badge ── */
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 20px; font-size: .8rem; font-weight: 600; }
.status-normal { background: rgba(16,185,129,.1); color: var(--success); }
.status-high { background: rgba(245,158,11,.1); color: var(--warning); }
.status-critical { background: rgba(239,68,68,.1); color: var(--danger); }

/* ── Add Reading Form ── */
.form-card { max-width: 560px; }
.form-card .form-group { margin-bottom: 20px; }
.form-card label { display: block; font-size: .85rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-card input, .form-card select { width: 100%; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); color: var(--text); transition: all .3s; }
.form-card input:focus, .form-card select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.reading-history { margin-top: 24px; }
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.reading-history table { width: 100%; border-collapse: collapse; }
.reading-history th, .reading-history td { padding: 10px 14px; text-align: start; font-size: .85rem; border-bottom: 1px solid var(--border); }
.reading-history th { font-weight: 600; color: var(--text-secondary); background: var(--bg); }

/* ── Reports ── */
.report-filters { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-btn { padding: 8px 18px; border-radius: 20px; font-size: .82rem; font-weight: 600; background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); transition: all .2s; }
.filter-btn.active, .filter-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.report-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 24px; }
.report-stat { background: var(--bg); border-radius: var(--radius-sm); padding: 16px; text-align: center; min-width: 0; }
.report-stat-value { font-size: 1.4rem; font-weight: 700; color: var(--primary); overflow-wrap: anywhere; }
.report-stat-label { font-size: .78rem; color: var(--text-secondary); margin-top: 4px; }

/* ── Settings Page ── */
.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; max-width: 800px; }
.settings-section .card { height: 100%; }
.settings-section .card-title { border-bottom: 1px solid var(--border); padding-bottom: 12px; }

/* ── Alerts Page ── */
.alerts-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.alerts-list .alert-item { cursor: pointer; transition: transform .15s; }
.alerts-list .alert-item:hover { transform: translateX(4px); }
html[dir="rtl"] .alerts-list .alert-item:hover { transform: translateX(-4px); }
.alert-item.unread { font-weight: 600; }

/* ── Recommendations Page ── */
.recs-full .rec-item { padding: 14px 0; font-size: .92rem; }
.ai-analyze-btn { margin-bottom: 20px; }

/* ── Toast ── */
.toast { position: fixed !important; bottom: -100px !important; left: 50%; transform: translateX(-50%) !important; background: var(--bg-sidebar); color: #fff; padding: 12px 24px; border-radius: var(--radius-sm); font-size: .85rem; z-index: 99999 !important; transition: bottom 0.4s ease, opacity 0.4s ease, visibility 0.4s ease; box-shadow: var(--shadow-lg); width: max-content; max-width: calc(100vw - 32px); text-align: center; opacity: 0; visibility: hidden; pointer-events: none; }
.toast.show { bottom: 80px !important; opacity: 1 !important; visibility: visible !important; pointer-events: auto !important; }

/* ── Overlay ── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; backdrop-filter: blur(2px); }

/* ── Mobile Nav ── */
.mobile-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--bg-card); border-top: 1px solid var(--border); z-index: 80; box-shadow: 0 -2px 10px rgba(0,0,0,.06); }
.mobile-nav { display: none; align-items: center; justify-content: space-around; }
.mobile-nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: .65rem; color: var(--text-light); padding: 8px 4px; transition: color .2s; text-decoration: none; min-width: 0; flex: 1; height: var(--mobile-nav-h); }
.mobile-nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-nav-item i { font-size: 1.15rem; }
.mobile-nav-item.active { color: var(--primary); }
.mobile-more-menu { position: fixed; bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px)); left: 0; right: 0; background: var(--bg-card); border-top: 1px solid var(--border); z-index: 79; box-shadow: var(--shadow-lg); padding: 8px; }
.mobile-more-menu a { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: .88rem; }
.mobile-more-menu a:hover { background: var(--bg); }

/* ── Loading Spinner ── */
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-light); }
.empty-state i { font-size: 3rem; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: .9rem; }

/* ── Responsive ── */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .content-grid { grid-template-columns: 1fr; }
    .report-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .settings-grid { grid-template-columns: 1fr; }
    .bottom-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    :root { --topbar-h: 58px; --mobile-nav-h: 66px; }
    html { font-size: 14px; }
    html[dir="rtl"] .sidebar { right: -260px !important; left: auto !important; transform: none !important; }
    html[dir="ltr"] .sidebar { left: -260px !important; right: auto !important; transform: none !important; }
    html[dir="rtl"] .sidebar.open { right: 0 !important; left: auto !important; transform: none !important; }
    html[dir="ltr"] .sidebar.open { left: 0 !important; right: auto !important; transform: none !important; }
    html[dir="rtl"] .main-content, html[dir="ltr"] .main-content { margin-right: 0 !important; margin-left: 0 !important; }
    .menu-toggle { display: flex; }
    .mobile-nav { display: flex; }
    .page-container { padding: 16px; padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 18px); }
    .topbar { padding: 0 14px; gap: 10px; }
    .page-title { font-size: 1rem; }
    .topbar-right { gap: 6px; }
    .btn-icon { width: 34px; height: 34px; }
    .user-menu { padding: 4px; }
    .user-avatar { width: 34px; height: 34px; }
    .user-info { display: none; }
    .user-menu .fa-chevron-down { display: none; }
    .user-dropdown { top: calc(var(--topbar-h) + 4px); max-width: calc(100vw - 32px); }
    html[dir="rtl"] .user-dropdown { left: 16px; }
    html[dir="ltr"] .user-dropdown { right: 16px; }
    .auth-screen { align-items: flex-start; padding: 24px 14px; min-height: 100svh; }
    .auth-container { padding: 28px 20px; border-radius: 16px; }
    .auth-header { margin-bottom: 24px; }
    .auth-logo { width: 56px; height: 56px; font-size: 24px; }
    .auth-header h1 { font-size: 1.12rem; line-height: 1.45; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat-card { padding: 14px; }
    .stat-card-header { gap: 8px; margin-bottom: 10px; }
    .stat-card-title { line-height: 1.35; }
    .stat-card-value { font-size: 1.4rem; }
    .stat-card-unit { display: inline-block; font-size: .74rem; }
    .stat-card-change, .stat-card-subtitle { font-size: .72rem; line-height: 1.45; }
    .stat-card-icon { width: 32px; height: 32px; font-size: .85rem; }
    .card { padding: 18px; border-radius: 10px; }
    .card-title { font-size: .95rem; line-height: 1.4; }
    .chart-container { height: 230px; }
    .monthly-card { align-items: flex-start; gap: 12px; }
    .monthly-value { font-size: 1.55rem; }
    .monthly-icon { font-size: 2rem; }
    .report-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
    .filter-btn { width: 100%; padding: 8px 10px; border-radius: 10px; }
    .reading-history table { min-width: 430px; }
    .alerts-header { align-items: stretch; }
    .alerts-header .btn { width: 100%; }
    .toast { bottom: -100px !important; }
    .toast.show { bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 14px) !important; }
}

@media (max-width: 480px) {
    :root { --mobile-nav-h: 62px; }
    body { background: #f6f8fb; }
    .page-container { padding: 12px; padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 16px); }
    .topbar { padding: 0 10px; }
    .page-title { max-width: 46vw; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .stat-card { padding: 12px; border-radius: 10px; }
    .stat-card-header { align-items: center; }
    .stat-card-value { font-size: 1.18rem; line-height: 1.25; }
    .stat-card-icon { width: 30px; height: 30px; border-radius: 8px; }
    .card { padding: 14px; border-radius: 10px; }
    .chart-container, .card .chart-container[style] { height: 220px !important; }
    .report-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .report-stat { padding: 12px 8px; }
    .report-stat-value { font-size: 1.12rem; }
    .report-stat-label { font-size: .72rem; line-height: 1.35; }
    .form-card { max-width: none; }
    .form-card input, .form-card select, .btn { min-height: 42px; }
    .mobile-nav-item { font-size: .6rem; padding-inline: 2px; }
    .mobile-nav-item i { font-size: 1rem; }
    .mobile-more-menu { padding: 6px; }
    .mobile-more-menu a { padding: 11px 12px; }
}

@media (max-width: 360px) {
    .stats-grid, .report-stats { grid-template-columns: 1fr; }
    .page-title { max-width: 40vw; }
    .mobile-nav-item span { font-size: .56rem; }
}

/* ── Debug and Password Reset link ── */
.auth-debug-link {
    margin-top: 14px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 0.85rem;
    text-align: start;
    line-height: 1.5;
}

/* ── Chat Page ── */
.chat-card {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-h) - 48px - 24px);
    padding: 0;
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}

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

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.2rem;
    box-shadow: 0 4px 10px rgba(37,99,235,.2);
}

.chat-title {
    font-size: 1.05rem;
    font-weight: 700;
}

.btn-clear-chat {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-clear-chat:hover {
    background: var(--bg);
    color: var(--danger);
    border-color: rgba(239,68,68,0.2);
}

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

.chat-message {
    display: flex;
    gap: 12px;
    max-width: 75%;
    align-items: flex-start;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.bot {
    align-self: flex-start;
}

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

.chat-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.chat-message.bot .chat-msg-avatar {
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    color: #fff;
    box-shadow: 0 3px 8px rgba(37,99,235,.15);
}

.chat-message.user .chat-msg-avatar {
    background: var(--bg-sidebar);
    color: #fff;
}

.chat-msg-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.55;
    box-shadow: var(--shadow);
}

.chat-message.bot .chat-msg-content {
    background: var(--bg-card);
    color: var(--text);
    border-top-left-radius: 4px;
    border: 1px solid var(--border);
}

html[dir="rtl"] .chat-message.bot .chat-msg-content {
    border-top-left-radius: 16px;
    border-top-right-radius: 4px;
}

.chat-message.user .chat-msg-content {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    border-top-right-radius: 4px;
}

html[dir="rtl"] .chat-message.user .chat-msg-content {
    border-top-right-radius: 16px;
    border-top-left-radius: 4px;
}

/* Markdown styling inside chatbot reply */
.chat-msg-content ul, .chat-msg-content ol {
    margin-top: 6px;
    margin-bottom: 6px;
    padding-inline-start: 20px;
}

.chat-msg-content li {
    margin-bottom: 4px;
}

.chat-msg-content strong {
    font-weight: 700;
}

/* Suggestions area */
.chat-suggestions {
    display: flex;
    gap: 8px;
    padding: 12px 24px;
    background: #f8fafc;
    overflow-x: auto;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    scrollbar-width: none;
}

.chat-suggestions::-webkit-scrollbar {
    display: none;
}

.suggestion-chip {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: all 0.2s;
    cursor: pointer;
}

.suggestion-chip:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    transform: translateY(-1px);
}

/* Input Form */
.chat-input-form {
    display: flex;
    padding: 16px 24px;
    gap: 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}

.chat-input-form input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 12px 20px;
    font-size: 0.92rem;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s;
}

.chat-input-form input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.btn-chat-send {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    padding: 0;
    flex-shrink: 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 20px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    opacity: 0.4;
    animation: typing 1s infinite alternate;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    from { transform: translateY(0); opacity: 0.4; }
    to { transform: translateY(-5px); opacity: 1; }
}

@media (max-width: 768px) {
    .chat-card {
        height: calc(100vh - var(--topbar-h) - var(--mobile-nav-h) - 32px);
    }
    .chat-message {
        max-width: 88%;
    }
    .chat-header {
        padding: 12px 16px;
    }
    .chat-messages {
        padding: 16px;
    }
    .chat-input-form {
        padding: 12px 16px;
    }
    .chat-suggestions {
        padding: 10px 16px;
    }
    .hide-mobile {
        display: none;
    }
}

