/* ═══════════════════════════════════════
   XZMAT Social Support Portal — Styles
   ═══════════════════════════════════════ */

:root {
  --bg:          #08111e;
  --surface:     #0f1d2e;
  --surface2:    #162436;
  --border:      #1e3448;
  --primary:     #1d8cf8;
  --primary-dim: #1466b8;
  --success:     #00c9a7;
  --warning:     #f9a825;
  --danger:      #e53935;
  --text:        #e0e6ed;
  --muted:       #a3b1c6;
  --muted-soft:  #7f8fa4;
  --focus-ring:  0 0 0 3px rgba(29,140,248,.45);
  --sidebar-w:   240px;
  --header-h:    64px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 20px rgba(0,0,0,.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Global focus ring (keyboard only) ─── */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: var(--focus-ring);
}

/* visually-hidden (for sr-only labels) */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* skip link */
.skip-link {
  position: absolute;
  left: -999px; top: 0;
  background: var(--primary);
  color: #fff;
  padding: 8px 14px;
  z-index: 9999;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; text-decoration: none; }

/* ── Scrollbar ─────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ════════════════════════════════════════
   LAYOUT
   ════════════════════════════════════════ */

#app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform .25s ease;
}

#sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}

#sidebar .brand .logo-icon {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}

#sidebar nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

#sidebar nav .nav-section {
  padding: 6px 20px 2px;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-top: 8px;
}

#sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--muted);
  font-size: .9rem;
  border-left: 3px solid transparent;
  transition: all .15s;
}

#sidebar nav a i { width: 18px; text-align: center; font-size: .95rem; }

#sidebar nav a:hover {
  color: var(--text);
  background: rgba(29,140,248,.08);
  text-decoration: none;
}

#sidebar nav a.active {
  color: var(--primary);
  background: rgba(29,140,248,.12);
  border-left-color: var(--primary);
}

#sidebar .sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 14px 20px;
}

#sidebar .sidebar-footer .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

#sidebar .sidebar-footer .avatar {
  width: 34px; height: 34px;
  background: var(--primary-dim);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}

#sidebar .sidebar-footer .user-name { font-size: .85rem; font-weight: 600; }
#sidebar .sidebar-footer .user-role { font-size: .75rem; color: var(--muted); }

#sidebar .sidebar-footer .btn-logout {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .82rem;
  transition: all .15s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}

#sidebar .sidebar-footer .btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ── Main Content ──────────────────────── */
#main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-header h1 {
  font-size: 1.15rem;
  font-weight: 600;
}

.page-header .header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-content {
  padding: 28px;
  flex: 1;
}

/* hamburger for mobile */
#menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px;
}

