/* ==========================================================================
   اتحاد شاغلين برج سكني — التنسيقات الأساسية
   ========================================================================== */

:root {
  --bg: #f2f5f3;
  --card: #ffffff;
  --ink: #10201b;
  --muted: #677d76;
  --line: #e2e9e6;
  --brand: #0c5c46;
  --brand-2: #12876a;
  --brand-soft: #e6f2ee;
  --gold: #b3811f;
  --gold-soft: #fbf3e2;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fdf2e2;
  --ok: #1c7a4a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 27, .06), 0 8px 24px rgba(16, 32, 27, .06);
  --shadow-lg: 0 12px 48px rgba(16, 32, 27, .18);
  --nav-h: 68px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Cairo", "Segoe UI", Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.35; }
p { margin: 0; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }
a { color: var(--brand); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 24px 18px;
  background:
    radial-gradient(1200px 600px at 80% -10%, #16795e 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #0a4a39 0%, transparent 55%),
    linear-gradient(160deg, #0c5c46 0%, #083b2e 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 24px;
  padding: 30px 24px 26px;
  box-shadow: var(--shadow-lg);
  animation: rise .45s cubic-bezier(.2, .8, .3, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.login-logo {
  width: 68px; height: 68px;
  border-radius: 20px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--brand-2), var(--brand));
  color: #fff;
  margin: 0 auto 16px;
  box-shadow: 0 10px 24px rgba(12, 92, 70, .3);
}
.login-logo svg { width: 36px; height: 36px; }

.login-title { text-align: center; font-size: 21px; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfc;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand-2);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(18, 135, 106, .12);
}
.field textarea { resize: vertical; min-height: 84px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 14.5px;
  transition: transform .12s, background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.975); }
.btn-primary { background: var(--brand); color: #fff; width: 100%; }
.btn-primary:hover { background: #0a4c3a; }
.btn-ghost { background: var(--brand-soft); color: var(--brand); }
.btn-ghost:hover { background: #d9ece5; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 8px 13px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 14px;
  font-weight: 600;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: #e7f6ee; color: var(--ok); }

/* ---------- app shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--brand-2), var(--brand));
  color: #fff;
}
.topbar-mark svg { width: 21px; height: 21px; }
.topbar-name {
  font-weight: 700; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-role { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.topbar-spacer { flex: 1; }
.topbar-user {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 10px 5px 5px;
  border-radius: 999px;
  background: var(--brand-soft);
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
}
.topbar-user-name { font-size: 13px; font-weight: 700; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout { flex: 1; display: flex; min-height: 0; }

.sidenav { display: none; }

.main {
  flex: 1;
  padding: 18px 16px calc(var(--nav-h) + 26px);
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- bottom nav ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
  height: var(--nav-h);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: center;
}
.navbtn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 700; color: var(--muted);
  padding: 6px 2px; border-radius: 12px;
  transition: color .15s, background .15s;
}
.navbtn svg { width: 21px; height: 21px; }
.navbtn.active { color: var(--brand); background: var(--brand-soft); }

/* ---------- page heading ---------- */
.page-head {
  display: flex; align-items: flex-start; gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 20px; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head-actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.period-picker {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 4px 6px;
}
.period-picker select {
  border: none; background: transparent; font-weight: 700;
  font-size: 13.5px; color: var(--ink); outline: none; padding: 4px 2px;
}
.period-picker button {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; color: var(--brand);
  background: var(--brand-soft);
}
.period-picker button:disabled { opacity: .35; }

/* ---------- cards / stats ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 14px; }
.card-head {
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line);
}
.card-head h3 { font-size: 15px; }
.card-head .sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.card-head-actions { margin-inline-start: auto; }
.card-body { padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.stat-value { font-size: 19px; font-weight: 800; letter-spacing: -.3px; }
.stat-value small { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.stat-icon {
  position: absolute; inset-inline-end: 10px; top: 10px;
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  opacity: .9;
}
.stat-icon svg { width: 16px; height: 16px; }
.stat.income .stat-icon { background: #e7f6ee; color: var(--ok); }
.stat.expense .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat.cash .stat-icon { background: var(--brand-soft); color: var(--brand); }
.stat.debt .stat-icon { background: var(--gold-soft); color: var(--gold); }
.stat.income .stat-value { color: var(--ok); }
.stat.expense .stat-value { color: var(--danger); }
.stat.debt .stat-value { color: var(--gold); }

.hero-stat {
  background: linear-gradient(150deg, #0d6550 0%, #08402f 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 10px 30px rgba(12, 92, 70, .28);
  position: relative;
  overflow: hidden;
}
.hero-stat::after {
  content: "";
  position: absolute; inset-inline-end: -40px; top: -50px;
  width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255, 255, 255, .07);
}
.hero-stat-label { font-size: 12.5px; opacity: .82; font-weight: 700; }
.hero-stat-value { font-size: 30px; font-weight: 800; letter-spacing: -1px; margin-top: 2px; }
.hero-stat-value small { font-size: 14px; opacity: .8; }
.hero-stat-foot { display: flex; gap: 16px; margin-top: 14px; font-size: 12.5px; flex-wrap: wrap; }
.hero-stat-foot span { opacity: .88; }
.hero-stat-foot b { display: block; font-size: 15px; }

/* ---------- list rows ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 700; font-size: 14px; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.row-amount { font-weight: 800; font-size: 14.5px; white-space: nowrap; }
.row-amount.neg { color: var(--danger); }
.row-amount.pos { color: var(--ok); }
.row-actions { display: flex; gap: 5px; flex-shrink: 0; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  color: var(--muted); background: #f4f7f6;
  transition: background .15s, color .15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.avatar-sq {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 11px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
  font-weight: 800; font-size: 14px;
}

.empty {
  text-align: center; padding: 34px 20px; color: var(--muted);
}
.empty svg { width: 40px; height: 40px; opacity: .35; margin-bottom: 8px; }
.empty-title { font-weight: 700; font-size: 14px; color: var(--ink); margin-bottom: 3px; }
.empty p { font-size: 13px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700;
}
.badge-ok { background: #e7f6ee; color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: #eef2f1; color: var(--muted); }
.badge-gold { background: var(--gold-soft); color: var(--gold); }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 6px; padding: 4px;
  background: #e9efec; border-radius: 12px; margin-bottom: 14px;
  overflow-x: auto;
}
.tabs button {
  flex: 1; padding: 9px 12px; border-radius: 9px;
  font-size: 13.5px; font-weight: 700; color: var(--muted);
  white-space: nowrap; transition: background .15s, color .15s;
}
.tabs button.active { background: #fff; color: var(--brand); box-shadow: var(--shadow); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: start; padding: 10px 12px;
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: #f7faf9; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafcfb; }

/* ---------- announcement cards ---------- */
.ann {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.ann:last-child { border-bottom: none; }
.ann.pinned { background: linear-gradient(90deg, var(--gold-soft), transparent 70%); }
.ann-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; flex-wrap: wrap; }
.ann-title { font-weight: 700; font-size: 14.5px; }
.ann-body { font-size: 13.5px; color: #33463f; white-space: pre-wrap; }
.ann-foot { font-size: 11.5px; color: var(--muted); margin-top: 8px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 22, 18, .5);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--card);
  width: 100%; max-width: 520px;
  border-radius: 22px 22px 0 0;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  animation: slideUp .26s cubic-bezier(.2, .8, .3, 1);
}
@keyframes slideUp { from { transform: translateY(40px); } to { transform: none; } }

.modal-head {
  padding: 16px 18px 12px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.modal-head h3 { font-size: 16px; }
.modal-close { margin-inline-start: auto; width: 32px; height: 32px; border-radius: 50%; background: #f1f5f3; display: grid; place-items: center; color: var(--muted); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex; gap: 10px; flex-shrink: 0;
}
.modal-foot .btn { flex: 1; }
.modal-foot .btn-primary { width: auto; }

/* ---------- toast ---------- */
.toasts {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px;
  width: calc(100% - 32px); max-width: 420px; pointer-events: none;
}
.toast {
  padding: 12px 16px; border-radius: 12px;
  font-size: 13.5px; font-weight: 700;
  box-shadow: var(--shadow-lg);
  animation: toastIn .22s ease;
  background: #17322a; color: #fff;
}
.toast.error { background: #7d1c16; }
.toast.ok { background: #14532d; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; } }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen {
  min-height: 60dvh; display: grid; place-items: center;
}
.loading-screen .spinner { border-color: rgba(12,92,70,.2); border-top-color: var(--brand); width: 28px; height: 28px; }

.chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; }
.chart-bars { display: flex; gap: 3px; align-items: flex-end; width: 100%; flex: 1; }
.chart-bar { flex: 1; border-radius: 4px 4px 0 0; min-height: 2px; transition: height .4s ease; }
.chart-bar.inc { background: var(--brand-2); }
.chart-bar.exp { background: #e08c86; }
.chart-label { font-size: 10.5px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); font-weight: 700; margin-top: 10px; }
.chart-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-inline-end: 4px; }

.divider { height: 1px; background: var(--line); margin: 14px 0; }

.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
.kv span { color: var(--muted); }
.kv b { font-weight: 700; }

.sheet-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 4px; }
.sheet-item {
  display: flex; align-items: center; gap: 9px;
  padding: 12px; border-radius: 12px; background: #f6f9f8;
  font-weight: 700; font-size: 13.5px; text-align: start;
}
.sheet-item svg { width: 18px; height: 18px; color: var(--brand); flex-shrink: 0; }
.sheet-item.active { background: var(--brand-soft); color: var(--brand); }

/* ---------- responsive ---------- */
@media (min-width: 900px) {
  .bottomnav { display: none; }
  .main { padding: 24px 28px 40px; }

  .layout { max-width: 1240px; margin: 0 auto; width: 100%; }

  .sidenav {
    display: flex; flex-direction: column; gap: 3px;
    width: 224px; flex-shrink: 0;
    padding: 18px 12px;
    border-inline-end: 1px solid var(--line);
    position: sticky; top: 59px;
    align-self: flex-start;
    height: calc(100dvh - 59px);
    overflow-y: auto;
  }
  .sidenav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 11px;
    font-weight: 700; font-size: 13.5px; color: var(--muted);
    transition: background .15s, color .15s;
    text-align: start;
  }
  .sidenav-item svg { width: 18px; height: 18px; }
  .sidenav-item:hover { background: #eef4f2; color: var(--ink); }
  .sidenav-item.active { background: var(--brand-soft); color: var(--brand); }

  .stats { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .stat-value { font-size: 21px; }
  .hero-stat-value { font-size: 36px; }

  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 20px; max-height: 88dvh; }
  .page-title { font-size: 23px; }
}

@media (min-width: 1200px) {
  .main { padding: 26px 34px 48px; }
}
