/* ============================================================
   Chinguetti Dental Clinic Manager — styles
   Arabic-first, RTL, mobile-friendly
   ============================================================ */
:root {
  --teal: #2f9fdd;
  --teal-dark: #1b7ab8;
  --teal-light: #e3f2fc;
  --gold: #c9a227;
  --ink: #1f2a33;
  --muted: #6b7a86;
  --bg: #edf4fa;
  --card: #ffffff;
  --danger: #c0392b;
  --danger-light: #fdecea;
  --ok: #1e8e3e;
  --ok-light: #e6f4ea;
  --warn: #b7791f;
  --warn-light: #fef6e0;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 40, 40, 0.08);
}

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

body {
  margin: 0;
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: 92px; /* space for bottom nav */
}

small.fr, .fr { font-size: 0.72em; color: var(--muted); font-weight: 400; display: block; }

/* ---------- Loading / login ---------- */
.loading-screen {
  min-height: 80vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 24px;
}
.login-wrap {
  min-height: 100vh; margin-bottom: -92px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 24px;
  background:
    linear-gradient(rgba(237,244,250,.88), rgba(237,244,250,.95)),
    url('bg.jpg') center / cover no-repeat;
}
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid var(--teal-light); border-top-color: var(--teal);
  animation: spin 0.9s linear infinite; margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.brand { margin-bottom: 28px; }
.brand h1 { margin: 0; font-size: 1.9rem; color: var(--teal-dark); font-weight: 800; }
.brand p { margin: 4px 0 0; color: var(--muted); }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin: 12px 16px;
}
.card h2 { margin: 0 0 4px; font-size: 1.25rem; }
.card h3 { margin: 16px 0 8px; font-size: 1.05rem; color: var(--teal-dark); }

form.stack { display: flex; flex-direction: column; gap: 12px; }

label { font-weight: 700; font-size: 0.95rem; }
label .fr { font-weight: 400; }

input, select, textarea {
  width: 100%; padding: 12px 14px; font-size: 1rem;
  font-family: inherit; border: 1.5px solid #d5dee3;
  border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-light);
}
textarea { min-height: 70px; resize: vertical; }

.btn {
  display: inline-block; border: none; cursor: pointer;
  background: var(--teal); color: #fff;
  font-family: inherit; font-weight: 700; font-size: 1.05rem;
  padding: 13px 22px; border-radius: 12px; text-align: center;
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: #e9eff1; color: var(--ink); }
.btn.danger { background: var(--danger); }
.btn.small { width: auto; padding: 8px 14px; font-size: 0.9rem; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.error {
  background: var(--danger-light); color: var(--danger);
  border-radius: 10px; padding: 12px; font-weight: 600; font-size: 0.95rem;
}
.hint { color: var(--muted); font-size: 0.85rem; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--teal-dark); color: #fff;
  padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 800; }
.topbar .who { font-size: 0.8rem; opacity: 0.85; }

/* ---------- Dashboard stat cards ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 16px; }
.stat {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 14px; text-align: center;
}
.stat .num { font-size: 1.5rem; font-weight: 800; color: var(--teal-dark); }
.stat .num.money { color: var(--warn); }
.stat .lbl { font-size: 0.95rem; font-weight: 700; margin-top: 4px; }
.stat.full { grid-column: 1 / -1; }

/* ---------- Lists ---------- */
.list-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin: 8px 16px;
  text-decoration: none; color: inherit;
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; font-size: 1.05rem; }
.list-item .sub { color: var(--muted); font-size: 0.85rem; }
.list-item .amount { font-weight: 800; white-space: nowrap; }
.rcpt-thumb {
  width: 64px; height: 64px; object-fit: cover; flex-shrink: 0;
  border-radius: 10px; border: 1px solid var(--teal-light);
}
.amount.pos { color: var(--warn); }
.amount.neg { color: var(--ok); }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 700;
  padding: 3px 10px; border-radius: 20px; white-space: nowrap;
}
.badge.scheduled { background: var(--teal-light); color: var(--teal-dark); }
.badge.confirmed { background: #e3f0fd; color: #1565c0; }
.badge.completed { background: var(--ok-light); color: var(--ok); }
.badge.cancelled { background: #f0f0f0; color: var(--muted); }
.badge.no_show   { background: var(--danger-light); color: var(--danger); }

/* Patient number pill — sequential numbering (1, 2, 3, ...) */
.pnum {
  display: inline-block; font-size: 0.8rem; font-weight: 800;
  padding: 3px 10px; border-radius: 20px; white-space: nowrap;
  background: #e3f0fd; color: #1565c0; margin-inline-end: 8px;
  font-variant-numeric: tabular-nums;
}
.badge.ok   { background: var(--ok-light); color: var(--ok); }
.badge.warn { background: var(--warn-light); color: var(--warn); }

.empty {
  text-align: center; color: var(--muted); padding: 36px 20px;
  margin: 12px 16px;
}
.empty .big { font-size: 2.2rem; }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 30;
  background: #fff; border-top: 1px solid #e2e8ea;
  display: flex; padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(15,40,40,0.08);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.bottomnav::-webkit-scrollbar { display: none; }
.bottomnav a {
  flex: 0 0 auto; min-width: 74px; text-align: center; text-decoration: none; color: var(--muted);
  font-size: 0.72rem; font-weight: 700; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.bottomnav a .ico { font-size: 1.35rem; }
.bottomnav a.active { color: var(--teal-dark); }

/* ---------- Detail sections ---------- */
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed #e6ecee; font-size: 0.98rem; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); font-weight: 600; }
.kv .v { font-weight: 700; text-align: left; }

.balance-box {
  border-radius: var(--radius); padding: 16px; margin: 12px 16px;
  text-align: center; font-weight: 800; font-size: 1.2rem;
}
.balance-box.owes { background: var(--warn-light); color: var(--warn); }
.balance-box.clear { background: var(--ok-light); color: var(--ok); }

.fab {
  position: fixed; bottom: calc(var(--navh, 104px) + 14px + env(safe-area-inset-bottom)); left: 16px; z-index: 25;
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--gold); color: #fff; font-size: 1.8rem; font-weight: 800;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25); cursor: pointer;
}

main { padding-bottom: calc(var(--navh, 104px) + 16px + env(safe-area-inset-bottom)); }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(10,25,25,0.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: slideup 0.25s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0.6; } }
.modal h2 { margin-top: 0; }

.status-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.status-row .btn.small { flex: 1; min-width: 100px; }

.searchbar { margin: 12px 16px 4px; }

@media (min-width: 700px) {
  .card, .stats, .searchbar { max-width: 640px; margin-right: auto; margin-left: auto; }
  .list-item, .empty, .balance-box { max-width: 640px; margin-right: auto; margin-left: auto; }
  .modal-back { align-items: center; }
  .modal { border-radius: 20px; }
}

/* ---------- Polish additions ---------- */
.fr.inline { display: inline; }

.linklike {
  background: none; border: none; cursor: pointer;
  color: var(--teal-dark); font-family: inherit;
  font-weight: 700; font-size: 0.95rem; padding: 10px 4px;
  text-align: center; width: 100%;
}
.linklike .fr { display: block; }

.rowbtns { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  background: #eef3f4; border: none; border-radius: 8px;
  padding: 7px 10px; cursor: pointer; font-size: 0.95rem; line-height: 1;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.danger { background: var(--danger-light); }
a.icon-btn { text-decoration: none; display: inline-block; }

.btn:disabled { opacity: 0.6; cursor: default; }

a.stat { display: block; }