/* ════════════════════════════════════════
   COMPONENTS — Buttons
   ════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
}

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover   { background: var(--primary-dim); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover   { filter: brightness(.9); }
.btn-warning   { background: var(--warning); color: #1a1a1a; }
.btn-warning:hover   { filter: brightness(.9); }
.btn-danger    { background: var(--danger);  color: #fff; }
.btn-danger:hover    { filter: brightness(.9); }
.btn-ghost     { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover     { color: var(--text); border-color: var(--muted); }
.btn-sm        { padding: 5px 11px; font-size: .8rem; }
.btn-block     { width: 100%; justify-content: center; }

/* User row (settings page) */
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-row__main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}
.user-row__info { min-width: 0; }
.user-row__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.avatar {
  width: 36px;
  height: 36px;
  background: var(--primary-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.btn-icon      { padding: 7px 10px; }

.btn:disabled,
.btn[aria-busy="true"] {
  opacity: .65;
  cursor: not-allowed;
  pointer-events: none;
}

.btn[aria-busy="true"] .btn-label { opacity: .7; }
.btn[aria-busy="true"] .btn-spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin .7s linear infinite;
  margin-right: 4px;
  vertical-align: -2px;
}
.btn .btn-spinner { display: none; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ════════════════════════════════════════
   COMPONENTS — Cards
   ════════════════════════════════════════ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

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

.card-title {
  font-size: .95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title i { color: var(--primary); }

/* ── Stat Cards ─────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.stat-icon.blue   { background: rgba(29,140,248,.15);  color: var(--primary); }
.stat-icon.green  { background: rgba(0,201,167,.15);   color: var(--success); }
.stat-icon.gold   { background: rgba(249,168,37,.15);  color: var(--warning); }
.stat-icon.red    { background: rgba(229,57,53,.15);   color: var(--danger);  }
.stat-icon.purple { background: rgba(156,39,176,.15);  color: #ce93d8; }

.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* ════════════════════════════════════════
   COMPONENTS — Tables
   ════════════════════════════════════════ */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

thead th {
  background: var(--surface2);
  color: var(--muted);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover { background: rgba(255,255,255,.025); }

/* ════════════════════════════════════════
   COMPONENTS — Badges
   ════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-success { background: rgba(0,201,167,.15);  color: var(--success); }
.badge-warning { background: rgba(249,168,37,.15); color: var(--warning); }
.badge-danger  { background: rgba(229,57,53,.15);  color: var(--danger);  }
.badge-primary { background: rgba(29,140,248,.15); color: var(--primary); }
.badge-muted   { background: rgba(127,143,164,.1); color: var(--muted);   }

/* ════════════════════════════════════════
   COMPONENTS — Forms
   ════════════════════════════════════════ */

.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: .83rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: .875rem;
  outline: none;
  transition: border-color .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

input::placeholder, textarea::placeholder { color: var(--muted); }

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

select option { background: var(--surface2); }

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

.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-section {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--primary);
  margin: 20px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ════════════════════════════════════════
   COMPONENTS — Modal
   ════════════════════════════════════════ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .2s;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: slideUp .22s;
}

.modal.modal-lg { max-width: 860px; }
.modal.modal-sm { max-width: 460px; }

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

.modal-title { font-size: 1rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color .15s;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Profile Modal Tabs ─────────────────── */
.tab-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  gap: 4px;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 16px;
  cursor: pointer;
  font-size: .875rem;
  transition: all .15s;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ════════════════════════════════════════
   COMPONENTS — Search & Filters
   ════════════════════════════════════════ */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 340px;
}

.search-box i {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: .85rem;
}

.search-box input {
  padding-left: 34px;
}

.filter-select {
  width: auto;
  min-width: 140px;
}

/* ════════════════════════════════════════
   COMPONENTS — Toast Notifications
   ════════════════════════════════════════ */

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .875rem;
  box-shadow: var(--shadow);
  min-width: 260px;
  max-width: 360px;
  animation: slideLeft .25s;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger);  }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--primary); }

.toast i.success { color: var(--success); }
.toast i.error   { color: var(--danger);  }
.toast i.warning { color: var(--warning); }
.toast i.info    { color: var(--primary); }

/* ════════════════════════════════════════
   COMPONENTS — Pagination
   ════════════════════════════════════════ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 0;
  font-size: .82rem;
  color: var(--muted);
}

.pagination-btns {
  display: flex;
  gap: 6px;
}

.page-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .82rem;
  transition: all .15s;
}

.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ════════════════════════════════════════
   COMPONENTS — Misc
   ════════════════════════════════════════ */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty-state i { font-size: 2.5rem; margin-bottom: 14px; display: block; }
.empty-state p { font-size: .9rem; }

/* ── Skeleton loaders ──────────────────── */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface2) 0%,
    rgba(255,255,255,.04) 50%,
    var(--surface2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.2s linear infinite;
  border-radius: var(--radius-sm);
  display: inline-block;
  height: 14px;
  width: 100%;
}
.skeleton-row td { padding: 14px; }
.skeleton-row .skeleton { height: 12px; }
@keyframes skeleton-shine {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Filter tools / results bar ────────── */
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}
.results-bar .btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: .8rem;
  padding: 2px 4px;
}
.results-bar .btn-link:hover { text-decoration: underline; }

