/* ===========================
   DESIGN SYSTEM
   =========================== */
:root {
  --bg: #080a0f;
  --surface: #0e1117;
  --surface2: #141820;
  --surface3: #1a2030;
  --border: #1e2535;
  --border2: #263040;
  --text: #dde4f0;
  --text2: #7a8599;
  --text3: #434e65;
  --green: #1dd37a;
  --green-dim: #0a2d1c;
  --green-glow: rgba(29,211,122,.15);
  --red: #ff4560;
  --red-dim: #2d0a12;
  --red-glow: rgba(255,69,96,.15);
  --gold: #f0b429;
  --gold-dim: #2d240a;
  --blue: #3d8ef0;
  --blue-dim: #0a1e2d;
  --accent: #6c5ce7;
  --accent2: #a29bfe;
  --accent-dim: #16133a;
  --r: 12px;
  --r-sm: 8px;
  --r-lg: 20px;
  --shadow: 0 8px 32px rgba(0,0,0,.5);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.6);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* Noise texture overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

/* ===========================
   SCREENS
   =========================== */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }
#app { position: relative; }

/* ===========================
   LOGIN — DESKTOP FIRST
   =========================== */
#loginScreen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  flex-direction: column !important;
  padding: 24px;
  background: radial-gradient(ellipse 80% 50% at 50% 0%, rgba(108,92,231,.1) 0%, transparent 65%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: clamp(28px,5vw,44px) clamp(24px,5vw,40px);
  box-shadow: 0 0 60px rgba(108,92,231,.08), var(--shadow-lg);
  animation: fadeUp .4s ease;
  position: relative;
}
.login-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: 20px 20px 0 0;
}
@keyframes fadeUp {
  from { opacity:0; transform:translateY(12px); }
  to   { opacity:1; transform:translateY(0); }
}
@keyframes float {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-5px); }
}
.login-logo {
  text-align: center;
  margin-bottom: 24px;
}
.login-logo-icon {
  font-size: 42px;
  display: block;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 20px rgba(108,92,231,.5));
  animation: float 4s ease-in-out infinite;
}
.login-logo h1 {
  font-family: 'Tajawal', sans-serif;
  font-size: clamp(26px,5vw,32px);
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #a29bfe, #6c5ce7, #3d8ef0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 3px;
}
.login-logo p {
  font-size: 12px;
  color: var(--text3);
}
.login-left { display: none; }
.login-right { display: contents; }
.login-form-wrap { width: 100%; }
.login-logo-sm { display: none; }
.login-tabs {
  display: flex;
  gap: 3px;
  background: var(--surface2);
  padding: 3px;
  border-radius: var(--r-sm);
  margin-bottom: 28px;
  border: 1px solid var(--border);
}
.login-tab {
  flex: 1;
  padding: 9px 8px;
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  color: var(--text3);
  user-select: none;
}
.login-tab.active {
  background: var(--surface3);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}

/* ===========================
   FORMS
   =========================== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  margin-bottom: 6px;
  letter-spacing: .8px;
  text-transform: uppercase;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: 14px;
  transition: border-color .2s, box-shadow .2s, background .2s;
  outline: none;
  font-variant-numeric: lining-nums;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  background: var(--surface3);
  box-shadow: 0 0 0 3px rgba(108,92,231,.12);
}
.form-group input[type="number"],
.form-group input[type="tel"] {
  direction: ltr;
  text-align: right;
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group select option { background: var(--surface2); }
.form-group .hint {
  font-size: 11px;
  color: var(--text3);
  margin-top: 5px;
}
.form-group .hint.err { color: var(--red); }
.pass-bar {
  height: 3px;
  border-radius: 2px;
  margin-top: 6px;
  transition: all .3s;
  background: var(--surface3);
}
.datetime-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: flex-end;
}
.now-btn {
  padding: 11px 13px;
  background: var(--accent-dim);
  border: 1px solid rgba(108,92,231,.3);
  border-radius: var(--r-sm);
  color: var(--accent2);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: all .2s;
  font-family: 'Cairo', sans-serif;
}
.now-btn:hover { background: rgba(108,92,231,.2); }

/* ===========================
   BUTTONS
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 20px;
  border-radius: var(--r-sm);
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: all .2s;
  white-space: nowrap;
  user-select: none;
}
.btn-primary {
  background: linear-gradient(135deg, #6c5ce7, #5a4bd4);
  color: #fff;
  box-shadow: 0 4px 20px rgba(108,92,231,.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 28px rgba(108,92,231,.5); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-full { width: 100%; padding: 13px; }
.btn-green { background: var(--green-dim); color: var(--green); border: 1px solid rgba(29,211,122,.2); }
.btn-green:hover { background: rgba(29,211,122,.12); }
.btn-red { background: var(--red-dim); color: var(--red); border: 1px solid rgba(255,69,96,.2); }
.btn-red:hover { background: rgba(255,69,96,.12); }
.btn-gold { background: var(--gold-dim); color: var(--gold); border: 1px solid rgba(240,180,41,.2); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 7px 13px; font-size: 12px; }
.btn-xs { padding: 5px 10px; font-size: 11px; border-radius: 6px; }

/* Alert boxes */
.alert { padding: 10px 14px; border-radius: var(--r-sm); font-size: 13px; display: none; margin-top: 10px; }
.alert.error { background: var(--red-dim); border: 1px solid rgba(255,69,96,.3); color: var(--red); }
.alert.success { background: var(--green-dim); border: 1px solid rgba(29,211,122,.3); color: var(--green); }
.alert.info { background: var(--gold-dim); border: 1px solid rgba(240,180,41,.3); color: var(--gold); }
.alert.show { display: block; animation: fadeSlideIn .2s ease; }

