/* ============================================================
   دفتر الحسابات — نظام التصميم
   المرجع: ledger-design/SKILL.md v2 — "توهّج زجاجي" (Glass Glow)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@700;800&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  /* الخلفية */
  --bg: #0A0E1A;
  --bg-elevated: #10162A;
  --bg-sunken: #060911;

  /* الزجاج */
  --glass-bg: rgba(255,255,255,0.055);
  --glass-bg-strong: rgba(255,255,255,0.09);
  --glass-border: rgba(255,255,255,0.12);
  --glass-border-glow: rgba(120,170,255,0.45);

  /* التدرّج الأساسي */
  --blue: #3B82F6;
  --cyan: #22D3EE;
  --violet: #8B5CF6;
  --gradient-primary: linear-gradient(135deg, var(--blue), var(--cyan));
  --gradient-accent: linear-gradient(135deg, var(--violet), #EC4899);

  /* الحالات الوظيفية */
  --emerald: #34D399;
  --emerald-glow: rgba(52,211,153,0.45);
  --rose: #FB7185;
  --rose-glow: rgba(251,113,133,0.45);
  --amber: #FBBF24;
  --amber-glow: rgba(251,191,36,0.4);

  /* النص */
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --text-dim: #5B6B85;

  /* توافق أسماء قديمة (تُستخدم بمكان أو مكانين قديم بالكود) */
  --white: var(--bg);
  --off-white: var(--bg-sunken);
  --ink: var(--text);
  --muted: var(--text-muted);
  --alert-red: var(--rose);
  --alert-red-tint: rgba(251,113,133,0.14);
  --blue-950: var(--bg-elevated);
  --blue-800: var(--blue);
  --blue-600: var(--blue);
  --blue-400: var(--cyan);
  --blue-200: rgba(59,130,246,0.25);
  --blue-100: var(--glass-border);

  /* الطباعة */
  --font-display: 'Cairo', sans-serif;
  --font-body: 'IBM Plex Sans Arabic', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  /* القياسات */
  --radius: 18px;
  --radius-lg: 24px;
  --gap: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 800; }
.num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
a { color: inherit; text-decoration: none; }
button { font-family: var(--font-body); cursor: pointer; }
input, select, textarea { font-family: var(--font-body); }

#app {
  max-width: 560px; margin: 0 auto; min-height: 100vh; position: relative; padding-bottom: 96px;
  background: var(--bg);
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--rose-glow); }
  50% { box-shadow: 0 0 14px 3px var(--rose-glow); }
}
@keyframes screenEnter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

#content { animation: screenEnter 320ms var(--ease); }

/* ---------- Focus ring (a11y) ---------- */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(34,211,238,0.2);
}

