/* PettyClick — موبايل أولاً، عربى RTL */
@font-face { font-family: 'Cairo'; src: url('fonts/cairo-arabic.woff2') format('woff2'); font-weight: 200 1000; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'Cairo'; src: url('fonts/cairo-latin.woff2') format('woff2'); font-weight: 200 1000; font-display: swap; }

:root {
  --bg: #f8f5f2; --card: #fff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #d96e26; --accent-2: #f29a55; --custody: #047857; --expense: #b91c1c; --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { font-family: 'Cairo', Tahoma, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5;
  padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
a { color: inherit; text-decoration: none; }
b, .amt, .nums b, .summary b, .bal b, .run, .key { font-variant-numeric: tabular-nums; }
/* الأرقام السالبة: علامة الناقص على الشمال صح */
.summary b, .period b, .bal b, .nums b, .amt, .run b { direction: ltr; unicode-bidi: isolate; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; background: var(--accent); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.top h1 { flex: 1; font-size: 19px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .back, .top .gear { font-size: 24px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; }
.top .back:active, .top .gear:active { background: rgba(255,255,255,.18); }

main { max-width: 640px; margin: 0 auto; padding: 14px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(15,23,42,.08); padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); } .small { font-size: 13.5px; } .center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.tag { font-size: 12px; background: var(--line); color: var(--muted); border-radius: 20px; padding: 1px 8px; font-weight: 600; vertical-align: middle; }
.tag.on { background: #ffedd5; color: var(--accent); }

.flash { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14.5px; }
.flash.ok { background: #dcfce7; color: #166534; } .flash.err { background: #fee2e2; color: #991b1b; }

/* الملخص */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.summary div, .period div { display: flex; flex-direction: column; }
.summary span, .period span { font-size: 13px; color: var(--muted); }
.summary b { font-size: 17px; }
.summary .left { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 8px; flex-direction: row; justify-content: space-between; align-items: center; }
.summary .left span { font-size: 16px; color: var(--text); font-weight: 700; }
.summary .left b { font-size: 26px; color: var(--custody); }
.neg b, .bal.neg b, .left.neg b { color: var(--expense) !important; }
.period { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: #fff7ed; }

/* العيادات */
.clinics, .entries { list-style: none; margin: 0; padding: 0; }
.clinic { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name bal" "nums bal"; gap: 2px 12px; align-items: center; }
.clinic:active { transform: scale(.99); }
.clinic.archived { opacity: .6; }
.clinic .name { grid-area: name; font-weight: 700; font-size: 17px; }
.clinic .nums { grid-area: nums; display: flex; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.clinic .nums b { color: var(--text); font-weight: 600; }
.clinic .bal { grid-area: bal; text-align: left; display: flex; flex-direction: column; align-items: flex-end; }
.clinic .bal small { color: var(--muted); font-size: 12px; }
.clinic .bal b { font-size: 21px; color: var(--custody); }

/* الحركات */
.entry { padding: 10px 12px; border-inline-start: 4px solid var(--custody); }
.entry.expense { border-inline-start-color: var(--expense); }
.entry a { display: block; }
.entry .l1, .entry .l2 { display: flex; align-items: center; gap: 8px; }
.entry .kind { font-size: 12px; font-weight: 700; border-radius: 20px; padding: 0 8px; background: #d1fae5; color: var(--custody); }
.entry.expense .kind { background: #fee2e2; color: var(--expense); }
.entry .date { color: var(--muted); font-size: 13.5px; }
.entry .amt { margin-inline-start: auto; font-size: 17px; color: var(--custody); direction: ltr; }
.entry.expense .amt { color: var(--expense); }
.entry .note { flex: 1; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .run { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* فورم */
.form { display: flex; flex-direction: column; gap: 12px; }
.form h3 { margin: 0; font-size: 17px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); font-weight: 600; }
input, select, button { font: inherit; }
input:not([type=radio]):not([type=checkbox]), select { width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 16px;
  color: var(--text); background: #fff; min-height: 46px; }
input:focus, select:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(242,154,85,.18); }
input.big { font-size: 24px; font-weight: 700; text-align: center; direction: ltr; }
input[type=date] { direction: ltr; text-align: right; }
.form.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.form.row input, .form.row select { min-width: 0; padding-inline: 8px; }
.form.row label:nth-of-type(3), .form.row .quick, .form.row .actions { grid-column: 1 / -1; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { border: 1px solid var(--line); background: #f8fafc; border-radius: 20px; padding: 4px 12px; font-size: 13px; color: var(--text); }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }
.check { flex-direction: row !important; align-items: center; gap: 6px !important; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; }
.seg label { display: block; }
.seg input { display: none; }
.seg span { display: block; text-align: center; padding: 9px; border-radius: 9px; font-weight: 700; color: var(--muted); font-size: 15px; }
.seg input[value=custody]:checked + span { background: var(--custody); color: #fff; }
.seg input[value=expense]:checked + span { background: var(--expense); color: #fff; }

.receipt-box { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.receipt-box .file { width: 100%; }
.thumb { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--line); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 11px 18px; min-height: 46px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; cursor: pointer; }
.btn:active { filter: brightness(.92); }
.btn.ghost { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }
.btn.danger { background: #fff; color: var(--expense); border: 1.5px solid var(--expense); }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 14px; }
.btn.custody { background: var(--custody); } .btn.expense { background: var(--expense); }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar .btn { flex: 1; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin: 8px 0; }

.fab { position: fixed; inset-inline: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: rgba(248,245,242,.94); backdrop-filter: blur(6px);
  border-top: 1px solid var(--line); }
.fab .btn { font-size: 17px; min-height: 52px; }
@media (min-width: 680px) { .fab { max-width: 640px; margin: 0 auto; border-radius: 16px 16px 0 0; } }

details > summary { cursor: pointer; font-weight: 700; color: var(--accent); list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 12px; }

.login { text-align: center; padding-top: 4vh; }
.login .logo { border-radius: 22px; box-shadow: 0 4px 14px rgba(217,110,38,.3); }
.login h2 { margin: 10px 0 0; }
.login .form { text-align: right; margin-top: 16px; }

.qr { display: flex; justify-content: center; padding: 10px; }
.qr img, .qr canvas { background: #fff; padding: 8px; border-radius: 10px; }
.key { text-align: center; font-family: monospace; font-size: 15px; letter-spacing: 1px; background: var(--bg); padding: 8px; border-radius: 8px; word-break: break-all; }

.offline { text-align: center; padding: 18vh 20px; }

/* أيقونات خطوط (SVG) */
.ic { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.top .ic { width: 24px; height: 24px; }
.btn .ic { width: 20px; height: 20px; }
.btn.small .ic { width: 17px; height: 17px; }
.fab .ic { width: 22px; height: 22px; stroke-width: 2.4; }
.clip .ic { width: 15px; height: 15px; color: var(--muted); vertical-align: -0.15em; }
summary .ic { margin-inline-end: 2px; }
.form h3 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.form h3 .ic { color: var(--accent); }
.form label.btn { flex-direction: row; color: var(--accent); font-size: 15px; }
