/* ============================================
   نظام الحسابات — Professional Fintech Theme
   Clean · Bold · Modern Dashboard
   ============================================ */

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

/* ── Tokens ── */
:root {
  --bg:         #F0F2F5;
  --bg2:        #E8EBF0;
  --surface:    #FFFFFF;
  --surface2:   #F8FAFC;
  --border:     #E2E8F0;
  --border2:    #CBD5E1;

  --text:       #0F172A;
  --text2:      #334155;
  --muted:      #64748B;
  --muted2:     #94A3B8;

  /* Brand */
  --primary:    #16A34A;
  --primary-d:  #15803D;
  --primary-l:  #DCFCE7;
  --primary-t:  rgba(22,163,74,.12);

  /* Semantics */
  --green:      #16A34A;
  --green-l:    #DCFCE7;
  --red:        #DC2626;
  --red-l:      #FEE2E2;
  --blue:       #2563EB;
  --blue-l:     #DBEAFE;
  --amber:      #D97706;
  --amber-l:    #FEF3C7;
  --violet:     #7C3AED;
  --violet-l:   #EDE9FE;

  --radius-xs:  6px;
  --radius-sm:  10px;
  --radius:     14px;
  --radius-lg:  18px;
  --radius-xl:  24px;

  --shadow-sm:  0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow:     0 4px 12px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg:  0 12px 32px rgba(15,23,42,.1), 0 4px 8px rgba(15,23,42,.06);
  --shadow-xl:  0 24px 48px rgba(15,23,42,.14), 0 8px 16px rgba(15,23,42,.08);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Cairo', -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow-x: hidden;
}
.hidden { display: none !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted2); }

/* ── Splash ── */
.splash {
  position: fixed; inset: 0; z-index: 99999;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0F172A 0%, #1E3A5F 50%, #0F4C2A 100%);
  transition: opacity .5s ease;
}
.splash-card {
  text-align: center;
  padding: 48px 40px;
  border-radius: var(--radius-xl);
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  min-width: min(320px, 88vw);
}
.splash-icon { font-size: 56px; line-height: 1; margin-bottom: 20px; }
.splash-title {
  font-size: 24px; font-weight: 900;
  color: #FFFFFF; margin-bottom: 6px; letter-spacing: .5px;
}
.splash-sub { font-size: 13px; color: rgba(255,255,255,.5); margin-bottom: 28px; }
.splash-loader {
  width: 34px; height: 34px; margin: 0 auto;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.15);
  border-top-color: #4ADE80;
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Intro ── */
.intro {
  position: fixed; inset: 0; z-index: 100000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(15,23,42,.65);
  backdrop-filter: blur(8px);
}
.intro-sheet {
  width: min(480px, 96vw);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  padding: 44px 32px 32px;
  text-align: center;
  border-top: 4px solid var(--primary);
}
.intro-emoji { font-size: 52px; margin-bottom: 18px; }
.intro-sheet h1 { font-size: 26px; font-weight: 900; margin: 0 0 10px; color: var(--text); }
.intro-sheet p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.7; }
.intro-slide { display: none; }
.intro-slide.active { display: block; }
.intro-actions { display: flex; gap: 12px; justify-content: center; margin-top: 32px; }