/* ── Page header utility ───────────────── */
.page-header__title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header__icon { color: var(--primary); margin-right: 8px; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.rtl { direction: rtl; text-align: right; }
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger);  }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.fw-600 { font-weight: 600; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.three-col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

/* detail rows inside profile */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.detail-item label {
  font-size: .75rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.detail-item .val {
  font-size: .9rem;
  font-weight: 500;
}

/* timeline */
.timeline { list-style: none; }

.timeline li {
  display: flex;
  gap: 14px;
  padding-bottom: 18px;
  border-left: 2px solid var(--border);
  margin-left: 14px;
  padding-left: 18px;
  position: relative;
}

.timeline li::before {
  content: '';
  width: 10px; height: 10px;
  background: var(--primary);
  border-radius: 50%;
  position: absolute;
  left: -6px;
  top: 5px;
}

.timeline-meta { font-size: .78rem; color: var(--muted); margin-top: 3px; }

/* ════════════════════════════════════════
   LOGIN PAGE
   ════════════════════════════════════════ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.login-box {
  width: 100%;
  max-width: 400px;
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand .logo {
  width: 60px; height: 60px;
  background: var(--primary);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  color: #fff;
  margin: 0 auto 14px;
}

.login-brand h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}

.login-brand p {
  font-size: .85rem;
  color: var(--muted);
  margin-top: 4px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-card .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 11px;
  font-size: .95rem;
  margin-top: 4px;
}

.login-error {
  background: rgba(229,57,53,.1);
  border: 1px solid rgba(229,57,53,.3);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .85rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.login-error[hidden] { display: none; }

/* password input with toggle */
.input-with-action { position: relative; }
.input-with-action input { padding-right: 40px; }
.input-action {
  position: absolute;
  right: 4px; top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
}
.input-action:hover { color: var(--text); }

/* ════════════════════════════════════════
   DASHBOARD CHART
   ════════════════════════════════════════ */

.chart-wrap {
  position: relative;
  height: 240px;
}

/* ════════════════════════════════════════
   ANIMATIONS
   ════════════════════════════════════════ */

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideLeft { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }

/* ════════════════════════════════════════
   RESPONSIVE & MOBILE
   ════════════════════════════════════════ */

/* Sidebar overlay (always in DOM, hidden by default) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 199;
}

/* Profile modal mini stats — 4-col on desktop */
.modal-stat-mini {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

/* ── 900px ─────────────────────────────── */
@media (max-width: 900px) {
  .form-row.cols-3 { grid-template-columns: 1fr 1fr; }
  .three-col       { grid-template-columns: 1fr 1fr; }
}

/* ── 768px (tablet / large phone) ──────── */
@media (max-width: 768px) {
  /* Sidebar slide-out */
  #sidebar                { transform: translateX(-100%); }
  #sidebar.open           { transform: translateX(0); }
  #main                   { margin-left: 0; }
  #menu-toggle            { display: block; }
  .sidebar-overlay.visible{ display: block; }
  #sidebar .brand         { font-size: .95rem; }

  /* Page header */
  .page-header {
    padding: 0 12px;
    height: auto;
    min-height: var(--header-h);
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .page-header h1   { font-size: .95rem; }
  #header-date      { display: none; }

  /* Page content */
  .page-content { padding: 12px 12px 48px; }
  .card         { padding: 14px; }

  /* Stat grid — 2 columns, compact cards */
  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
  }
  .stat-card  { padding: 12px 10px; gap: 8px; }
  .stat-icon  { width: 36px; height: 36px; font-size: 1rem; }
  .stat-value { font-size: 1.15rem; }
  .stat-label { font-size: .72rem; }

  /* Profile modal mini stats → 2-col */
  .modal-stat-mini { grid-template-columns: 1fr 1fr; }

  /* Bottom-sheet modals */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 92vh;
  }
  .modal-header  { padding: 14px 16px; }
  .modal-body    { padding: 16px; }
  .modal-footer  { padding: 12px 16px; flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* Toolbar vertical stack */
  .toolbar      { flex-direction: column; align-items: stretch; gap: 8px; }
  .search-box   { max-width: 100%; min-width: 0; flex: unset; }
  .filter-select,
  .toolbar input[type="date"] { width: 100%; min-width: 0; }
  .toolbar .btn { justify-content: center; }

  /* Scrollable tabs */
  .tab-nav { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab-btn { white-space: nowrap; flex-shrink: 0; }

  /* Grids collapse to 1 column */
  .two-col, .three-col, .form-row, .detail-grid { grid-template-columns: 1fr; }

  /* Tables — scroll horizontally, no forced min-width */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Pagination stacks */
  .pagination { flex-direction: column; align-items: center; gap: 10px; }

  /* Hide non-critical columns */
  .col-hide-mobile { display: none; }

  /* Chart shorter on mobile */
  .chart-wrap { height: 180px; }
}

/* ── 640px (most phones in portrait) ───── */
@media (max-width: 640px) {
  /* Icon-only header buttons — prevent overflow */
  .header-actions .btn span { display: none; }
  .header-actions .btn      { padding: 8px 10px; }

  /* Stat cards: column layout so labels have full width */
  .stat-card {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px;
    gap: 4px;
  }
  .stat-icon  { width: 30px; height: 30px; font-size: .85rem; margin-bottom: 2px; }
  .stat-value { font-size: 1.05rem; }
  .stat-label { font-size: .68rem; line-height: 1.3; }
}

/* ── 420px (small phones) ───────────────── */
@media (max-width: 420px) {
  .page-content { padding: 10px 10px 48px; }
  .card         { padding: 10px; }

  /* Toast full-width */
  #toast-container { right: 10px; left: 10px; bottom: 14px; }
  .toast { min-width: unset; width: 100%; max-width: 100%; }
}

/* ════════════════════════════════════════
   MOBILE POLISH (touch, safe-area, scroll)
   ════════════════════════════════════════ */

/* Safe-area insets (iPhone X+ notch / home bar) */
@supports (padding: max(0px)) {
  #sidebar              { padding-top: env(safe-area-inset-top); }
  #sidebar .sidebar-footer { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .page-header          { padding-top: env(safe-area-inset-top); }
  #toast-container      { bottom: max(24px, env(safe-area-inset-bottom)); }
  .modal-backdrop       { padding-bottom: env(safe-area-inset-bottom); }
}

/* Smooth momentum scrolling for any scroll containers */
.table-wrap, .modal-body, #sidebar nav, .tab-nav {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Sticky table header when vertical scrolling inside table-wrap */
.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Horizontal-scroll hint shadow on table-wrap */
.table-wrap {
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(15,29,46,0)) left center / 24px 100% no-repeat local,
    linear-gradient(to left,  var(--surface) 30%, rgba(15,29,46,0)) right center / 24px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.4), transparent) left center / 14px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.4), transparent) right center / 14px 100% no-repeat scroll;
}

