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

  :root {
    --bg-dark: #0a0e1a;
    --bg-card: #111827;
    --bg-card2: #1a2235;
    --accent: #00d4aa;
    --accent2: #0066ff;
    --accent3: #ff6b35;
    --text-main: #e8edf5;
    --text-muted: #6b7a99;
    --text-dim: #8892a4;
    --border: #1e2d4a;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --sidebar-w: 240px;
    --header-h: 64px;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
  }

  /* ===== THEMES ===== */
  body[data-theme="dark-blue"] {
    --bg-dark: #0a0e1a; --bg-card: #111827; --bg-card2: #1a2235;
    --accent: #00d4aa; --accent2: #0066ff; --border: #1e2d4a;
    --text-main: #e8edf5; --text-muted: #6b7a99; --text-dim: #8892a4;
  }
  body[data-theme="dark-purple"] {
    --bg-dark: #0d0a1a; --bg-card: #16112a; --bg-card2: #1f1840;
    --accent: #a855f7; --accent2: #6366f1; --border: #2d1f4a;
    --text-main: #ede8f5; --text-muted: #7a6b99; --text-dim: #9488b4;
  }
  body[data-theme="dark-green"] {
    --bg-dark: #0a140e; --bg-card: #101f14; --bg-card2: #172a1c;
    --accent: #22c55e; --accent2: #16a34a; --border: #1a3322;
    --text-main: #e8f5ec; --text-muted: #6b9975; --text-dim: #88a48e;
  }
  body[data-theme="dark-red"] {
    --bg-dark: #140a0a; --bg-card: #1f1010; --bg-card2: #2a1515;
    --accent: #ef4444; --accent2: #dc2626; --border: #3a1a1a;
    --text-main: #f5e8e8; --text-muted: #996b6b; --text-dim: #a48888;
  }
  body[data-theme="light"] {
    --bg-dark: #f0f4f8; --bg-card: #ffffff; --bg-card2: #f8fafc;
    --accent: #0066ff; --accent2: #00d4aa; --border: #e2e8f0;
    --text-main: #1a2235; --text-muted: #64748b; --text-dim: #94a3b8;
    --shadow: 0 4px 24px rgba(0,0,0,0.08);
  }
  body[data-theme="light-warm"] {
    --bg-dark: #fdf8f0; --bg-card: #ffffff; --bg-card2: #fef9f0;
    --accent: #f59e0b; --accent2: #ef4444; --border: #e8dcc8;
    --text-main: #1c1a12; --text-muted: #78716c; --text-dim: #a8a29e;
    --shadow: 0 4px 24px rgba(0,0,0,0.08);
  }
  body[data-theme="midnight"] {
    --bg-dark: #000000; --bg-card: #0a0a0a; --bg-card2: #111111;
    --accent: #ffffff; --accent2: #888888; --border: #222222;
    --text-main: #ffffff; --text-muted: #666666; --text-dim: #888888;
  }

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

  body {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    background: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    direction: rtl;
    overflow-y: auto;   /* يضمن التمرير العمودي */
    -webkit-overflow-scrolling: touch; /* تمرير سلس على iOS */
  }

  /* ===== SIDEBAR ===== */
  #sidebar {
    position: fixed;
    top: 0; right: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
  }

  .sidebar-logo {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .logo-icon {
    width: 42px; height: 42px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
  }

  .logo-text {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.3;
  }
  .logo-text span { color: var(--accent); font-size: 11px; font-weight: 400; }

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

  .nav-section-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 12px 4px;
    margin-top: 8px;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 2px;
    border: 1px solid transparent;
  }

  .nav-item:hover {
    background: var(--bg-card2);
    color: var(--text-main);
  }

  .nav-item.active {
    background: linear-gradient(135deg, rgba(0,212,170,0.15), rgba(0,102,255,0.1));
    color: var(--accent);
    border-color: rgba(0,212,170,0.2);
  }

  .nav-item .icon { font-size: 18px; width: 22px; text-align: center; }

  .sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
  }

  /* ===== MAIN ===== */
  #main {
    margin-right: var(--sidebar-w);
    min-height: 100vh;
    overflow-x: clip; /* clip لا ينشئ scroll container مثل hidden */
  }

  #header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .ticker-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0 18px;
    font-size: 11px;
    font-weight: 600;
    border-right: 1px solid var(--border);
    height: 28px;
  }

  .ticker-item .t-name {
    color: var(--text-muted);
    font-size: 10px;
  }
  .ticker-item .t-price {
    color: var(--text-main);
    font-weight: 700;
  }
  .ticker-item .t-up   { color: var(--success); font-size: 10px; }
  .ticker-item .t-down { color: var(--danger);  font-size: 10px; }

  .ticker-loading {
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 16px;
    animation: pulse 1.5s ease-in-out infinite;
  }

  @keyframes pulse {
    0%,100% { opacity:1; }
    50%      { opacity:0.4; }
  }

  .header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
  }

  @keyframes bellShake {
    0%,100% { transform: rotate(0); }
    15%     { transform: rotate(15deg); }
    30%     { transform: rotate(-12deg); }
    45%     { transform: rotate(10deg); }
    60%     { transform: rotate(-8deg); }
    75%     { transform: rotate(5deg); }
  }
  #notif-badge {
    animation: none;
  }
  #notif-badge.has-debts {
    animation: bellShake 2.5s ease infinite 3s;
  }
  .header-meta {
    display: flex;
    align-items: center;
    gap: 14px;
  }

  .header-date {
    background: var(--bg-card2);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    font-size: 12px;
  }

  #content {
    padding: 28px;
    position: relative;
    min-height: calc(100vh - var(--header-h));
  }
  .page { position: relative; z-index: 1; }

  /* ===== PAGES ===== */
  .page { display: none; }
  .page.active {
    display: block;
    animation: pageEnter 0.3s ease both;
  }

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

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

  .stat-card {
    animation: cardPop 0.35s ease both;
  }
  .stat-card:nth-child(1) { animation-delay: 0.03s; }
  .stat-card:nth-child(2) { animation-delay: 0.07s; }
  .stat-card:nth-child(3) { animation-delay: 0.11s; }
  .stat-card:nth-child(4) { animation-delay: 0.15s; }
  .stat-card:nth-child(5) { animation-delay: 0.19s; }
  .stat-card:nth-child(6) { animation-delay: 0.23s; }

  /* nav item hover — subtle glow + slide */
  .nav-item {
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, padding-right 0.2s ease;
  }
  .nav-item:hover {
    background: rgba(255,255,255,0.04);
    color: var(--text-main);
    padding-right: 22px;
  }
  .nav-item.active {
    background: linear-gradient(135deg, rgba(0,212,170,0.12), rgba(0,102,255,0.08));
    color: var(--accent);
    border-color: rgba(0,212,170,0.2);
    box-shadow: inset 3px 0 0 var(--accent);
  }

  /* stat card hover — clean lift with glow */
  .stat-card {
    transition: transform 0.22s ease, box-shadow 0.22s ease;
  }
  .stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.06);
  }

  /* card hover — very subtle lift */
  .card {
    transition: box-shadow 0.22s ease, border-color 0.22s ease;
  }
  .card:hover {
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    border-color: rgba(255,255,255,0.08);
  }

  /* btn — smooth press */
  .btn {
    transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease !important;
  }
  .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
  }
  .btn:active {
    transform: translateY(1px) scale(0.97) !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3) !important;
  }

  /* sidebar logo */
  .logo-icon {
    transition: opacity 0.2s ease;
  }
  .logo-icon:hover {
    opacity: 0.8;
  }

  /* theme picker */
  .theme-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 12px;
  }
  .theme-btn {
    border-radius: 10px;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 10px 6px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }
  .theme-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
  .theme-btn.active { border-color: var(--accent); transform: translateY(-1px); }
  .theme-swatch {
    width: 36px; height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }

  /* ===== CARDS ===== */
  .card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
  }

  .card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  /* ===== STATS GRID ===== */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
  }

  .stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
  }

  .stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  }

  .stat-card::before {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 4px; height: 100%;
  }

  .stat-card.green::before { background: var(--success); }
  .stat-card.blue::before { background: var(--info); }
  .stat-card.orange::before { background: var(--warning); }
  .stat-card.red::before { background: var(--danger); }
  .stat-card.teal::before { background: var(--accent); }

  .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
  }

  .stat-value {
    font-size: 26px;
    font-weight: 900;
    line-height: 1;
    margin-bottom: 4px;
  }

  .stat-card.green .stat-value { color: var(--success); }
  .stat-card.blue .stat-value { color: var(--info); }
  .stat-card.orange .stat-value { color: var(--warning); }
  .stat-card.red .stat-value { color: var(--danger); }
  .stat-card.teal .stat-value { color: var(--accent); }

  .stat-sub {
    font-size: 11px;
    color: var(--text-muted);
  }

  .stat-icon {
    position: absolute;
    bottom: 16px;
    left: 16px;
    font-size: 32px;
    opacity: 0.08;
  }

  /* ===== GRID ===== */
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

  /* ===== FORMS ===== */
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
  }

  .form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .form-group.full { grid-column: 1 / -1; }

  label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-dim);
  }

  input, select, textarea {
    background: var(--bg-card2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-main);
    font-family: 'Cairo', sans-serif;
    font-size: 13.5px;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    width: 100%;
    direction: rtl;
  }

  input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,212,170,0.1);
  }

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

  select option { background: var(--bg-card); }

  /* ===== BUTTONS ===== */
  .btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 13.5px;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    direction: rtl;
  }

  .btn-primary {
    background: linear-gradient(135deg, var(--accent), #00b894);
    color: #0a0e1a;
  }
  .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,212,170,0.4); }

  .btn-secondary {
    background: var(--bg-card2);
    color: var(--text-main);
    border: 1px solid var(--border);
  }
  .btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

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

  .btn-success {
    background: rgba(16,185,129,0.15);
    color: var(--success);
    border: 1px solid rgba(16,185,129,0.3);
  }
  .btn-success:hover { background: var(--success); color: white; }

  .btn-sm { padding: 6px 12px; font-size: 12px; }
  .btn-lg { padding: 13px 28px; font-size: 15px; }

  /* ===== TABLE ===== */
  .table-wrap { overflow-x: auto; }

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }

  thead th {
    background: var(--bg-card2);
    padding: 12px 14px;
    text-align: right;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }

  tbody tr {
    border-bottom: 1px solid rgba(30,45,74,0.5);
    transition: background 0.15s;
  }

  tbody tr {
    transition: background 0.15s ease;
  }
  tbody tr:hover { background: rgba(255,255,255,0.04); }

  tbody td {
    padding: 11px 14px;
    color: var(--text-main);
    vertical-align: middle;
  }

  /* ===== BADGES ===== */
  .badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    gap: 4px;
  }

  .badge-success { background: rgba(16,185,129,0.15); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
  .badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
  .badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }
  .badge-info { background: rgba(59,130,246,0.15); color: var(--info); border: 1px solid rgba(59,130,246,0.3); }
  .badge-teal { background: rgba(0,212,170,0.15); color: var(--accent); border: 1px solid rgba(0,212,170,0.3); }

  /* ===== SEARCH BAR ===== */
  .search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
    flex-wrap: wrap;
  }

  .search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
  }

  .search-input-wrap input {
    padding-right: 36px;
  }

  .search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
    pointer-events: none;
  }

  /* ===== MODAL ===== */
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .modal-overlay.open {
    opacity: 1;
    pointer-events: all;
  }

  .modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    opacity: 0;
    transform: translateY(16px) scale(0.98);
    transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  }

  .modal-overlay.open .modal {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

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

  .modal-title {
    font-size: 17px;
    font-weight: 700;
  }

  .modal-close {
    background: var(--bg-card2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    width: 32px; height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
  }

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

  .modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    background: var(--bg-card);
    z-index: 5;
  }

  /* ===== TOAST ===== */
  #toast-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 18px;
    font-size: 13.5px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
    animation: slideUp 0.3s ease;
    min-width: 240px;
  }

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

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

  /* ===== SECTION HEADER ===== */
  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
  }

  .section-title {
    font-size: 20px;
    font-weight: 700;
  }

  /* ===== DIVIDER ===== */
  .divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
  }

  /* ===== SCROLLBAR ===== */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

  .empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
  .empty-state p { font-size: 14px; }

  /* ===== RADIO GROUP ===== */
  .radio-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
  }

  .radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
  }

  .radio-option input { width: auto; }
  .radio-option:has(input:checked) {
    border-color: var(--accent);
    background: rgba(0,212,170,0.1);
    color: var(--accent);
  }

  /* ===== DASHBOARD ACTIVITY ===== */
  .activity-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(30,45,74,0.5);
  }

  .activity-item:last-child { border-bottom: none; }

  .activity-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .activity-text { flex: 1; font-size: 13px; }
  .activity-time { font-size: 11px; color: var(--text-muted); }

  /* ===== MOBILE — BOTTOM NAV ===== */
  /* ══════════ DASHBOARD GRID CLASSES ══════════ */
  .dash-grid-4 { display:grid; grid-template-columns:repeat(4,1fr); gap:14px; margin-bottom:20px; }
  .dash-grid-3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap:14px; margin-bottom:20px; }
  .dash-grid-2 { display:grid; grid-template-columns:1fr 1fr; gap:20px; margin-bottom:20px; }

  /* ══════════ MOBILE BOTTOM NAV ══════════ */
  #mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 62px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    z-index: 100;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.25);
  }

  .mob-nav-inner {
    display: flex; align-items: center;
    justify-content: space-around;
    height: 100%; padding: 0 4px;
  }

  .mob-nav-item {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px; flex: 1; height: 100%;
    cursor: pointer; border: none;
    background: none;
    color: var(--text-muted);
    font-size: 10px; font-family: inherit; font-weight: 600;
    padding: 5px 2px; position: relative;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-nav-item .mob-icon { font-size: 21px; line-height:1; transition: transform 0.2s; }
  .mob-nav-item.active { color: var(--accent); }
  .mob-nav-item.active .mob-icon { transform: translateY(-2px) scale(1.1); }
  .mob-nav-item.active::after {
    content: ''; position: absolute; bottom: 3px;
    width: 18px; height: 2.5px;
    background: var(--accent); border-radius: 2px;
  }

  /* More bottom sheet */
  #mob-more-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 209;
    -webkit-tap-highlight-color: transparent;
  }
  #mob-more-menu {
    position: fixed; bottom: 62px; left: 0; right: 0;
    background: var(--bg-card);
    border-radius: 24px 24px 0 0;
    z-index: 210;
    padding: 12px 16px 16px;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.4);
    visibility: hidden;
    transform: translateY(100%);
    transition: transform 0.25s ease-out, visibility 0.25s;
  }
  #mob-more-menu.open {
    transform: translateY(0);
    visibility: visible;
  }
  .mob-more-handle {
    width: 36px; height: 4px; background: var(--border);
    border-radius: 2px; margin: 0 auto 14px;
  }
  .mob-more-grid {
    display: grid; grid-template-columns: repeat(4,1fr); gap: 8px;
    margin-bottom: 12px;
  }
  .mob-more-item {
    display: flex; flex-direction: column; align-items: center;
    gap: 6px; padding: 13px 6px; border-radius: 14px;
    background: var(--bg-card2);
    cursor: pointer; font-size: 11px; font-weight: 600;
    color: var(--text-dim); text-align: center; border: none;
    font-family: inherit;
    transition: all 0.15s; -webkit-tap-highlight-color: transparent;
  }
  .mob-more-item:active { transform: scale(0.92); background: rgba(0,212,170,0.12); color: var(--accent); }
  .mob-more-item .mi { font-size: 24px; }
  .mob-logout-btn {
    width:100%; padding: 13px; background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2); border-radius: 12px;
    color: var(--danger); font-size: 14px; font-weight: 700;
    cursor: pointer; font-family: inherit; margin-bottom: 4px;
    -webkit-tap-highlight-color: transparent;
  }

  /* ══════════ TABLET (max 900px) ══════════ */
  @media (max-width: 900px) {
    :root { --sidebar-w: 200px; }
    #content { padding: 20px 16px; }
    .stats-grid { grid-template-columns: repeat(2,1fr); gap: 12px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 14px; }
  }

  /* ══════════ MOBILE (max 640px) ══════════ */
  @media (max-width: 640px) {

    /* — Layout — */
    #sidebar { display: none !important; }
    #main {
      margin-right: 0 !important;
      overflow: visible !important; /* إصلاح: يمنع حجب التمرير العمودي على iOS */
      min-height: unset !important; /* إصلاح: 100vh يُربك iOS في تحديد scroll container */
      height: auto !important;
    }
    #content {
      min-height: unset !important; /* إصلاح: يتسبب في إخفاء المحتوى عن نطاق التمرير */
    }
    html {
      overflow-y: scroll !important; /* body هو scroll container الصريح */
      height: auto !important;
    }
    body {
      overflow-y: scroll !important;
      height: auto !important;
    }
    #mobile-bottom-nav { display: block; }

    #header {
      padding: 0 10px;
      height: 52px;
      position: sticky;
      top: 0;
      z-index: 50;
    }
    .header-date, .header-meta > *:not(:last-child) { display: none !important; }
    .header-title { font-size: 14px; font-weight: 700; }
    .header-meta { gap: 6px; }

    #content {
      padding: 12px 12px 100px; /* زيادة المسافة السفلية لضمان ظهور الزر فوق nav */
      touch-action: pan-y !important; /* يضمن التمرير العمودي اللمسي */
    }

    /* — Dashboard grids — */
    .dash-grid-4 {
      grid-template-columns: repeat(2,1fr) !important;
      gap: 10px !important;
      margin-bottom: 12px !important;
    }
    .dash-grid-3 {
      grid-template-columns: repeat(3,1fr) !important;
      gap: 8px !important;
      margin-bottom: 12px !important;
    }
    .dash-grid-2 {
      grid-template-columns: 1fr !important;
      gap: 12px !important;
      margin-bottom: 12px !important;
    }
    .dash-grid-3 .card { padding: 12px 10px !important; }
    .dash-grid-3 .card > div:first-child { font-size: 10px !important; }
    .dash-grid-3 .card > div:nth-child(2) { font-size: 16px !important; }

    /* — Stat cards — */
    .stats-grid { grid-template-columns: repeat(2,1fr); gap: 9px; }
    .stat-card { padding: 14px 10px; border-radius: 14px; }
    .stat-value { font-size: 19px !important; }
    .stat-label { font-size: 11px; }
    .stat-sub { font-size: 10px; }
    .stat-icon { font-size: 18px !important; top: 12px !important; right: 12px !important; }

    /* — Cards — */
    .card { padding: 14px 12px; border-radius: 14px; }
    .card-title { font-size: 13px; margin-bottom: 12px; }

    /* — Grids — */
    .grid-2, .grid-3 { grid-template-columns: 1fr !important; gap: 12px; }
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
    [style*="grid-template-columns:repeat(3"] { grid-template-columns: repeat(2,1fr) !important; }
    [style*="grid-template-columns:repeat(4"] { grid-template-columns: repeat(2,1fr) !important; }

    /* — Section headers — */
    .section-header { flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
    .section-title { font-size: 16px; }
    .section-header .btn { font-size: 12px; padding: 7px 12px; }

    /* — Tables — */
    .table-wrap {
      border-radius: 10px;
      -webkit-overflow-scrolling: touch;
      position: relative;
    }
    /* تلميح بصري للتمرير: ظل خفيف على الحافة يدل أن في محتوى إضافي */
    .table-wrap::after {
      content: '';
      position: absolute;
      top: 0; bottom: 0; left: 0;
      width: 14px;
      background: linear-gradient(to left, transparent, rgba(0,0,0,0.18));
      pointer-events: none;
    }
    table th, table td {
      padding: 9px 9px !important;
      font-size: 11.5px !important;
      white-space: nowrap;
    }
    table th { font-size: 11px !important; }

    /* عمود الإجراءات (آخر عمود) — يثبت على الحافة المرئية كي لا يختفي بالتمرير */
    table td:last-child, table th:last-child {
      position: sticky;
      left: 0;
      z-index: 3;
      background: var(--bg-card);
      box-shadow: -8px 0 10px -6px rgba(0,0,0,0.35);
    }
    table tbody tr:nth-child(even) td:last-child { background: var(--bg-card2); }

    /* أزرار الإجراءات داخل الجداول والبطاقات — مساحة لمس أكبر وفراغ أوسع */
    table td:last-child .btn-sm,
    .btn-sm {
      min-height: 36px;
      min-width: 36px;
      padding: 8px 12px !important;
      font-size: 12px !important;
    }
    table td:last-child > div[style*="display:flex"],
    table td > div[style*="display:flex"] {
      gap: 8px !important;
      flex-wrap: nowrap;
    }

    /* — Forms — */
    .form-grid { grid-template-columns: 1fr !important; gap: 10px; }
    .form-group label { font-size: 12px; margin-bottom: 5px; }
    .form-group input,
    .form-group select,
    .form-group textarea {
      font-size: 16px !important;
      padding: 10px 12px !important;
    }
    .form-group.full { grid-column: auto !important; }

    /* — Buttons — */
    .btn        { padding: 9px 14px; font-size: 13px; border-radius: 9px; }
    .btn-sm     { padding: 6px 11px; font-size: 11.5px; }
    .btn-lg     { padding: 11px 20px; font-size: 14px; }
    .btn-primary, .btn-danger, .btn-success, .btn-secondary { min-height: 38px; }

    /* — Radio groups — */
    .radio-group { gap: 7px; flex-wrap: wrap; }
    .radio-option { padding: 7px 11px; font-size: 12px; }

    /* — Badges — */
    .badge { font-size: 10px; padding: 2px 7px; }

    /* — Modals → bottom sheet on mobile — */
    .modal-overlay {
      align-items: flex-end !important;
      padding: 0 !important;
    }
    .modal {
      width: 100% !important;
      max-width: 100% !important;
      max-height: 92vh !important;
      overflow-y: auto !important;
      border-radius: 22px 22px 0 0 !important;
      padding: 20px 16px !important;
      margin: 0 !important;
    }
    .modal-header { padding-bottom: 12px; margin-bottom: 12px; }

    /* drag handle for modals */
    .modal::before {
      content: '';
      display: block;
      width: 36px; height: 4px;
      background: var(--border);
      border-radius: 2px;
      margin: -8px auto 16px;
    }

    /* — Toast — */
    #toast-container {
      top: auto !important;
      bottom: 72px !important;
      left: 10px; right: 10px;
    }

    /* — Devices page table — hide less important cols — */
    .hide-mobile { display: none !important; }

    /* — Employees cards — */
    #employees-list .card { border-radius: 14px; }
  }

  /* ══════════ Very small (max 380px) ══════════ */
  @media (max-width: 380px) {
    .dash-grid-4 { grid-template-columns: repeat(2,1fr) !important; gap: 8px !important; }
    .dash-grid-3 { grid-template-columns: repeat(3,1fr) !important; gap: 6px !important; }
    .stat-value { font-size: 17px !important; }
    .mob-nav-item { font-size: 9px; }
    .mob-nav-item .mob-icon { font-size: 19px; }
    #content { padding: 10px 10px 76px; }
  }

  /* ===== PRINT ===== */
  @media print {
    body { background: white; color: black; }
    #sidebar, #header { display: none; }
    #main { margin: 0; }
    #content { padding: 0; }
    .btn, .search-bar, .section-header .btn { display: none; }
    .card { border: 1px solid #ccc; box-shadow: none; background: white; }
    table, th, td { color: black; border-color: #ccc; }
    thead th { background: #f5f5f5; }
    .badge { border: 1px solid #ccc; color: black; }
  }

  /* ===== INVOICE ===== */
  #invoice-print {
    display: none;
    padding: 40px;
    font-family: 'Cairo', sans-serif;
    direction: rtl;
  }

  #invoice-print.show { display: block; }

  .invoice-header {
    text-align: center;
    margin-bottom: 32px;
    padding-bottom: 20px;
    border-bottom: 2px solid #333;
  }

  .invoice-shop-name {
    font-size: 28px;
    font-weight: 900;
    margin-bottom: 4px;
  }

  .invoice-shop-info {
    font-size: 13px;
    color: #666;
  }

  .invoice-title {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    margin: 20px 0;
    color: #333;
  }

  .invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
  }

  .invoice-table th, .invoice-table td {
    border: 1px solid #ddd;
    padding: 10px 14px;
    text-align: right;
    font-size: 13px;
    color: #333;
  }

  .invoice-table th { background: #f5f5f5; font-weight: 700; }

  .invoice-total {
    text-align: left;
    font-size: 16px;
    font-weight: 700;
    margin-top: 16px;
    padding: 12px;
    background: #f5f5f5;
    border-radius: 8px;
  }

  .invoice-footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
    font-size: 12px;
    color: #888;
  }

  /* ══ PRICE TICKER ══ */
  #header-row1 {
    display: flex;
    align-items: center;
    height: var(--header-h);
    padding: 0 28px;
    gap: 12px;
  }
  .header-title { flex-shrink: 0; }
  .header-meta  { flex-shrink: 0; margin-right: auto; }

  #price-ticker-bar {
    flex: 1;
    min-width: 0;
    height: 28px;
    overflow: hidden;
    position: relative;
    background: var(--bg-card2);
    border: 1px solid var(--border);
    border-radius: 20px;
    display: flex;
    align-items: center;
  }
  #price-ticker-bar::before,
  #price-ticker-bar::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    width: 32px;
    z-index: 2;
    pointer-events: none;
  }
  #price-ticker-bar::before { right: 48px; background: linear-gradient(to left, var(--bg-card2), transparent); }
  #price-ticker-bar::after  { left: 0;     background: linear-gradient(to right, var(--bg-card2), transparent); }

  #ticker-label {
    position: absolute;
    left: 0;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 8px;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--accent);
    background: var(--bg-card2);
    border-right: 1px solid var(--border);
    z-index: 3;
    white-space: nowrap;
  }

  #ticker-track {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    padding-left: 52px;
    animation: tickerScroll 40s linear infinite;
  }
  #ticker-track:hover { animation-play-state: paused; cursor: default; }

  @keyframes tickerScroll {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-50%); }
  }

  .ticker-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0 16px;
    font-size: 11px;
    font-weight: 700;
    border-right: 1px solid var(--border);
    height: 28px;
  }
  .ticker-item .t-icon { font-size: 13px; }
  .ticker-item .t-name { color: var(--text-muted); font-size: 10px; font-weight: 600; }
  .ticker-item .t-price { color: var(--text-main); }
  .ticker-item .t-up   { color: #22c55e; font-size: 10px; }
  .ticker-item .t-down { color: #ef4444; font-size: 10px; }
  .ticker-item .t-neutral { color: var(--text-muted); font-size: 10px; }
  .ticker-loading { font-size: 11px; color: var(--text-muted); padding: 0 16px; }

  @media (max-width: 768px) {
    #price-ticker-bar { display: none; }
    #header-row1 { padding: 0 10px; gap: 6px; }
  }

  /* ══ NO ANIMATIONS ON MOBILE for performance ══ */
  @media (max-width: 640px) {
    .stat-card { animation: none !important; }
    .page.active { animation: none !important; }
    .card:hover { transform: none !important; box-shadow: none !important; }
    .stat-card:hover { transform: none !important; box-shadow: none !important; }
    .btn:hover { transform: none !important; }
    .nav-item:hover { padding-right: 12px !important; }
    * { -webkit-tap-highlight-color: transparent; }
    /* overscroll-behavior-y: contain أُزيل لأنه يتسبب في تعطيل التمرير على بعض الجوالات */
  }

/* Shared usability improvements, including RTL and narrow screens. */
body[data-theme="dark-blue"] { --accent: #e2b347; --accent2: #5b9cff; --text-muted: #a3aec2; --text-dim: #b6bfd0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
button, input:not([type="checkbox"]):not([type="radio"]), select { min-height: 44px; }
button:disabled { opacity: .6; cursor: wait; }
input[type="tel"], input[type="email"] { direction: ltr; text-align: right; }
.card, .stat-card { border-radius: 16px; }
th { white-space: nowrap; }
td { line-height: 1.7; }
tbody tr:hover { background: var(--bg-card2); }
#sync-status { font-size: 12px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-main); white-space: nowrap; }
#sync-status[data-state="saving"], #sync-status[data-state="loading"] { color: var(--warning); }
#sync-status[data-state="error"], #sync-status[data-state="offline"] { color: var(--danger); }
#sync-status[data-state="saved"] { color: var(--success); }
.modal { max-height: 90dvh; overflow-y: auto; }
@media (max-width: 640px) {
  .section-header { flex-wrap: wrap; gap: 12px; }
  .section-header > div { flex-wrap: wrap; }
  .header-meta { flex-wrap: wrap; gap: 6px; }
  #sync-status { font-size: 11px; padding: 3px 7px; }
  .table-wrap { overscroll-behavior-x: contain; }
  .form-control, input, select, textarea { font-size: 16px; }
  .modal { width: 100%; max-height: 88dvh; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

body[data-theme="dark-blue"] .btn-primary { background: linear-gradient(135deg, #e2b347, #c9960c); }
body[data-theme="dark-blue"] .btn-primary:hover { box-shadow: 0 4px 16px rgba(201,150,12,.25); }
@media (max-width: 640px) { .header-meta > #sync-status { display: inline-flex !important; } }

/* Account access and password controls */
#s-login { overflow-x: hidden !important; overflow-y: auto !important; align-items: flex-start !important; padding: 32px 16px; }
#s-login .auth-shell { flex-shrink: 0; margin-block: auto; }
.auth-password-row { display: flex; align-items: stretch; gap: 8px; min-width: 0; }
.auth-password-row input { flex: 1; min-width: 0; }
.auth-password-row button { flex: 0 0 auto; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; color: var(--text-main); background: var(--bg-card2); font: inherit; font-size: 12px; }
.auth-control { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-dark); color: var(--text-main); font: inherit; }
.auth-field { margin-bottom: 16px; }
.auth-field label { display: block; margin-bottom: 6px; font-size: 13px; color: #e2b347; }
.auth-link { background: transparent; border: 0; padding: 8px; color: #e2b347; font: inherit; font-size: 13px; cursor: pointer; }
.account-hint { font-size: 13px; line-height: 1.8; color: var(--text-muted); margin: 8px 0 14px; }
.account-message { font-size: 13px; line-height: 1.8; margin: 10px 0; overflow-wrap: anywhere; color: var(--success); }
.account-message:empty { display: none; }
.account-message[data-state="error"] { color: var(--danger); }
.account-actions { display: flex; gap: 10px; flex-wrap: wrap; }
#s-login .account-hint { color: #a3aec2; }
#s-login .auth-password-row button { color: #e2b347; }
#s-login .account-message { margin-bottom: 16px; }
@media (max-width: 640px) {
  #s-login { padding: 28px 12px; }
  .account-actions > button { flex: 1 1 100%; }
}