/* ── Login ── */
.login-gate {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(145deg, #0F172A 0%, #1A3A2A 40%, #162032 100%);
  background-size: 200% 200%;
}
.login-wrap {
  width: min(420px, 96vw);
  display: flex; flex-direction: column; gap: 28px; align-items: center;
}
.login-logo { text-align: center; }
.logo-icon {
  width: 88px; height: 88px; border-radius: 26px;
  background: linear-gradient(145deg, var(--primary), #166534);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  font-size: 42px;
  box-shadow: 0 20px 48px rgba(22,163,74,.4), 0 0 0 1px rgba(255,255,255,.08);
}
.login-logo h1 { font-size: 28px; font-weight: 900; color: #FFFFFF; margin: 0 0 6px; }
.login-logo p { font-size: 14px; color: rgba(255,255,255,.45); margin: 0; }
.login-card {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-xl);
}
.login-card h2 { font-size: 22px; font-weight: 900; margin: 0 0 24px; text-align: center; color: var(--text); }
.error-msg {
  margin-top: 14px; padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--red-l); color: var(--red);
  font-size: 13px; font-weight: 700; text-align: center;
  border: 1px solid rgba(220,38,38,.15);
}

/* ── Top Bar ── */
.topbar {
  position: sticky; top: 0; z-index: 200;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 32px; height: 32px; border-radius: 8px; }
.brand-title { font-size: 18px; font-weight: 900; color: var(--text); letter-spacing: -.3px; }
.brand-title span { color: var(--primary); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px;
  transition: all .15s;
  box-shadow: var(--shadow-sm);
}
.icon-btn:hover { background: var(--surface2); color: var(--text); border-color: var(--border2); }
.icon-btn:active { transform: scale(.95); }
.icon-btn.danger:hover { background: var(--red-l); color: var(--red); border-color: rgba(220,38,38,.2); }

/* ── Main ── */
main {
  max-width: 980px; margin: 0 auto;
  padding: 24px 20px 100px;
  position: relative;
}

/* ── Pages ── */
.page { display: none; }
.page.active { display: flex; flex-direction: column; gap: 18px; }

/* ── Section Headers ── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2px; padding: 0 2px;
}
.section-title {
  font-size: 18px; font-weight: 800; color: var(--text); letter-spacing: -.3px;
}
.section-count {
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  padding: 4px 12px; border-radius: 99px;
  box-shadow: var(--shadow-sm);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header { padding: 20px 20px 0; }
.card-header h3 {
  font-size: 17px; font-weight: 800;
  color: var(--text); margin: 0 0 16px;
  display: flex; align-items: center; gap: 10px;
}
.hdr-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.hdr-icon.blue   { background: var(--blue-l);   color: var(--blue); }
.hdr-icon.green  { background: var(--green-l);  color: var(--green); }
.hdr-icon.red    { background: var(--red-l);    color: var(--red); }
.hdr-icon.orange { background: var(--amber-l);  color: var(--amber); }

/* ── Forms ── */
.form-body { padding: 0 20px 20px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 7px; }
.field label {
  font-size: 12px; font-weight: 700; color: var(--text2);
  letter-spacing: .2px;
}
input, select, textarea {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
  appearance: none; -webkit-appearance: none;
}
input::placeholder { color: var(--muted2); }
input:focus, select:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath stroke='%2364748B' stroke-width='1.5' fill='none' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center;
  padding-left: 34px; cursor: pointer;
}
.form-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding: 14px 20px 20px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  background: var(--surface2);
}
.sep-line { border: none; border-top: 1px solid var(--border); margin: 0 20px; }

/* ── Buttons ── */
.btn {
  border: none; border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 14px; font-weight: 700;
  font-family: inherit; cursor: pointer;
  transition: all .15s ease;
  display: inline-flex; align-items: center; gap: 7px;
  white-space: nowrap; letter-spacing: .1px;
}
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 4px 14px rgba(22,163,74,.35);
}
.btn-primary:hover { background: var(--primary-d); box-shadow: 0 6px 20px rgba(22,163,74,.4); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text2);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--bg2); border-color: var(--border2); color: var(--text); }

.btn-ghost { background: transparent; color: var(--primary); font-weight: 700; }
.btn-ghost:hover { color: var(--primary-d); text-decoration: underline; }

.btn-danger {
  background: var(--red-l); color: var(--red);
  border: 1.5px solid rgba(220,38,38,.2);
}
.btn-danger:hover { background: #FECcCC; }

.btn-sm { padding: 7px 13px; font-size: 12px; border-radius: var(--radius-xs); }

.file-btn { position: relative; overflow: hidden; }
.file-btn input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ── KPI Cards ── */
.kpi-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
}
@media (max-width: 520px) { .kpi-grid { grid-template-columns: 1fr; gap: 10px; } }