/* Prevent iOS Safari from auto-zooming on input focus (needs >=16px) */
@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  input[type="password"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px;
  }
  /* Larger tap targets */
  .btn          { min-height: 44px; padding: 10px 16px; }
  .btn-sm       { min-height: 36px; padding: 7px 12px; }
  .btn-icon     { min-height: 40px; min-width: 40px; padding: 8px 10px; }
  .modal-close  { min-height: 40px; min-width: 40px; font-size: 1.25rem; }
  #menu-toggle  { min-height: 44px; min-width: 44px; }

  /* Tap-friendly nav links */
  #sidebar nav a { padding: 12px 20px; font-size: .95rem; }
  #sidebar nav a i { font-size: 1.05rem; }

  /* Page header: shrink h1 icon */
  .page-header h1 i { font-size: .9em; }

  /* Cards have soft shadow + slightly raised look */
  .card { box-shadow: 0 1px 2px rgba(0,0,0,.2); }

  /* Tables: bigger hit area on rows, action buttons line up */
  tbody td { padding: 14px 12px; }
  thead th { padding: 12px 10px; font-size: .72rem; }

  /* Form spacing */
  .form-group { margin-bottom: 14px; }
  label       { font-size: .85rem; margin-bottom: 8px; }

  /* Modal — sticky footer always visible */
  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    z-index: 2;
  }

  /* Toolbar: compact, search keeps icon spacing */
  .toolbar { gap: 10px; }

  /* Pagination buttons larger */
  .page-btn { width: 40px; height: 40px; font-size: .9rem; }

  /* Login fits small screens */
  .login-card  { padding: 22px 18px; }
  .login-brand { margin-bottom: 22px; }
  .login-brand .logo { width: 52px; height: 52px; font-size: 1.5rem; }
  .login-brand h1    { font-size: 1.2rem; }
}

/* ── Floating Action Button (mobile primary action) ── */
.fab {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(29,140,248,.45);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  cursor: pointer;
  z-index: 150;
  transition: transform .15s, background .15s;
}
.fab:hover, .fab:focus-visible { background: var(--primary-dim); transform: scale(1.05); }

@media (max-width: 640px) {
  .fab { display: flex; }
  /* Ensure list pages have room for the FAB above content */
  .page-content { padding-bottom: 96px; }
}

/* ── Card list: alternative compact layout for small data tables ── */
.card-list {
  display: none;
  flex-direction: column;
  gap: 8px;
}

/* Reduced motion — disable animations */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ════════════════════════════════════════
   LANGUAGE SWITCHER
   ════════════════════════════════════════ */

.lang-switcher {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.lang-btn {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 4px;
  border-radius: var(--radius-sm);
  font-size: .72rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .04em;
  transition: all .15s;
  text-align: center;
}

.lang-btn:hover { color: var(--text); border-color: var(--muted); }
.lang-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Login page language switcher */
.login-lang-switcher {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
}

.login-lang-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

.login-lang-btn:hover { color: var(--text); border-color: var(--muted); }
.login-lang-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ════════════════════════════════════════
   RTL SUPPORT (Arabic & Sorani Kurdish)
   ════════════════════════════════════════ */

[dir="rtl"] body {
  font-family: 'Segoe UI', 'Tahoma', 'Arial', system-ui, sans-serif;
}

/* Sidebar: move to right side in RTL */
[dir="rtl"] #sidebar {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--border);
}

