:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --primary: #0f766e;
  --primary-dark: #0b5852;
  --text: #1f2933;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --warn: #d97706;
  --info: #2563eb;
  --success: #059669;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .06);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", sans-serif;
  background: linear-gradient(180deg, #eef2f1 0%, var(--bg) 240px);
  color: var(--text);
  direction: rtl;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  background: linear-gradient(135deg, #0f766e 0%, #115e59 60%, #134e4a 100%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(15, 118, 110, .25);
}
.topbar h1 { font-size: 1.1rem; margin: 0; }
.topbar .sub { font-size: .8rem; opacity: .85; }

.container { max-width: 1280px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 16px;
  margin-bottom: 11px;
  border: 1px solid var(--border);
  transition: box-shadow .2s, transform .2s;
}
.card:hover { box-shadow: 0 6px 20px rgba(0, 0, 0, .08); }
.card h2 { margin: 0 0 8px; font-size: 1.05rem; }
.card h3 { margin: 0 0 6px; font-size: .95rem; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(135deg, #14857a, var(--primary-dark));
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 15px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(15, 118, 110, .25);
  transition: filter .15s, transform .1s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.secondary { background: #eef2f1; color: var(--primary-dark); }
.btn.secondary:hover { background: #e0e7e5; }
.btn.whatsapp { background: #25d366; }
.btn.whatsapp:hover { background: #1da851; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 11px; font-size: .85rem; border-radius: 8px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

label { display: block; font-size: .88rem; margin: 8px 0 3px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.banner {
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  font-weight: 600;
  border: 1px solid transparent;
}
.banner.due_today { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.banner.overdue { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.banner.upcoming { background: #eff6ff; color: var(--info); border-color: #bfdbfe; }
.banner.paid_off { background: #ecfdf5; color: var(--success); border-color: #a7f3d0; }
.banner .due-date { font-weight: 400; font-size: .85rem; display: block; margin-top: 2px; }

.big-number { font-size: 2.1rem; font-weight: 800; color: var(--primary-dark); }
.big-number .unit { font-size: 1rem; font-weight: 600; color: var(--muted); }

.progress { background: #e5e7eb; border-radius: 999px; height: 14px; overflow: hidden; margin: 10px 0; }
.progress > span { display: block; height: 100%; background: var(--success); border-radius: 999px; transition: width .4s; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  line-height: 1.35;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.stat .k { font-size: .82rem; color: var(--muted); }
.stat .v { font-size: 1rem; font-weight: 700; text-align: left; }

.offer { border: 1px solid #99f6e4; border-radius: var(--radius); padding: 16px; margin-bottom: 12px; background: linear-gradient(135deg, #f0fdfa, #ffffff); position: relative; overflow: hidden; }
.offer::before { content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 5px; background: linear-gradient(180deg, var(--primary), #115e59); }
.offer .title { font-size: 1.2rem; font-weight: 800; color: var(--primary-dark); }
.offer ul { margin: 8px 0 0; padding-inline-start: 18px; }
.offer li { margin: 2px 0; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .82rem; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.badge.active { background: #eff6ff; color: var(--info); }
.badge.paid_off { background: #ecfdf5; color: var(--success); }
.badge.overdue { background: #fef2f2; color: var(--danger); }
.badge.due_today { background: #fff7ed; color: var(--warn); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px 0; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 50px; z-index: 9; }
.tab { padding: 9px 13px; border: none; background: transparent; color: var(--muted); font-family: inherit; font-size: .92rem; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 700; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error-msg { color: var(--danger); font-size: .9rem; margin-top: 8px; min-height: 1.2em; }
.ok-msg { color: var(--success); font-size: .9rem; margin-top: 8px; }
.copy-box { display: flex; gap: 8px; align-items: center; background: #f9fafb; border: 1px dashed var(--primary); border-radius: 10px; padding: 10px 12px; font-weight: 700; }
.copy-box .val { flex: 1; word-break: break-all; }

.receipt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.receipt-grid figure { margin: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.receipt-grid img { width: 100%; height: 120px; object-fit: cover; display: block; }
.receipt-grid figcaption { padding: 6px 8px; font-size: .78rem; }
.receipt-folder { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: #fbfdfd; overflow: hidden; }
.receipt-folder > summary { cursor: pointer; padding: 12px 14px; font-weight: 600; list-style: none; display: flex; align-items: center; justify-content: space-between; user-select: none; }
.receipt-folder > summary::-webkit-details-marker { display: none; }
.receipt-folder[open] > summary { border-bottom: 1px solid var(--border); background: #f1f7f6; }
.receipt-folder .folder-name { color: var(--brand, #0f766e); }
.receipt-folder > .receipt-grid { padding: 12px 14px; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-start; justify-content: center; padding: 20px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: var(--radius); padding: 18px; max-width: 560px; width: 100%; margin-top: 20px; }
.hidden { display: none !important; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { padding: 6px 13px; border: 1px solid var(--border); border-radius: 999px; background: #fff; color: var(--muted); font-family: inherit; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }

.print-only { display: none; }

@media print {
  .topbar, .tabs, .no-print, .modal-bg, #logout { display: none !important; }
  .print-only { display: block !important; }
  body { background: #fff; }
  .container { max-width: none; padding: 0; }
  .card { box-shadow: none; border: none; margin-bottom: 8px; page-break-inside: avoid; }
  th, td { font-size: 11px; }

  /* طباعة كشف الحساب فقط: أظهِر النافذة وأخفِ ما عداها */
  body.print-statement .topbar,
  body.print-statement .tabs,
  body.print-statement .container { display: none !important; }
  body.print-statement .modal-bg {
    display: block !important;
    position: static;
    background: #fff;
    padding: 0;
    overflow: visible;
  }
  body.print-statement .modal {
    box-shadow: none;
    max-width: none;
    width: auto;
    margin: 0;
  }
}

@media (max-width: 480px) {
  .big-number { font-size: 1.7rem; }
  .grid { grid-template-columns: 1fr; }
}