/* ---------- Topbar ---------- */
.topbar {
  position: relative;
  background: var(--bg-elevated);
  color: var(--text);
  padding: 20px 18px 16px;
  overflow: hidden;
}
.topbar::before {
  content: '';
  position: absolute; inset: -40% -20% auto -20%; height: 220px;
  background: radial-gradient(circle at 70% 20%, rgba(59,130,246,0.35), transparent 60%),
              radial-gradient(circle at 20% 60%, rgba(139,92,246,0.28), transparent 55%);
  pointer-events: none;
}
.topbar > * { position: relative; z-index: 1; }
.topbar .brand { font-family: var(--font-display); font-size: 24px; font-weight: 800; letter-spacing: .2px; }
.topbar .sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.topbar .search-row { margin-top: 14px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: 14px; padding: 10px 12px;
  backdrop-filter: blur(16px) saturate(140%);
  transition: border-color .25s var(--ease);
}
.search-box:focus-within { border-color: var(--glass-border-glow); }
.search-box input {
  background: none; border: none; color: var(--text); flex: 1; font-size: 14px; outline: none;
}
.search-box input::placeholder { color: var(--text-dim); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.bell-btn {
  background: var(--glass-bg); border: 1px solid var(--glass-border); color: var(--text);
  width: 40px; height: 40px; border-radius: 13px; display: flex; align-items: center; justify-content: center;
  position: relative; flex-shrink: 0; backdrop-filter: blur(16px);
  transition: border-color .25s var(--ease), transform .15s var(--ease);
}
.bell-btn:active { transform: scale(0.94); }
.bell-badge {
  position: absolute; top: -4px; left: -4px; background: var(--rose); color: #240a0d;
  font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px; font-family: var(--font-mono);
  animation: glowPulse 2.4s var(--ease) infinite;
}
.month-nav {
  display: flex; align-items: center; justify-content: space-between; margin-top: 14px;
  background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: 14px; padding: 8px 10px;
  backdrop-filter: blur(16px);
}
.month-nav button {
  background: var(--glass-bg-strong); border: none; color: var(--text);
  width: 30px; height: 30px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  transition: transform .15s var(--ease);
}
.month-nav button:active { transform: scale(0.9); }
.month-nav .label { font-family: var(--font-display); font-weight: 800; font-size: 15px; }

/* ---------- Content ---------- */
.content { padding: 16px; }
.section-title {
  font-size: 13px; font-weight: 600; color: var(--text-muted); margin: 20px 2px 10px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ---------- KPI grid ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card {
  background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius);
  padding: 14px; backdrop-filter: blur(20px) saturate(140%);
  transition: border-color .25s var(--ease), transform .2s var(--ease);
}
.stat-card:hover { border-color: var(--glass-border-glow); }
.stat-card .lbl { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .val { font-size: 18px; font-weight: 600; }
.stat-card.wide { grid-column: 1 / 3; display: flex; align-items: center; justify-content: space-between; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 4px 10px;
  border-radius: 20px; font-weight: 600;
}
.tag.owe-me { background: rgba(52,211,153,0.14); color: var(--emerald); }
.tag.i-owe { background: rgba(251,113,133,0.14); color: var(--rose); }

/* ---------- Glass cards (list items) ---------- */
.card {
  background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; backdrop-filter: blur(20px) saturate(140%);
  transition: border-color .25s var(--ease);
}
.card:hover { border-color: var(--glass-border-glow); }
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-title { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.card-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.progress { height: 6px; background: var(--glass-bg-strong); border-radius: 6px; margin-top: 10px; overflow: hidden; }
.progress > div { height: 100%; background: var(--gradient-primary); border-radius: 6px; box-shadow: 0 0 10px rgba(59,130,246,0.5); transition: width .4s var(--ease); }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px; }
.pill.remain { background: rgba(251,113,133,0.14); color: var(--rose); }
.pill.done { background: rgba(52,211,153,0.14); color: var(--emerald); box-shadow: 0 0 12px -2px var(--emerald-glow); }
.pill.overdue { background: var(--rose); color: #240a0d; animation: glowPulse 2.4s var(--ease) infinite; }
.pill.upcoming { background: rgba(251,191,36,0.16); color: var(--amber); }

/* ---------- Entries (ledger rows -> glass rows with glow rail) ---------- */
.entry-row {
  display: flex; align-items: center; justify-content: space-between; padding: 11px 0;
  border-top: 1px solid var(--glass-border); position: relative;
}
.entry-row:first-child { border-top: none; }
.entry-row .rail {
  position: absolute; right: -14px; top: 6px; bottom: 6px; width: 3px; border-radius: 3px;
}
.entry-row.status-full .rail { background: var(--gradient-primary); box-shadow: 0 0 8px rgba(59,130,246,0.6); }
.entry-row.status-partial .rail { background: var(--text-dim); }
.entry-left { display: flex; flex-direction: column; gap: 2px; }
.entry-date { font-size: 12px; color: var(--text-muted); }
.entry-note { font-size: 12.5px; color: var(--text-muted); }
.entry-amount { font-weight: 700; color: var(--text); font-size: 15px; }
.entry-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  background: var(--glass-bg-strong); border: 1px solid transparent; width: 32px; height: 32px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; color: var(--text-muted);
  transition: border-color .2s var(--ease), color .2s var(--ease), transform .15s var(--ease);
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.danger { color: var(--rose); }
.icon-btn.active { color: var(--cyan); border-color: rgba(34,211,238,0.35); }

.empty { text-align: center; color: var(--text-muted); font-size: 13.5px; padding: 44px 14px; }
.empty .big { font-size: 32px; margin-bottom: 10px; opacity: .7; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(calc(-50% + 240px));
  width: 56px; height: 56px; border-radius: 18px; background: var(--gradient-primary); color: #051025;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(59,130,246,0.45), 0 0 0 1px rgba(255,255,255,0.15) inset;
  border: none; z-index: 40; transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
.fab:active { transform: translateX(calc(-50% + 240px)) scale(0.93); box-shadow: 0 4px 16px rgba(59,130,246,0.5); }
@media (max-width: 600px) { .fab { right: 18px; left: auto; transform: none; } .fab:active { transform: scale(0.93); } }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; max-width: 560px; margin: 0 auto;
  background: var(--glass-bg-strong); border-top: 1px solid var(--glass-border);
  backdrop-filter: blur(24px) saturate(160%);
  display: flex; padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 41;
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; color: var(--text-dim); padding: 6px 0; font-size: 10.5px;
  transition: color .2s var(--ease);
}
.tab-btn.active { color: var(--cyan); font-weight: 700; }

/* ---------- Bottom sheet / modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(4,7,14,.6); backdrop-filter: blur(2px); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s var(--ease);
}
.overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  width: 100%; max-width: 560px; background: var(--bg-elevated); border: 1px solid var(--glass-border);
  border-bottom: none; border-radius: 24px 24px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .28s var(--ease); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 -20px 60px rgba(0,0,0,.5);
}
.overlay.open .sheet { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; background: var(--glass-border); border-radius: 4px; margin: 0 auto 14px; }
.sheet h3 { margin: 0 0 14px; font-size: 19px; color: var(--text); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.field input[type=text], .field input[type=number], .field input[type=date], .field input[type=password],
.field select, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1.5px solid var(--glass-border);
  font-family: var(--font-body); font-size: 14.5px; background: var(--bg-sunken); color: var(--text);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--cyan); outline: none; box-shadow: 0 0 0 3px rgba(34,211,238,0.15);
}
.field textarea { resize: none; min-height: 60px; }
.field-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.field-error { font-size: 12px; color: var(--rose); margin-top: 5px; }

.seg { display: flex; background: var(--bg-sunken); border-radius: 12px; padding: 4px; gap: 4px; border: 1px solid var(--glass-border); }
.seg button { flex: 1; border: none; background: none; padding: 9px; border-radius: 9px; font-weight: 600; font-size: 13.5px; color: var(--text-muted); transition: all .2s var(--ease); }
.seg button.active { background: var(--gradient-primary); color: #051025; box-shadow: 0 2px 10px rgba(59,130,246,0.4); }

.photo-picker { display: flex; align-items: center; gap: 10px; }
.photo-thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; border: 1.5px solid var(--glass-border); }
.photo-btn { flex: 1; border: 1.5px dashed var(--glass-border); border-radius: 12px; padding: 14px; text-align: center; color: var(--text-muted); font-size: 13px; background: var(--bg-sunken); }

.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  border: none; border-radius: 13px; padding: 13px; font-family: var(--font-body); font-weight: 700;
  font-size: 14.5px; display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .15s var(--ease), box-shadow .2s var(--ease), filter .2s var(--ease);
}
.btn.block { width: 100%; }
.btn.flex { flex: 1; }
.btn.primary { background: var(--gradient-primary); color: #051025; box-shadow: 0 4px 18px rgba(59,130,246,0.35); }
.btn.primary:active { transform: scale(0.97); filter: brightness(1.08); }
.btn.ghost { background: var(--glass-bg-strong); color: var(--text); border: 1px solid var(--glass-border); }
.btn.ghost:active { transform: scale(0.97); }
.btn.danger { background: rgba(251,113,133,0.14); color: var(--rose); }
.btn.danger:active { transform: scale(0.97); }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ---------- Viewer / toast ---------- */
.viewer {
  position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 70;
  display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .2s var(--ease);
}
.viewer.open { opacity: 1; pointer-events: auto; }
.viewer img { max-width: 92%; max-height: 80%; border-radius: 14px; }
.viewer .close { position: absolute; top: 20px; left: 20px; background: var(--glass-bg-strong); border: 1px solid var(--glass-border); color: #fff; width: 38px; height: 38px; border-radius: 12px; backdrop-filter: blur(10px); }

.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(6px);
  background: var(--glass-bg-strong); border: 1px solid var(--glass-border-glow); backdrop-filter: blur(20px);
  color: var(--text); padding: 11px 20px; border-radius: 14px;
  font-size: 13px; z-index: 80; opacity: 0; transition: opacity .25s var(--ease), transform .25s var(--ease); pointer-events: none;
  max-width: 90%; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading-full { display: flex; align-items: center; justify-content: center; height: 60vh; color: var(--text-muted); font-size: 13px; }

/* ---------- Signature glow badge (replaces ink stamp) ---------- */
.stamp-mark { color: var(--emerald); flex-shrink: 0; filter: drop-shadow(0 0 10px var(--emerald-glow)); }

/* ---------- Global search results ---------- */
.search-results {
  position: fixed; inset: 0; background: var(--bg); z-index: 55; overflow-y: auto;
  padding: 16px; padding-bottom: 40px; animation: screenEnter 220ms var(--ease);
}
.search-result-item {
  display: block; padding: 12px 0; border-top: 1px solid var(--glass-border);
}
.search-result-item:first-child { border-top: none; }
.search-result-type { font-size: 11px; color: var(--cyan); font-weight: 600; margin-bottom: 3px; }

/* ---------- Reminders / bell panel ---------- */
.reminder-item {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 0;
  border-top: 1px solid var(--glass-border);
}
.reminder-item:first-child { border-top: none; }

/* ---------- Login screen ---------- */
.login-wrap {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px; position: relative; overflow: hidden;
}
.login-wrap::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 25% 20%, rgba(59,130,246,0.25), transparent 45%),
              radial-gradient(circle at 80% 75%, rgba(139,92,246,0.22), transparent 45%),
              radial-gradient(circle at 60% 10%, rgba(34,211,238,0.15), transparent 40%);
  pointer-events: none;
}
.login-card {
  position: relative; z-index: 1;
  background: var(--glass-bg-strong); border: 1px solid var(--glass-border); backdrop-filter: blur(24px) saturate(140%);
  border-radius: var(--radius-lg); padding: 32px 26px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .display { font-size: 30px; background: var(--gradient-primary); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-brand .sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Utility ---------- */
.text-red { color: var(--rose); }
.text-blue { color: var(--cyan); }
.text-muted { color: var(--text-muted); }