/* ===========================
   MAIN APP LAYOUT
   =========================== */
#mainScreen { background: var(--bg); }
.app-layout { display: block; min-height: 100vh; position: relative; }

/* Sidebar */
.sidebar {
  width: 260px;
  min-height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  right: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.sidebar-head {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  font-family: 'Tajawal', sans-serif;
  font-size: 20px;
  font-weight: 900;
  background: linear-gradient(135deg, #a29bfe, #6c5ce7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.user-ava {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
  flex-shrink: 0;
}
.user-chip-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-chip-role {
  font-size: 10px;
  color: var(--text3);
  background: var(--surface3);
  padding: 2px 7px;
  border-radius: 10px;
  display: inline-block;
  margin-top: 2px;
}
.nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--text3);
  padding: 10px 8px 5px;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  margin-bottom: 1px;
  position: relative;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent2); font-weight: 600; }
.nav-item.active::before {
  content: '';
  position: absolute;
  right: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
}
.nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-badge {
  background: var(--red);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  margin-right: auto;
}
.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); }

/* Main content */
.main-wrap {
  margin-right: 260px;
  min-height: 100vh;
  transition: margin .3s;
  overflow-x: hidden;
}
.page-inner {
  padding: 28px 32px;
  max-width: 1200px;
}
.page { display: none; }
.page.active { display: block; animation: fadeIn .25s ease; }

