/* ==========================================================================
   كاش ليا — styles.css
   Light theme, RTL, mobile-first. iOS-safe: safe-area insets, 16px inputs,
   >=44px touch targets, no hover-only interactions.
   ========================================================================== */

:root {
  /* palette — restrained finance green */
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --surface-2: #FAFBFC;
  --ink: #1C2B33;
  --muted: #66757E;
  --faint: #93A1AA;
  --line: #E4E8EC;
  --line-strong: #D4DAE0;
  --primary: #0E5C49;
  --primary-dark: #0E3E33;   /* header / brand */
  --primary-soft: #E7F2EF;
  --up: #0B7A55;
  --up-soft: #E4F3EC;
  --down: #B3261E;
  --down-soft: #FBEBEA;
  --warn: #9A6A0B;
  --warn-soft: #FBF3E1;
  --gold: #A16207;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 30px rgba(14, 62, 51, .18);

  --tabbar-h: 58px;
  --header-h: 118px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Tajawal', -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

button { font-family: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
input, select, textarea { font-family: inherit; color: var(--ink); }

#app { min-height: 100vh; min-height: 100dvh; }

/* ==========================================================================
   Header (sticky) — title + total net balance
   ========================================================================== */
#app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--primary-dark);
  color: #fff;
  /* respect iPhone notch / status bar in standalone mode */
  padding-top: env(safe-area-inset-top);
  padding-bottom: 10px;
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset;
}
.header-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 2px 12px 0;
}
.header-title { flex: 1; text-align: center; font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.header-btn {
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; color: #fff;
}
.header-btn svg { width: 22px; height: 22px; }
.header-spacer { width: 44px; }
.net-balance {
  display: flex; align-items: baseline; justify-content: center;
  gap: 10px; padding: 2px 16px 4px;
}
.net-label { font-size: 13px; color: rgba(255,255,255,.72); font-weight: 500; }
.net-amount { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; direction: ltr; unicode-bidi: isolate; }
.net-amount small { font-size: 14px; font-weight: 500; color: rgba(255,255,255,.72); }
.net-amount.neg { color: #FFC9C4; }

/* ==========================================================================
   Layout / screens
   ========================================================================== */
#main { padding: 12px 14px calc(var(--tabbar-h) + 26px + env(safe-area-inset-bottom)); }
.screen { display: none; }
.screen.active { display: block; }

.section-title {
  font-size: 14px; font-weight: 700; color: var(--muted);
  margin: 18px 2px 8px; display: flex; align-items: center; justify-content: space-between;
}
.section-title:first-child { margin-top: 2px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}

/* ==========================================================================
   Buttons & inputs — all touch targets >= 44px, input font-size >= 16px
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border-radius: 13px; font-size: 16px; font-weight: 700;
  background: var(--primary); color: #fff;
  border: 1px solid transparent;
  transition: opacity .12s;
  user-select: none;
}
.btn:active { opacity: .82; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--primary); border-color: var(--line-strong); }
.btn.danger { background: var(--down-soft); color: var(--down); }
.btn.danger-solid { background: var(--down); color: #fff; }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: 14px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn svg { width: 20px; height: 20px; }

.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 13.5px; font-weight: 700; color: var(--muted); margin: 0 2px 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  font-size: 16px;              /* prevents iOS auto-zoom */
  min-height: 46px;
  padding: 9px 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  -webkit-appearance: none;
  appearance: none;
}
.field textarea { min-height: 66px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: #fff;
}
.field .hint { font-size: 12.5px; color: var(--faint); margin-top: 4px; }
select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2366757E' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;   /* RTL: arrow on the left */
  padding-left: 34px;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

/* Segmented buttons (service / type / options) */
.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.seg-btn {
  flex: 1; min-width: 72px; min-height: 48px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 1.5px solid var(--line-strong);
  border-radius: 13px; background: var(--surface);
  font-size: 15px; font-weight: 700; color: var(--ink);
  padding: 8px 10px;
  -webkit-user-select: none; user-select: none;
}
.seg-btn .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.seg-btn.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.seg-col { display: grid; gap: 8px; }
.seg-col .seg-btn { justify-content: flex-start; text-align: right; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 14px; }
.seg-col .seg-btn small { font-weight: 500; font-size: 12.5px; color: var(--faint); }
.seg-col .seg-btn.active small { color: var(--primary); opacity: .8; }

/* Amount fields with currency suffix */
.money-wrap { position: relative; }
.money-wrap input { padding-left: 46px; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.money-wrap::after {
  content: 'ج.م'; position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 13px; font-weight: 700; color: var(--faint); pointer-events: none;
}

/* ==========================================================================
   Home — balance cards + stats
   ========================================================================== */
.balance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bal-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 14px; text-align: right;
}
.bal-card.wide { grid-column: 1 / -1; }
.bal-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bal-ico { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; }
.bal-ico svg { width: 18px; height: 18px; }
.bal-name { font-size: 14px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bal-amount { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.bal-amount small { font-size: 12px; font-weight: 500; color: var(--muted); }
.bal-amount.neg { color: var(--down); }
.bal-edit { font-size: 12px; color: var(--primary); font-weight: 700; margin-top: 4px; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 10px; text-align: center; box-shadow: var(--shadow); }
.stat-val { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.stat-lbl { font-size: 11.5px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.stat-val.pos { color: var(--up); }
.stat-val.neg { color: var(--down); }

/* banner */
.banner {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--warn-soft); border: 1px solid #EFDFB8;
  color: #6B4A08; border-radius: 13px; padding: 11px 13px;
  font-size: 13.5px; margin-bottom: 10px;
}
.banner svg { width: 19px; height: 19px; flex: none; margin-top: 1px; }
.banner .btn { margin-top: 8px; }

/* recent list on home */
.mini-tx { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.mini-tx:last-child { border-bottom: 0; }
.mini-tx .grow { flex: 1; min-width: 0; }
.mini-tx .t1 { font-size: 14.5px; font-weight: 700; }
.mini-tx .t2 { font-size: 12px; color: var(--muted); }
.tx-amt { font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }

/* ==========================================================================
   Lists / rows (transactions, entries)
   ========================================================================== */
.tx-row {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 11px 13px; margin-bottom: 8px;
  box-shadow: var(--shadow); min-height: 58px;
  width: 100%; text-align: right;
}
.tx-ico {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.tx-ico svg { width: 20px; height: 20px; }
.tx-ico.in { background: var(--up-soft); color: var(--up); }
.tx-ico.out { background: var(--down-soft); color: var(--down); }
.tx-ico.neutral { background: #EEF1F4; color: var(--muted); }
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tx-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  border-radius: 6px; padding: 1px 7px;
}
.badge.w { background: var(--down-soft); color: var(--down); }
.badge.t { background: var(--primary-soft); color: var(--primary); }
.day-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 16px 4px 8px; font-size: 13px; font-weight: 700; color: var(--muted);
}
.day-head .day-profit { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* chips / filters */
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 38px; padding: 6px 15px;
  border: 1.5px solid var(--line-strong); border-radius: 20px;
  background: var(--surface); font-size: 13.5px; font-weight: 700; color: var(--muted);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filter-bar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filter-bar select, .filter-bar input {
  font-size: 15px; min-height: 44px; padding: 8px 12px;
  border: 1.5px solid var(--line-strong); border-radius: 12px; background: var(--surface);
  width: 100%;
}
.empty {
  text-align: center; color: var(--faint); padding: 34px 10px; font-size: 14.5px;
}
.empty svg { width: 40px; height: 40px; opacity: .4; margin-bottom: 8px; }

/* ==========================================================================
   New transaction screen
   ========================================================================== */
.tx-form .type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.type-toggle .seg-btn { min-height: 52px; font-size: 16.5px; }
.type-toggle .seg-btn.active.w-style { background: var(--down-soft); border-color: var(--down); color: var(--down); box-shadow: inset 0 0 0 1px var(--down); }
.type-toggle .seg-btn.active.t-style { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }

.preview-card {
  background: var(--surface-2); border: 1.5px dashed var(--line-strong);
  border-radius: 14px; padding: 12px 14px; margin: 4px 0 14px;
}
.preview-line { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; font-size: 14px; }
.preview-line .pl-name { color: var(--muted); font-weight: 500; }
.preview-line .pl-val { font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.preview-line .pl-delta { font-size: 12.5px; font-weight: 700; margin-inline-start: 6px; }
.preview-line.net { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.pl-delta.pos { color: var(--up); }
.pl-delta.neg { color: var(--down); }
.pl-val.pos, .pl-val.net-pos { color: var(--up); }
.pl-val.neg, .pl-val.net-neg { color: var(--down); }

/* ==========================================================================
   Debts
   ========================================================================== */
.debt-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.debt-total-card { border-radius: var(--radius); padding: 13px 14px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.debt-total-card.they { border-top: 3px solid var(--up); }
.debt-total-card.i { border-top: 3px solid var(--down); }
.debt-total-card .dt-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.debt-total-card .dt-val { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; margin-top: 2px; }
.debt-total-card.they .dt-val { color: var(--up); }
.debt-total-card.i .dt-val { color: var(--down); }

.debt-badge { font-size: 11.5px; font-weight: 700; border-radius: 6px; padding: 1px 8px; white-space: nowrap; }
.debt-badge.they { background: var(--up-soft); color: var(--up); }
.debt-badge.i { background: var(--down-soft); color: var(--down); }
.debt-badge.zero { background: #EEF1F4; color: var(--faint); }

/* ==========================================================================
   Reports
   ========================================================================== */
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 11px 13px; box-shadow: var(--shadow); }
.sum-card .sc-lbl { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.sum-card .sc-val { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; margin-top: 2px; }
.sum-card.hero { grid-column: 1 / -1; background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.sum-card.hero .sc-lbl { color: rgba(255,255,255,.7); }
.sum-card.hero .sc-val.pos { color: #7BE0B4; }
.sum-card.hero .sc-val.neg { color: #FFC9C4; }
.sc-val.pos { color: var(--up); }
.sc-val.neg { color: var(--down); }

table.mini-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.mini-table th { text-align: right; font-size: 12px; color: var(--faint); font-weight: 700; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.mini-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.mini-table tr:last-child td { border-bottom: 0; }
.mini-table .num { direction: ltr; unicode-bidi: isolate; }

.chart-box { padding: 8px 4px 2px; }
.chart-box svg { width: 100%; height: auto; display: block; }

/* ==========================================================================
   Modal (bottom sheet) + toast
   ========================================================================== */
#modal-root .modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(15, 25, 30, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadein .16s ease;
}
#modal-root .modal {
  background: var(--surface); width: 100%; max-width: 560px;
  max-height: 88vh; max-height: 88dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: slideup .22s ease;
  box-shadow: var(--shadow-lg);
}
.modal-title { font-size: 17px; font-weight: 800; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(40px); opacity: .4; } to { transform: translateY(0); opacity: 1; } }

#toast-root {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom));
  z-index: 120; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 20px;
}
.toast {
  max-width: 100%;
  background: #24333B; color: #fff;
  font-size: 14.5px; font-weight: 500;
  border-radius: 12px; padding: 11px 18px;
  box-shadow: var(--shadow-lg);
  animation: slideup .2s ease;
  text-align: center;
}
.toast.err { background: var(--down); }
.toast.ok { background: var(--up); }

/* ==========================================================================
   Right sidebar (tablet/desktop) — hidden on mobile by default
   ========================================================================== */
#sidebar { display: none; }

/* ==========================================================================
   Tab bar
   ========================================================================== */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,.96);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; font-weight: 700; color: var(--faint);
  min-height: 44px;
}
.tab svg { width: 23px; height: 23px; }
.tab.active { color: var(--primary); }
.tab-new-circle {
  width: 44px; height: 44px; margin-top: -16px;
  border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(14, 92, 73, .35);
}
.tab-new-circle svg { width: 22px; height: 22px; }
.tab.active .tab-new-circle { background: var(--primary-dark); }

/* ==========================================================================
   Setup screen
   ========================================================================== */
.setup-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--primary-dark); overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.setup-overlay .screen { color: #fff; padding: 0 0 40px; min-height: 100vh; min-height: 100dvh; }
.setup-hero { padding: calc(env(safe-area-inset-top) + 34px) 22px 6px; text-align: center; }
.setup-logo {
  width: 76px; height: 76px; border-radius: 22px; margin: 0 auto 14px;
  background: #fff; color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
}
.setup-logo svg { width: 40px; height: 40px; }
.setup-hero h1 { font-size: 25px; font-weight: 800; margin: 0 0 6px; }
.setup-hero p { margin: 0; color: rgba(255,255,255,.72); font-size: 14.5px; }
.setup-body { padding: 18px 16px 0; }
.setup-body .card { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.14); box-shadow: none; color: #fff; }
.setup-body .field > label { color: rgba(255,255,255,.75); }
.setup-body input {
  background: rgba(255,255,255,.1) !important; border-color: rgba(255,255,255,.25) !important; color: #fff;
}
.setup-body .money-wrap::after { color: rgba(255,255,255,.55); }
.setup-note { font-size: 13px; color: rgba(255,255,255,.65); text-align: center; padding: 14px 26px 0; }

/* ==========================================================================
   Misc
   ========================================================================== */
.list-card { padding: 4px 12px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 4px; border-bottom: 1px solid var(--line);
  text-align: right; min-height: 52px;
}
.menu-item:last-child { border-bottom: 0; }
.menu-ico { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex: none; }
.menu-ico svg { width: 19px; height: 19px; }
.menu-txt { flex: 1; font-size: 15.5px; font-weight: 700; }
.menu-sub { font-size: 12px; color: var(--muted); font-weight: 500; }
.menu-arrow { color: var(--faint); width: 18px; height: 18px; flex: none; }
.ico-primary { background: var(--primary-soft); color: var(--primary); }
.ico-down { background: var(--down-soft); color: var(--down); }
.ico-up { background: var(--up-soft); color: var(--up); }
.ico-warn { background: var(--warn-soft); color: var(--warn); }
.ico-neutral { background: #EEF1F4; color: var(--muted); }

.note-box {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 12px 14px; font-size: 13.5px; color: var(--muted);
}
.footer-credit { text-align: center; font-size: 12.5px; color: var(--faint); padding: 22px 0 6px; }
.link-danger { color: var(--down); font-weight: 700; }

/* ==========================================================================
   Responsive system — tablet (768–1099px) & desktop (>=1100px)
   Mobile (<768px) stays exactly as designed above.
   ========================================================================== */

:root { --sidebar-w: 228px; }

/* dual-view helpers: mobile card lists vs desktop tables */
.only-desktop { display: none !important; }

/* desktop data tables (history / expenses / other profits / debts) */
.table-wrap {
  overflow-x: auto;                       /* wide tables scroll inside their container */
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 660px; }
.data-table th {
  text-align: right; font-size: 12.5px; color: var(--muted); font-weight: 700;
  padding: 10px 12px; border-bottom: 1px solid var(--line-strong);
  white-space: nowrap; background: var(--surface-2);
}
.data-table th[data-sort] { cursor: pointer; -webkit-user-select: none; user-select: none; }
.data-table th .dir { font-size: 10px; opacity: .85; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .row-actions { white-space: nowrap; text-align: left; }
.data-table .row-actions .btn { min-height: 38px; padding: 5px 12px; font-size: 13px; }

/* keyboard focus rings (desktop/keyboard users) */
:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: none; border-color: var(--primary);
}

/* hover feedback — only for real pointers, never sticky on touch */
@media (hover: hover) and (pointer: fine) {
  .btn:hover { filter: brightness(1.06); }
  .btn.ghost:hover, .btn.secondary:hover { filter: none; background: var(--primary-soft); }
  .btn.ghost:hover { border-color: var(--primary); }
  .chip:hover { border-color: var(--primary); color: var(--primary); }
  .chip.active:hover { color: #fff; }
  .tx-row:hover, .mini-tx:hover { border-color: var(--line-strong); }
  .menu-item:hover { background: var(--surface-2); }
  .bal-card .bal-edit:hover { text-decoration: underline; }
  .data-table tbody tr.row-click:hover td { background: var(--surface-2); }
  .data-table th[data-sort]:hover { color: var(--primary); }
  .seg-btn:not(.active):hover { border-color: var(--primary); }
}

/* ---------------- tablet & desktop shell (>=768px) ---------------- */
@media (min-width: 768px) {
  .only-mobile { display: none !important; }
  .only-desktop { display: block !important; }

  #app { padding-right: var(--sidebar-w); min-height: 100vh; min-height: 100dvh; background: var(--bg); }

  /* bottom tab bar → right sidebar (RTL) */
  #tabbar { display: none; }

  #sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
    width: var(--sidebar-w);
    background: var(--surface); border-left: 1px solid var(--line);
    padding: 16px 12px 14px;
    overflow-y: auto;
  }
  .side-brand {
    display: flex; align-items: center; gap: 9px;
    font-size: 16px; font-weight: 800; color: var(--primary-dark);
    padding: 2px 8px 14px;
  }
  .side-logo {
    width: 34px; height: 34px; border-radius: 10px; flex: none;
    background: var(--primary-dark); color: #fff;
    display: flex; align-items: center; justify-content: center;
  }
  .side-logo svg { width: 18px; height: 18px; }
  .side-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 46px; padding: 9px 12px;
    border-radius: 12px; font-size: 14.5px; font-weight: 700; color: var(--muted);
    text-align: right; transition: background .12s, color .12s;
  }
  .side-item svg { width: 20px; height: 20px; flex: none; }
  .side-item.active { background: var(--primary-soft); color: var(--primary); }
  .side-sep { height: 1px; background: var(--line); margin: 10px 6px; flex: none; }
  .side-foot { margin-top: auto; padding: 12px 8px 0; font-size: 11px; color: var(--faint); line-height: 1.8; }
  .side-foot kbd {
    display: inline-block; min-width: 17px; text-align: center;
    border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px;
    background: var(--surface-2); padding: 0 4px; font-family: inherit; font-size: 10.5px; color: var(--muted);
  }

  /* content area: constrained, centered, never stretched */
  #main { max-width: 940px; margin: 0 auto; padding: 18px 24px 40px; }

  /* header spans the content area next to the sidebar (safe-area insets = 0 on desktop) */
  #app-header { position: sticky; }

  /* filters in a top bar row instead of stacked */
  .filter-bar { flex-direction: row; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
  .filter-bar > * { flex: 1 1 200px; min-width: 0; }
  .filter-bar .filter-row { display: flex; flex: 2 1 320px; gap: 10px; }
  .filter-bar .filter-count { flex: 0 0 auto; display: flex; align-items: center; padding-bottom: 2px; }

  /* forms never stretch across the full screen */
  .form-narrow { max-width: 640px; }

  /* modals: centered dialogs instead of bottom sheets */
  #modal-root .modal-backdrop { align-items: center; padding: 24px; }
  #modal-root .modal {
    border-radius: 18px;
    padding: 18px 18px 16px;
    max-height: 86vh; max-height: 86dvh;
  }
  #toast-root { bottom: 26px; }

  /* setup overlay stays phone-sized and centered */
  .setup-overlay .screen { max-width: 560px; margin: 0 auto; }
}

/* ---------------- desktop (>=1100px): wide layouts ---------------- */
@media (min-width: 1100px) {
  #main { max-width: 1120px; }

  /* home: balance cards grid + profit cards next to chart */
  .balance-grid { grid-template-columns: repeat(4, 1fr); }
  .bal-card.wide { grid-column: auto; }
  .home-top { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 14px; align-items: stretch; }
  .home-top .stats-grid { grid-template-columns: 1fr; gap: 8px; }
  .home-top .stat-card { display: flex; align-items: center; justify-content: space-between; text-align: right; padding: 12px 16px; }
  .home-top .stat-card .stat-val { font-size: 20px; order: 2; }
  .home-top .stat-card .stat-lbl { order: 1; margin-top: 0; font-size: 13px; }

  /* reports: two-column grid */
  #screen-reports.active { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 18px; align-items: start; }
  #screen-reports.active > .rp-full { grid-column: 1 / -1; }
  #screen-reports.active > .rp-l { grid-column: 1; }
  #screen-reports.active > .rp-r { grid-column: 2; }

  /* new operation: form + always-visible preview side by side */
  .tx-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    column-gap: 22px;
    align-items: start;
    max-width: 1040px;
  }
  .tx-form > .fx-svc     { grid-column: 1; grid-row: 1; }
  .tx-form > .fx-type    { grid-column: 1; grid-row: 2; }
  .tx-form > .fx-amt     { grid-column: 1; grid-row: 3; }
  .tx-form > .fx-collect { grid-column: 1; grid-row: 4; }
  .tx-form > .fx-fee     { grid-column: 1; grid-row: 5; }
  .tx-form > .fx-cust    { grid-column: 1; grid-row: 6; }
  .tx-form > .fx-note    { grid-column: 1; grid-row: 7; }
  .tx-form > .fx-date    { grid-column: 1; grid-row: 8; }
  .tx-form > .fx-save    { grid-column: 1; grid-row: 9; }
  .tx-form > .fx-ptitle  { grid-column: 2; grid-row: 1; margin-top: 2px; }
  .tx-form > .fx-preview { grid-column: 2; grid-row: 2 / 9; align-self: start; position: sticky; top: calc(var(--header-h) + 14px); }
  .tx-form > .fx-preview .preview-card { margin: 0; }
}

/* ==========================================================================
   الاشتراك: شاشة التسجيل والتجديد
   ========================================================================== */
.renew-ico { background: var(--down-soft); color: var(--down); }
.renew-status {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 14px; margin-top: 10px; text-align: right;
}
.renew-line { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 14px; }
.renew-line span { color: var(--muted); }
.renew-line b { direction: ltr; unicode-bidi: isolate; }
.pay-box { background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 12px 14px; margin: 10px 0 14px; }
.pay-line { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-size: 14.5px; }
.pay-line b { font-variant-numeric: tabular-nums; }
.pay-note { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.7; }
.btn.whatsapp { background: #1FA855; color: #fff; text-decoration: none; }
@media (hover: hover) and (pointer: fine) { .btn.whatsapp:hover { filter: brightness(1.07); } }