.kpi-card {
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
  transition: transform .2s, box-shadow .2s;
  border: 1px solid transparent;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

/* Color variants */
.kpi-card.accent {
  background: linear-gradient(145deg, #0F4C2A, #16A34A);
  color: #fff;
  border-color: rgba(255,255,255,.1);
}
.kpi-card.green {
  background: linear-gradient(145deg, #064E3B, #059669);
  color: #fff; border-color: rgba(255,255,255,.1);
}
.kpi-card.red {
  background: linear-gradient(145deg, #7F1D1D, #DC2626);
  color: #fff; border-color: rgba(255,255,255,.1);
}
.kpi-card:not(.accent):not(.green):not(.red) {
  background: var(--surface); border-color: var(--border);
}

/* Decorative circle */
.kpi-card::after {
  content: '';
  position: absolute; top: -20px; left: -20px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,.06);
  pointer-events: none;
}

.kpi-label {
  font-size: 11px; font-weight: 800;
  color: rgba(255,255,255,.7); letter-spacing: .8px; text-transform: uppercase;
  margin-bottom: 10px;
}
.kpi-card:not(.accent):not(.green):not(.red) .kpi-label { color: var(--muted); }

.kpi-value {
  font-size: 28px; font-weight: 900; color: #FFFFFF;
  letter-spacing: -1px; line-height: 1.1; margin-bottom: 4px;
}
.kpi-card:not(.accent):not(.green):not(.red) .kpi-value { color: var(--text); }

.kpi-sub { font-size: 12px; font-weight: 600; color: rgba(255,255,255,.65); }
.kpi-card:not(.accent):not(.green):not(.red) .kpi-sub { color: var(--muted); }

/* ── List Items ── */
.list-group {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
  cursor: default;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface2); }
.list-item:active { background: var(--bg2); }

.item-icon {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.item-icon.blue   { background: var(--blue-l);   }
.item-icon.green  { background: var(--green-l);  }
.item-icon.red    { background: var(--red-l);    }
.item-icon.orange { background: var(--amber-l);  }
.item-icon.purple { background: var(--violet-l); }

.item-body { flex: 1; min-width: 0; }
.item-name {
  font-size: 15px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-detail { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.item-amount { font-size: 16px; font-weight: 800; color: var(--text); letter-spacing: -.4px; }
.item-amount.red   { color: var(--red); }
.item-amount.green { color: var(--green); }
.item-date { font-size: 11px; color: var(--muted2); }
.item-actions { display: flex; gap: 6px; }

/* Badge */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 99px;
  font-size: 11px; font-weight: 800; letter-spacing: .3px;
}
.badge-blue   { background: var(--blue-l);  color: var(--blue); }
.badge-green  { background: var(--green-l); color: var(--green); }
.badge-red    { background: var(--red-l);   color: var(--red); }
.badge-gray   { background: var(--bg2);     color: var(--muted); border: 1px solid var(--border); }

/* ── Empty State ── */
.empty-state {
  padding: 52px 24px; text-align: center;
  background: var(--surface); border-radius: var(--radius-lg);
  border: 2px dashed var(--border);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
.empty-title { font-size: 17px; font-weight: 800; color: var(--text2); margin-bottom: 6px; }
.empty-sub { font-size: 13px; color: var(--muted); }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 2px solid var(--border); }
th {
  padding: 12px 16px; text-align: right;
  font-size: 11px; font-weight: 800; color: var(--muted);
  letter-spacing: .6px; text-transform: uppercase;
  background: var(--surface2);
}
td {
  padding: 13px 16px; text-align: right;
  font-size: 14px; color: var(--text2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }
tbody tr:hover td:first-child { color: var(--text); font-weight: 600; }

.show-mobile  { display: none; }
.show-desktop { display: none; }
@media (min-width: 768px)  { .show-desktop { display: block; } }
@media (max-width: 767px)  { .show-mobile  { display: block; } }

/* ── Bottom Tab Bar ── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(15,23,42,.08);
  display: flex; justify-content: space-around; align-items: stretch;
  z-index: 100;
}
.tab-item {
  flex: 1; border: none; background: transparent;
  padding: 8px 4px 4px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  color: var(--muted2);
  cursor: pointer; transition: color .15s;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.tab-item svg { width: 22px; height: 22px; fill: currentColor; }
.tab-item span { font-size: 10px; font-weight: 800; letter-spacing: .3px; }
.tab-item.active { color: var(--primary); }
.tab-item.active .tab-dot {
  display: block;
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 30px; height: 3px;
  background: var(--primary);
  border-radius: 0 0 3px 3px;
}
.tab-dot { display: none; }
.tab-item:active { opacity: .7; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--text);
  color: #FFFFFF;
  padding: 11px 22px; border-radius: 99px;
  font-size: 13px; font-weight: 700;
  box-shadow: var(--shadow-lg);
  opacity: 0; transition: opacity .2s, transform .2s;
  z-index: 99999; white-space: nowrap; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Charts ── */
.chart-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
@media (max-width: 600px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card {
  background: var(--surface);
  border-radius: var(--radius-lg); padding: 20px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.chart-card h4 {
  font-size: 15px; font-weight: 800; color: var(--text);
  margin: 0 0 16px; display: flex; align-items: center; gap: 7px;
}

/* ── Settings ── */
.settings-group {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow); overflow: hidden;
}
.settings-group-label {
  font-size: 11px; font-weight: 800; color: var(--muted);
  letter-spacing: .8px; text-transform: uppercase;
  padding: 16px 20px 8px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--border); gap: 12px;
  transition: background .12s;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:hover { background: var(--surface2); }
.settings-row-label {
  display: flex; align-items: center; gap: 12px;
  font-size: 15px; color: var(--text2); font-weight: 600;
}
.settings-icon {
  width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}

/* Toggle */
.toggle { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--border2); border-radius: 99px;
  transition: background .2s; cursor: pointer;
}
.toggle-track::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  transition: transform .22s cubic-bezier(.34,1.56,.64,1);
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track::after { transform: translateX(20px); }

/* Swatches */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: transform .15s; box-shadow: var(--shadow-sm);
}
.swatch.active { border-color: var(--text); transform: scale(1.2); }
.swatch:hover { transform: scale(1.1); }

/* Note */
.note { font-size: 12px; color: var(--muted); padding: 8px 20px 14px; line-height: 1.6; }

/* Statement highlight */
.stmt-row.invoice td:first-child { border-right: 3px solid var(--red); }
.stmt-row.receipt td:first-child { border-right: 3px solid var(--green); }

/* ── Responsive ── */
@media (max-width: 480px) {
  main { padding: 14px 12px 90px; }
  .form-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 22px; }
  .topbar { padding: 0 14px; }
}
html { scroll-behavior: smooth; }

/* ── Dark Mode overrides (body.dark) ── */
body.dark {
  --bg:         #0F1117;
  --bg2:        #161B22;
  --surface:    #1C2128;
  --surface2:   #22272E;
  --border:     #30363D;
  --border2:    #484F58;
  --text:       #E6EDF3;
  --text2:      #8B949E;
  --muted:      #6E7681;
  --muted2:     #484F58;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
  --shadow:     0 4px 12px rgba(0,0,0,.4);
  --shadow-lg:  0 12px 32px rgba(0,0,0,.5);
  --shadow-xl:  0 24px 48px rgba(0,0,0,.6);
}
body.dark .topbar { background: var(--surface); }
body.dark .tabbar { background: var(--surface); }
body.dark .login-gate {
  background: linear-gradient(145deg, #050810 0%, #0A1A10 40%, #070D1A 100%);
}
body.dark input, body.dark select {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}
body.dark input:focus, body.dark select:focus {
  background: var(--surface);
}
body.dark .form-actions { background: var(--surface2); }
body.dark tbody tr:hover td { background: var(--surface2); }
body.dark .empty-state { background: var(--surface); border-color: var(--border); }
body.dark .settings-group-label { background: var(--surface2); }