[dir="rtl"] #main {
  margin-left: 0;
  margin-right: var(--sidebar-w);
}

/* Nav links: flip active border and text alignment */
[dir="rtl"] #sidebar nav a {
  border-left: none;
  border-right: 3px solid transparent;
  flex-direction: row-reverse;
}

[dir="rtl"] #sidebar nav a.active {
  border-right-color: var(--primary);
}

[dir="rtl"] #sidebar .brand {
  flex-direction: row-reverse;
}

[dir="rtl"] #sidebar .sidebar-footer .user-info {
  flex-direction: row-reverse;
}

/* Page header: reverse order */
[dir="rtl"] .page-header__title-group {
  flex-direction: row-reverse;
}

[dir="rtl"] .page-header h1 i {
  margin-right: 0;
  margin-left: 8px;
}

/* Search box: icon on right */
[dir="rtl"] .search-box i {
  left: auto;
  right: 11px;
}

[dir="rtl"] .search-box input {
  padding-left: 12px;
  padding-right: 34px;
}

/* Tables: right-align headers */
[dir="rtl"] thead th {
  text-align: right;
}

[dir="rtl"] tbody td {
  text-align: right;
}

/* Toast: slide from left in RTL */
[dir="rtl"] #toast-container {
  right: auto;
  left: 24px;
}

[dir="rtl"] .toast {
  border-left: none;
  border-right: 3px solid var(--border);
}

[dir="rtl"] .toast.success { border-right-color: var(--success); }
[dir="rtl"] .toast.error   { border-right-color: var(--danger);  }
[dir="rtl"] .toast.warning { border-right-color: var(--warning); }
[dir="rtl"] .toast.info    { border-right-color: var(--primary); }

/* Cards and forms */
[dir="rtl"] .card-header { flex-direction: row-reverse; }
[dir="rtl"] .card-title  { flex-direction: row-reverse; }
[dir="rtl"] .modal-header { flex-direction: row-reverse; }
[dir="rtl"] .modal-footer { justify-content: flex-start; }

/* Input with action button (password toggle) */
[dir="rtl"] .input-with-action input {
  padding-right: 12px;
  padding-left: 40px;
}

[dir="rtl"] .input-action {
  right: auto;
  left: 4px;
}

/* Text alignment for RTL */
[dir="rtl"] label { text-align: right; }
[dir="rtl"] .form-section { text-align: right; }
[dir="rtl"] .btn { justify-content: center; }
[dir="rtl"] .modal-title { text-align: right; }
[dir="rtl"] .page-header h1 { text-align: right; }
[dir="rtl"] .detail-item label { text-align: right; }
[dir="rtl"] .card-header { text-align: right; }
[dir="rtl"] .btn-group { flex-direction: row-reverse; }
[dir="rtl"] .toolbar { flex-direction: row-reverse; }

/* User row in settings */
[dir="rtl"] .user-row        { flex-direction: row-reverse; }
[dir="rtl"] .user-row__main  { flex-direction: row-reverse; }

/* Timeline */
[dir="rtl"] .timeline li {
  border-left: none;
  border-right: 2px solid var(--border);
  margin-left: 0;
  margin-right: 14px;
  padding-left: 0;
  padding-right: 18px;
}

[dir="rtl"] .timeline li::before {
  left: auto;
  right: -6px;
}

/* Btn spinner margin */
[dir="rtl"] .btn[aria-busy="true"] .btn-spinner {
  margin-right: 0;
  margin-left: 4px;
}

/* Mobile sidebar slide from right */
@media (max-width: 768px) {
  [dir="rtl"] #sidebar {
    transform: translateX(100%);
  }
  [dir="rtl"] #sidebar.open {
    transform: translateX(0);
  }
  [dir="rtl"] #main {
    margin-right: 0;
  }
  [dir="rtl"] #toast-container {
    left: 10px;
    right: auto;
  }
}

/* FAB in RTL */
[dir="rtl"] .fab {
  right: auto;
  left: 18px;
}

@media (max-width: 640px) {
  [dir="rtl"] .fab {
    right: auto;
    left: 18px;
  }
}
