/* دفاتري: واجهة محاسبية هادئة. أسطح بيضاء على رمادي فاتح، لون واحد للتمييز (أزرق الحبر)،
   والأرقام بخط مستقيم الأعمدة. سمة فاتحة واحدة مقصودة لتبقى الألوان ثابتة على كل الأجهزة. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #1d4ed8;
  --accent-soft: #eef3ff;
  --plus: #047857;
  --plus-soft: #ecfdf5;
  --minus: #b91c1c;
  --minus-soft: #fef2f2;
  --radius: 12px;
  --font: "Readex Pro", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.big, .bal, td.num, .cols span:last-child { font-variant-numeric: tabular-nums; }

/* ---------------- الرأس */
.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 600; }
.mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.mark::before { content: ""; width: 12px; height: 2px; background: #fff; box-shadow: 0 -5px 0 #fff, 0 5px 0 #fff; border-radius: 2px; }
.who { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--muted); min-width: 0; }
#who-name { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font-size: 13px; }
.linkish:hover { color: var(--accent); }

/* ---------------- اختيار الدفتر */
.tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 12px 16px; background: var(--bg);
  position: sticky; top: 0; z-index: 5;
  max-width: 760px; margin: 0 auto;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: 7px 14px; border-radius: 999px; font-size: 14px;
}
.tab[aria-selected="true"] { background: var(--text); border-color: var(--text); color: #fff; }

/* ---------------- المحتوى */
main { max-width: 760px; margin: 0 auto; padding: 4px 16px 40px; display: grid; gap: 14px; }
.stack { display: grid; gap: 14px; }
.state { color: var(--muted); text-align: center; padding: 48px 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }

/* الملخص */
.summary .big-label { color: var(--muted); font-size: 13px; }
.summary .big { font-size: 30px; font-weight: 600; line-height: 1.3; }
.summary .big small { font-size: 14px; font-weight: 400; color: var(--muted); margin-inline-start: 4px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-top: 16px; }
.cols div { background: var(--bg); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; }
.cols span:first-child { color: var(--muted); font-size: 12px; }
.cols span:last-child { font-weight: 600; font-size: 15px; }

/* النماذج */
form.entry { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
form.entry .full { grid-column: 1 / -1; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select {
  width: 100%; height: 44px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  font-size: 16px; color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[inputmode="decimal"], input.ltr, input[type="date"] { direction: ltr; text-align: right; }

.btn {
  height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font-weight: 500; cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.del { height: 26px; min-width: 26px; padding: 0 6px; font-size: 14px; line-height: 1; }
.btn.danger { background: var(--minus); color: #fff; border-color: var(--minus); }
.form-error { color: var(--minus); font-size: 13px; margin: 0; }
.form-error:empty { display: none; }

/* الحسابات */
.card.accounts { padding: 0; overflow: hidden; }
.accounts h2 { padding: 18px 18px 10px; margin: 0; }
.acct { border-top: 1px solid var(--border); }
.acct summary {
  list-style: none; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto 16px; align-items: center; gap: 0 12px;
  padding: 12px 18px;
}
.acct summary::-webkit-details-marker { display: none; }
.acct summary::after {
  content: ""; width: 7px; height: 7px; justify-self: end; grid-column: 3; grid-row: 1;
  border-left: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s;
}
.acct[open] summary::after { transform: rotate(-45deg); }
.acct summary:hover { background: #fafbfc; }
.acct .name { font-weight: 500; }
.acct .role { color: var(--muted); font-size: 11px; font-weight: 400; background: var(--bg); padding: 1px 8px; border-radius: 999px; margin-inline-start: 6px; }
.acct .bal { font-weight: 600; grid-column: 2; grid-row: 1; }
.acct .sub { grid-column: 1 / 3; color: var(--muted); font-size: 12px; }
.zero { color: var(--muted); }
.neg { color: var(--minus); }

.stmt { padding: 0 12px 14px; display: grid; gap: 10px; }
.stmt-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: right; padding: 8px 5px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-weight: 500; font-size: 12px; background: var(--bg); }
td.num { white-space: nowrap; }
td.date { white-space: nowrap; color: var(--muted); }
.pill { white-space: nowrap; display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: var(--bg); }
.pill.plus { background: var(--plus-soft); color: var(--plus); }
.pill.minus { background: var(--minus-soft); color: var(--minus); }
.note { color: var(--muted); font-size: 12px; margin: 0; }
.link-row { display: flex; gap: 8px; align-items: end; }
.link-row label { flex: 1; }

/* أفراد العائلة */
.users-list { display: grid; }
.user-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--border); }
.user-row .name { font-weight: 500; }
.user-row .uname { direction: ltr; color: var(--muted); font-size: 12px; font-weight: 400; }
.user-row .actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.user-row .actions input { height: 32px; width: 170px; font-size: 14px; }
.off { opacity: .5; }

/* الدخول */
.login { max-width: 360px; width: 100%; margin: 48px auto 0; padding: 24px; }
.login h2 { font-size: 18px; margin-bottom: 18px; }
.login form { display: grid; gap: 14px; }
.login .btn { width: 100%; }

.toast {
  position: fixed; inset-inline: 16px; bottom: 20px; margin: 0 auto; max-width: 400px;
  background: var(--text); color: #fff; padding: 12px 16px; border-radius: 10px; text-align: center; font-size: 14px;
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .toast, .acct summary::after { transition: none; } }

@media (max-width: 480px) {
  .summary .big { font-size: 26px; }
  .card { padding: 16px; }
}