/* Page header */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-head h2 {
  font-family: 'Tajawal', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.page-head-actions { display: flex; gap: 8px; align-items: center; }

/* ===========================
   STATS GRID
   =========================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card::after {
  content: '';
  position: absolute;
  top: -20px; left: -20px;
  width: 100px; height: 100px;
  border-radius: 50%;
  opacity: .06;
}
.stat-card.green::after { background: var(--green); }
.stat-card.red::after { background: var(--red); }
.stat-card.gold::after { background: var(--gold); }
.stat-card.blue::after { background: var(--blue); }
.stat-icon { font-size: 20px; margin-bottom: 10px; }
.stat-label { font-size: 10px; font-weight: 700; letter-spacing: .6px; color: var(--text3); text-transform: uppercase; }
.stat-val {
  font-family: 'Tajawal', sans-serif;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  margin-top: 4px;
  font-variant-numeric: lining-nums;
}
.stat-card.green .stat-val { color: var(--green); }
.stat-card.red .stat-val { color: var(--red); }
.stat-card.gold .stat-val { color: var(--gold); }
.stat-card.blue .stat-val { color: var(--blue); }
.stat-sub { font-size: 11px; color: var(--text3); margin-top: 5px; }

/* ===========================
   FILTERS / CHIPS
   =========================== */
.filters {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.chip {
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text3);
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.chip:hover { background: var(--surface3); color: var(--text2); }
.chip.active { background: var(--accent-dim); color: var(--accent2); border-color: rgba(108,92,231,.3); }
.search-field {
  padding: 6px 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  outline: none;
  width: 180px;
  transition: border-color .2s;
  margin-right: auto;
}
.search-field:focus { border-color: var(--accent); }

/* ===========================
   DEBT CARDS
   =========================== */
.debt-list { display: flex; flex-direction: column; gap: 8px; }
.debt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 18px;
  cursor: pointer;
  transition: all .2s;
  border-right: 3px solid transparent;
  position: relative;
}
.debt-card:hover {
  background: var(--surface2);
  border-color: var(--border2);
  transform: translateX(-2px);
}
.debt-card.for-me { border-right-color: var(--green); }
.debt-card.on-me { border-right-color: var(--red); }
.debt-card.settled { border-right-color: var(--text3); opacity: .55; }
.debt-card.linked { border-style: dashed; }
.debt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.debt-person { display: flex; align-items: center; gap: 10px; }
.debt-ava {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.for-me .debt-ava { background: var(--green-dim); color: var(--green); }
.on-me .debt-ava { background: var(--red-dim); color: var(--red); }
.settled .debt-ava { background: var(--surface3); color: var(--text3); }
.debt-name { font-weight: 600; font-size: 14px; }
.debt-date { font-size: 11px; color: var(--text3); margin-top: 1px; }
.debt-amount-col { text-align: left; flex-shrink: 0; }
.debt-amt {
  font-family: 'Tajawal', sans-serif;
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: lining-nums;
  direction: ltr;
  display: block;
}
.for-me .debt-amt { color: var(--green); }
.on-me .debt-amt { color: var(--red); }
.settled .debt-amt { color: var(--text3); }
.debt-sub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.debt-desc { font-size: 12px; color: var(--text2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prog-wrap { height: 2px; background: var(--surface3); border-radius: 1px; margin-top: 6px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: 1px; transition: width .5s; }
.for-me .prog-fill { background: var(--green); }
.on-me .prog-fill { background: var(--red); }

/* Badges */
.badge {
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: .3px;
}
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-gold { background: var(--gold-dim); color: var(--gold); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }
.badge-gray { background: var(--surface3); color: var(--text3); }
.badge-purple { background: var(--accent-dim); color: var(--accent2); }

/* ===========================
   MODALS
   =========================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; animation: fadeIn .2s ease; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp .25s ease;
}
.modal-sm { max-width: 400px; }
.modal-lg { max-width: 640px; }
.modal-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-title { font-size: 15px; font-weight: 700; }
.modal-close {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--surface2);
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.modal-close:hover { background: var(--red-dim); color: var(--red); }
.modal-body { padding: 20px; }
.modal-foot { padding: 0 20px 20px; display: flex; gap: 8px; justify-content: flex-end; }

/* Type selector */
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.type-btn {
  padding: 14px;
  border-radius: var(--r-sm);
  border: 2px solid var(--border);
  background: var(--surface2);
  color: var(--text3);
  cursor: pointer;
  transition: all .2s;
  text-align: center;
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 600;
  user-select: none;
}
.type-btn .ti { font-size: 22px; display: block; margin-bottom: 5px; }
.type-btn.sel-green { border-color: var(--green); background: var(--green-dim); color: var(--green); }
.type-btn.sel-red { border-color: var(--red); background: var(--red-dim); color: var(--red); }

/* Person dropdown */
.pdrop-wrap { position: relative; }
.pdrop-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: 14px;
  outline: none;
  transition: all .2s;
}
.pdrop-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,92,231,.12); }
.pdrop-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0; left: 0;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  z-index: 300;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.pdrop-list.open { display: block; animation: fadeIn .15s ease; }
.pdrop-item {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .1s;
}
.pdrop-item:hover { background: var(--surface3); }
.pdrop-ava {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--accent-dim);
  color: var(--accent2);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.pdrop-meta { font-size: 11px; color: var(--text3); }
.pdrop-item.new-item { color: var(--gold); border-top: 1px solid var(--border); }
.pdrop-item.new-item .pdrop-ava { background: var(--gold-dim); color: var(--gold); }

/* ===========================
   DETAIL PANEL
   =========================== */
.detail-panel {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 150;
  background: var(--bg);
  overflow-y: auto;
}
.detail-panel.open { display: block; animation: slideRight .3s ease; }
.detail-panel-head {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  flex-wrap: wrap;
}
.back-btn {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text2);
  font-size: 16px;
  transition: all .2s;
  flex-shrink: 0;
}
.back-btn:hover { background: var(--surface2); color: var(--text); }
.detail-body { padding: 24px; max-width: 680px; margin: 0 auto; }
.detail-hero {
  text-align: center;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: 22px;
  position: relative;
  overflow: hidden;
}
.detail-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: .04;
  border-radius: var(--r-lg);
}
.detail-hero.for-me::before { background: radial-gradient(circle at 50% 40%, var(--green), transparent 70%); }
.detail-hero.on-me::before { background: radial-gradient(circle at 50% 40%, var(--red), transparent 70%); }
.hero-amt {
  font-family: 'Tajawal', sans-serif;
  font-size: clamp(36px, 6vw, 52px);
  font-weight: 900;
  line-height: 1;
  margin: 12px 0;
  font-variant-numeric: lining-nums;
  direction: ltr;
  display: block;
}
.for-me .hero-amt { color: var(--green); text-shadow: 0 0 40px var(--green-glow); }
.on-me .hero-amt { color: var(--red); text-shadow: 0 0 40px var(--red-glow); }
.timeline { position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  right: 16px; top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}
.tl-item { display: flex; gap: 14px; margin-bottom: 16px; }
.tl-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  flex-shrink: 0;
  margin-top: 6px;
  z-index: 1;
}
.tl-dot.origin { background: var(--accent); width: 16px; height: 16px; margin-top: 4px; }
.tl-dot.pay { background: var(--green); }
.tl-dot.add { background: var(--gold); }
.tl-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  flex: 1;
}
.tl-title { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.tl-meta { font-size: 11px; color: var(--text3); }
.tl-amt {
  font-family: 'Tajawal', sans-serif;
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: lining-nums;
  direction: ltr;
  display: inline-block;
}

/* ===========================
   PEOPLE GRID
   =========================== */
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.person-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px;
  cursor: pointer;
  transition: all .2s;
}
.person-card:hover { background: var(--surface2); transform: translateY(-2px); box-shadow: var(--shadow); }
.person-card-ava {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-dim), rgba(108,92,231,.3));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: var(--accent2);
  margin-bottom: 12px;
}
.person-card h3 { font-size: 14px; font-weight: 600; }
.bal-pos { color: var(--green); font-family: 'Tajawal', sans-serif; font-weight: 700; font-size: 15px; font-variant-numeric: lining-nums; }
.bal-neg { color: var(--red); font-family: 'Tajawal', sans-serif; font-weight: 700; font-size: 15px; font-variant-numeric: lining-nums; }
.bal-zero { color: var(--text3); font-family: 'Tajawal', sans-serif; font-weight: 700; font-size: 15px; }

