:root {
  --bg: #ECF0F3;
  --surface: #FFFFFF;
  --field: #F3F6F8;
  --ink: #12263A;
  --muted: #5B6B7B;
  --line: #D3DCE4;
  --accent: #0C5F8A;
  --accent-ink: #FFFFFF;
  --gain: #14804A;
  --gain-bg: #E1F3E9;
  --loss: #B42E2B;
  --loss-bg: #F9E3E1;
  --font: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D1620; --surface: #15222F; --field: #0F1A25; --ink: #E6EDF3; --muted: #8FA1B2;
    --line: #26384A; --accent: #4DB3E6; --accent-ink: #06202F;
    --gain: #4CC38A; --gain-bg: #163526; --loss: #F0817A; --loss-bg: #3A1B1A;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.55; }
[hidden] { display: none !important; }
#app { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; }
.main { display: flex; flex-direction: column; gap: 20px; }
h1, h2, h3 { margin: 0; font-weight: 700; text-wrap: balance; }
h1 { font-size: 34px; line-height: 1.2; color: var(--accent); }
h2 { font-size: 23px; line-height: 1.3; }
h3 { font-size: 18px; margin-top: 6px; }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.card .sub { margin: 0; }
.num { font-variant-numeric: tabular-nums; unicode-bidi: isolate; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.badge { display: inline-block; padding: 1px 10px; border-radius: 999px; background: var(--field); border: 1px solid var(--line); font-size: 13px; font-weight: 700; color: var(--ink); }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.top-actions { display: flex; gap: 8px; }

.auth { max-width: 440px; margin: 40px auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* totals card, shaped like a boarding pass */
.pass { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.pass-main { padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 2px; }
.eyebrow { font-size: 16px; color: var(--muted); font-weight: 700; }
.big { font-size: 44px; line-height: 1.15; font-weight: 700; overflow-wrap: anywhere; }
.pass-cut { position: relative; border-top: 2px dashed var(--line); margin-inline: 14px; }
.pass-cut::before, .pass-cut::after { content: ""; position: absolute; top: -10px; width: 18px; height: 18px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); }
.pass-cut::before { inset-inline-start: -23px; }
.pass-cut::after { inset-inline-end: -23px; }
.pass-stats { margin: 0; padding: 14px 18px 16px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pass-stats dt, .m-stats dt { font-size: 13px; color: var(--muted); }
.pass-stats dd, .m-stats dd { margin: 0; font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }

/* forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld.wide { grid-column: 1 / -1; }
@media (min-width: 560px) { .fld.half { grid-column: span 1; } }
label { font-size: 14px; font-weight: 700; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 10px; height: 46px; padding: 0 12px; width: 100%; min-width: 0; }
input.n { text-align: right; direction: ltr; font-variant-numeric: tabular-nums; font-size: 17px; }
textarea { height: auto; min-height: 76px; padding-block: 10px; resize: vertical; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.preview { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; background: var(--field); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; font-weight: 700; }
.preview .num { font-size: 22px; }
.actions { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; }
button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); height: 46px; padding: 0 16px; font-weight: 700; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); flex: 1; min-width: 140px; }
button.small { height: 34px; padding: 0 12px; font-size: 14px; }
button.danger { color: var(--loss); border-color: var(--loss); }
.msg { grid-column: 1 / -1; margin: 0; min-height: 1.4em; font-size: 14px; color: var(--muted); }
.msg.err { color: var(--loss); font-weight: 700; }

/* months */
.months { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.month { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.month > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; }
.month > summary::-webkit-details-marker { display: none; }
.m-name { font-size: 24px; font-weight: 700; }
.m-count { grid-column: 1; color: var(--muted); font-size: 14px; }
.chip { grid-column: 2; grid-row: 1 / span 2; font-weight: 700; font-size: 18px; padding: 4px 12px; border-radius: 999px; background: var(--field); }
.chip.gain { background: var(--gain-bg); }
.chip.loss { background: var(--loss-bg); }
.m-body { border-top: 1px solid var(--line); padding: 14px 16px 6px; display: flex; flex-direction: column; gap: 10px; }
.m-stats { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 12px 0; border-top: 1px dashed var(--line); }
.r-date { font-size: 17px; color: var(--ink); min-width: 52px; font-weight: 700; }
.r-date small { display: block; font-size: 13px; color: var(--muted); font-weight: 700; text-align: center; }
.r-label { font-weight: 700; font-size: 20px; overflow-wrap: anywhere; }
.r-nums, .r-meta { display: flex; gap: 2px 12px; flex-wrap: wrap; font-size: 16px; font-weight: 700; color: var(--ink); }
.r-meta { font-size: 15px; margin-top: 4px; }
.r-nums { margin-top: 2px; }
.r-profit { font-weight: 700; font-size: 21px; }
.r-note { margin-top: 6px; padding: 6px 10px; background: var(--field); border-radius: 8px; font-size: 16px; font-weight: 700; white-space: pre-line; overflow-wrap: anywhere; }
.r-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 14px; padding: 22px 18px; color: var(--muted); text-align: center; }

/* export */
.exp-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.exp-row .fld { flex: 1 1 200px; }
.exp-row button { flex: 1 1 150px; }

/* admin */
.ulist, .alist { list-style: none; margin: 0; padding: 0; }
.ul-row { padding: 12px 0; border-top: 1px dashed var(--line); }
.ul-row:first-child, .al-row:first-child { border-top: 0; }
.u-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.ul-meta { font-size: 14px; color: var(--muted); }
.u-ctrl { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.u-ctrl select { width: auto; height: 34px; font-size: 14px; }
.u-ctrl input { flex: 1 1 140px; height: 34px; font-size: 14px; }
.al-row { padding: 10px 0; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 2px; }
.al-top { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; font-size: 14px; }
.al-act { font-weight: 700; }
.act-add, .act-user_create, .act-import { color: var(--gain); }
.act-edit, .act-user_update, .act-password_change { color: var(--accent); }
.act-delete, .act-login_failed { color: var(--loss); }
.act-login, .act-setup { color: var(--muted); }
.al-sum { font-size: 14px; overflow-wrap: anywhere; }
.al-diff { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
#recentList .row:first-child { border-top: 0; padding-top: 0; }

/* تبويبات + تقسيم الأرباح */
#accountsView, #profitsView { display: flex; flex-direction: column; gap: 20px; }
#accountsView[hidden], #profitsView[hidden] { display: none; }
.tabs { display: flex; gap: 8px; }
.tab { flex: 1; height: 48px; font-size: 17px; background: var(--surface); }
.tab.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.sc-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.sc { background: var(--field); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 16px; }
.r-split { display: flex; flex-wrap: wrap; gap: 6px 8px; margin-top: 6px; }
.r-split .sc { font-size: 15px; font-weight: 700; padding: 4px 12px; }
.sp-rows { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.sp-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px auto auto; gap: 8px; align-items: center; }
.sp-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.sp-total { font-weight: 700; }
.sp-total.ok { color: var(--gain); }
.sp-total.bad { color: var(--loss); }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 16px; }
.tbl th, .tbl td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--line); }
.tbl th { background: var(--field); font-size: 15px; }
.tbl tfoot td { font-weight: 700; background: var(--field); }
#profBody { display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 520px) {
  .tbl { font-size: 14px; }
  .tbl th, .tbl td { padding: 9px 4px; }
  .tbl th { font-size: 13px; }
}
.chk { display: flex; gap: 8px; align-items: center; font-size: 15px; }
.chk input { width: 20px; height: 20px; }
.err-box { background: var(--loss-bg); color: var(--loss); border-radius: 10px; padding: 10px 14px; font-size: 15px; }
.err-box ul { margin: 6px 0 0; padding-inline-start: 20px; }
#oldView { display: flex; flex-direction: column; gap: 20px; }
#oldView[hidden] { display: none; }
@media (max-width: 520px) { .tab { font-size: 15px; padding: 0 4px; } }
.fs-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.fs-actions .sub { margin: 0; flex: 1; min-width: 160px; }
.fs-rows { display: flex; flex-direction: column; gap: 8px; }
.fs-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px auto; gap: 8px; align-items: center; }
.sc.custom { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.opt { font-weight: 400; color: var(--muted); font-size: 0.85em; }

.r-no { font-size: 15px; color: var(--muted); font-weight: 700; }
.cus-row { cursor: pointer; }
.cus-row:focus-visible { outline: 3px solid var(--acc, #0C5F8A); outline-offset: 2px; }
.cus-name { margin: 12px 0 4px; }