/* ===========================
   NOTIFS
   =========================== */
.notif-list { display: flex; flex-direction: column; gap: 6px; }
.notif-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 13px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  transition: all .15s;
}
.notif-item.unread { border-color: rgba(108,92,231,.3); background: rgba(108,92,231,.04); }
.notif-item:hover { background: var(--surface2); }
.notif-icon { font-size: 20px; flex-shrink: 0; }
.notif-title { font-weight: 600; font-size: 13px; }
.notif-body { font-size: 12px; color: var(--text2); margin-top: 2px; }
.notif-time { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* ===========================
   USERS LIST (Admin)
   =========================== */
.user-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  transition: border-color .2s;
}
.user-row:hover { border-color: var(--border2); }
.user-row.selected-row { border-color: rgba(108,92,231,.4); background: rgba(108,92,231,.04); }
.user-row-info { flex: 1; min-width: 0; }
.user-row-info h4 { font-size: 14px; font-weight: 600; }
.user-row-phone { font-size: 11px; color: var(--text3); direction: ltr; display: inline-block; margin-top: 1px; }
.user-row-tags { display: flex; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.user-row-actions { display: flex; gap: 5px; flex-shrink: 0; }

/* Excel Import */
.drop-zone {
  border: 2px dashed var(--border2);
  border-radius: var(--r);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  color: var(--text3);
  margin-bottom: 16px;
}
.drop-zone:hover, .drop-zone.drag { border-color: var(--accent); background: var(--accent-dim); color: var(--accent2); }
.import-table-wrap { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; max-height: 240px; overflow-y: auto; }
.import-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.import-table th { background: var(--surface3); padding: 8px 12px; text-align: right; color: var(--text2); font-weight: 600; }
.import-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.import-table tr:last-child td { border-bottom: none; }
.row-err td { color: var(--red); background: rgba(255,69,96,.04); }

/* ===========================
   PERMISSIONS TABLE
   =========================== */
.perm-grid { display: grid; gap: 2px; }
.perm-row {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: var(--r-sm);
  gap: 12px;
  font-size: 13px;
}
.perm-row:nth-child(even) { background: var(--surface3); }
.perm-row-name { flex: 1; font-weight: 500; }
.perm-check {
  width: 20px; height: 20px;
  border-radius: 5px;
  border: 2px solid var(--border2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  flex-shrink: 0;
  font-size: 11px;
  background: var(--surface);
}
.perm-check.checked { background: var(--green); border-color: var(--green); color: #fff; }

/* ===========================
   MOBILE TOPBAR
   =========================== */
.mobile-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  box-sizing: border-box;
}
.hamburger {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 16px;
  color: var(--text2);
  flex-shrink: 0;
}
.mobile-logo { font-family: 'Tajawal', sans-serif; font-size: 18px; font-weight: 900; background: linear-gradient(135deg, #a29bfe, #6c5ce7); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.mobile-notif-btn { margin-right: auto; cursor: pointer; position: relative; font-size: 18px; }
.mob-notif-dot {
  display: none;
  position: absolute;
  top: -2px; left: -2px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--surface);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0,0,0,.6);
}
.sidebar-overlay.open { display: block; }

/* ===========================
   TOAST
   =========================== */
.toasts {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  padding: 11px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  animation: slideUp .3s ease;
  min-width: 240px;
  max-width: 360px;
  font-size: 13px;
  font-weight: 500;
}
.toast.success { border-color: rgba(29,211,122,.3); }
.toast.error { border-color: rgba(255,69,96,.3); }

/* ===========================
   EMPTY STATE
   =========================== */
.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--text3);
}
.empty-icon { font-size: 44px; margin-bottom: 14px; opacity: .4; }
.empty h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; color: var(--text2); }
.empty p { font-size: 13px; max-width: 300px; margin: 0 auto; line-height: 1.6; }

/* ===========================
   CHARTS
   =========================== */
.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: 16px;
}
.chart-title { font-size: 13px; font-weight: 700; color: var(--text2); margin-bottom: 14px; }
.bar-chart { display: flex; align-items: flex-end; gap: 5px; height: 72px; }
.bar-item { flex: 1; border-radius: 3px 3px 0 0; min-width: 14px; cursor: pointer; transition: opacity .2s; }
.bar-item:hover { opacity: .8; }
.bar-labels { display: flex; gap: 5px; margin-top: 6px; }
.bar-label { flex: 1; text-align: center; font-size: 10px; color: var(--text3); }
.section-sep { font-size: 13px; font-weight: 700; color: var(--text2); margin-bottom: 12px; margin-top: 20px; display: flex; align-items: center; gap: 8px; }

/* ===========================
   ANIMATIONS
   =========================== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideRight { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* ===========================
   RESPONSIVE
   =========================== */

/* =============================================
   RESPONSIVE — MOBILE FIRST
   ============================================= */

/* Tablet & Mobile */

/* Small phones */


@media (max-width: 900px) {
  /* ── sidebar: هيد عن الشاشة لليمين ── */
  .sidebar {
    transform: translateX(110%) !important;
    width: 80vw;
    max-width: 300px;
  }
  .sidebar.open {
    transform: translateX(0) !important;
    box-shadow: -20px 0 60px rgba(0,0,0,.8);
  }

  /* ── main: يملأ الشاشة ── */
  .main-wrap {
    margin-right: 0 !important;
    width: 100% !important;
    box-sizing: border-box;
  }

  /* ── top bar ── */
  .mobile-bar { display: flex !important; }

  /* ── page ── */
  .page-inner {
    padding: 12px 12px 100px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  /* ── stats ── */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-val { font-size: 22px; }

  /* ── filters scroll ── */
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    gap: 5px;
  }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; font-size: 12px; padding: 6px 12px; }

  /* ── modals من الأسفل ── */
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal {
    border-radius: 20px 20px 0 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh !important;
    margin: 0 !important;
  }
  .modal-head { padding: 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 0 16px 32px; gap: 8px; }

  /* ── debt cards ── */
  .debt-card { padding: 11px 12px; }
  .debt-name { font-size: 13px; }

  /* ── detail ── */
  .hero-amt { font-size: 28px !important; }
  .detail-hero { padding: 20px 14px; }
  .detail-body { padding: 12px 14px; }

  /* ── page head ── */
  .page-head { flex-wrap: wrap; gap: 8px; }
  .page-head h2 { font-size: 17px; }

  /* ── datetime ── */
  .datetime-row { grid-template-columns: 1fr 1fr; }
  .datetime-row .now-btn { grid-column: 1 / -1; }

  /* ── people ── */
  .people-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* ── iOS zoom fix ── */
  input, select, textarea { font-size: 16px !important; }

  /* ── misc ── */
  .login-left { display: none; }
  #page-settings > div { max-width: 100% !important; }
  #bulkBar { flex-wrap: wrap; }
  .user-row { padding: 10px 12px; }
  .type-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .people-grid { grid-template-columns: 1fr; }
  .page-inner { padding: 10px 10px 100px; }
  .login-card { padding: 24px 18px; }
  .stat-val { font-size: 20px; }
}
