/* ميزان — ورقة أنماط واحدة، تبدأ من الجوال ثم تتسع للحاسوب.
   كل الأحجام بوحدات منطقية (RTL) والجداول تتحول إلى بطاقات على الشاشات الضيقة عبر data-label. */

:root {
  --green: #193e38; --green-2: #315c51; --teal: #0e5a56; --sheet: #00613d; --gold: #e3bb27; --accent: #a18b56;
  --bg: #f5f6f3; --surface: #fff; --ink: #23322f; --muted: #7f9387; --line: #e4ebe6; --danger: #b23a32;
  --radius: 10px; --tap: 44px; --nav-h: 62px; --side: 230px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 Tajawal, system-ui, Arial, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
h1, h2, h3, h4 { margin: 0; }
a { color: var(--green-2); }

/* ---------- الشريط العلوي والتنقل (جوال: شريط علوي + تبويبات سفلية) ---------- */
aside { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--green); color: #fff; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: .5px; }
.brand small { display: none; color: #a7bdb1; font-size: 11px; font-weight: 400; letter-spacing: 0; }
.aside-bottom { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #cfe0d6; }
.aside-note { display: none; }
.logout { border: 0; background: transparent; color: #d6e4db; padding: 8px 4px; }

.nav { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
.nav button { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.nav button i { font-style: normal; font-size: 20px; line-height: 1; }
.nav button.active { color: var(--green); font-weight: 700; box-shadow: inset 0 3px 0 var(--green); }

main { padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1500px; }
.top { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.eyebrow, .top .sub { display: none; }
.eyebrow { color: var(--accent); font-weight: 700; font-size: 12px; }
.top h1 { font-size: 22px; margin: 0; }
.sub { color: var(--muted); font-size: 13px; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.top-actions .btn { flex: 1; }

/* ---------- عناصر عامة ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 16px; border: 1px solid transparent; border-radius: 9px; background: var(--green); color: #fff; font-weight: 700; text-decoration: none; text-align: center; }
.btn.light { background: #eaf1eb; color: var(--green); }
.btn.line { background: transparent; border-color: #c9d7cd; color: var(--green); }
.btn.danger { background: var(--surface); border-color: #e3b4b0; color: var(--danger); }
.iconbtn { min-width: 36px; min-height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 17px; }
.iconbtn:hover { background: #eef2ef; color: var(--ink); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.notice { margin-bottom: 14px; padding: 12px 16px; border-radius: var(--radius); background: #e7f1e7; color: #305b43; }
.notice.error { background: #f9eae7; color: #983e35; }
.note, .note-inline { color: #98a69f; font-size: 12px; line-height: 1.8; }
.muted { color: #93a099; font-size: 12px; }
.bad, .error { color: var(--danger); }
.empty, .none { padding: 18px; text-align: center; color: #98a69f; }
.voice-status { color: #8a7650; font-size: 13px; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; background: #eef2ef; color: #4d5c56; font-size: 12px; font-weight: 700; }
.badge.payable { background: #e6eefb; color: #2a4f8f; }
.badge.receivable { background: #eaf5e6; color: #2f6a24; }
.badge.paid { background: #e3f3e8; color: #23683c; }
.badge.unpaid { background: #fdf0dc; color: #8a5a10; }

/* ---------- النماذج ---------- */
label { display: block; color: #527065; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: var(--tap); margin-top: 6px; padding: 10px 12px; border: 1px solid #dce6df; border-radius: 8px; background: var(--surface); font-size: 16px; /* 16px يمنع تكبير الصفحة في iOS */ }
textarea { min-height: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #548879; outline-offset: -1px; }
input[type=checkbox] { width: 20px; min-height: 0; height: 20px; margin: 0; }
input[type=file] { font-size: 13px; }
.inline-check { display: flex; align-items: center; gap: 8px; }
.pass-wrap { position: relative; display: block; }
.pass-wrap input { padding-inline-end: 48px; }
.pass-toggle { position: absolute; inset-inline-end: 0; bottom: 0; display: grid; place-items: center; width: var(--tap); height: var(--tap); border: 0; background: none; color: var(--muted); }
.pass-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.link { padding: 8px 0; border: 0; background: none; color: var(--green-2); font-size: 13px; text-decoration: underline; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
.full { grid-column: 1 / -1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.actions .btn { flex: 1; }
.week-controls { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 14px; }
.week-controls > * { grid-column: span 3; min-width: 0; }
.week-controls > .compact { grid-column: span 2; padding: 0 8px; }
.week-controls > .note-inline { grid-column: 1 / -1; }
.week-controls select, .week-controls input[type=date], .week-controls input[type=month] { width: 100%; margin: 0; }
.week-controls .spacer { display: none; }

dialog { width: 100%; max-width: none; max-height: 92dvh; margin: auto 0 0; padding: 0; overflow: auto; border: 0; border-radius: 16px 16px 0 0; box-shadow: 0 -10px 60px #122a2455; }
dialog::backdrop { background: #102c25a0; }
.modal { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
.modal h2 { margin-bottom: 14px; }
.audio-upload { margin-top: 18px; font-size: 12px; }

/* ---------- الجدول الأسبوعي (ورقة قابلة للطباعة) ---------- */
.sheet { max-width: 980px; margin: 0 auto; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.sheet-head { margin-bottom: 14px; text-align: center; }
.sheet-logo { color: var(--sheet); font-size: 40px; line-height: 1; }
.sheet-head h2 { margin: 6px 0 4px; color: var(--sheet); font-size: 18px; }
.sheet-title { display: inline-block; margin-top: 6px; padding: 5px 16px; border-block: 1px solid var(--gold); color: #4d5c56; font-weight: 700; font-size: 14px; }
.sheet-lawyer { margin-top: 8px; font-weight: 700; }
.sheet-day { margin-top: 14px; }
.day-bar { padding: 9px 14px; border-radius: 8px 8px 0 0; background: var(--sheet); color: #fff; font-weight: 700; font-size: 14px; }
.day-bar.total { margin-top: 16px; border-radius: 8px; text-align: center; }
.chip { display: inline-block; margin-bottom: 8px; padding: 4px 16px; border-radius: 999px; background: #f4ecc2; color: #6d5a15; font-weight: 700; }
.sheet .none { margin: 0; border: 1px solid #ece3b6; border-top: 0; padding: 12px; }

/* ---------- جداول (تتحول إلى بطاقات على الجوال) ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 9px 8px; background: #f7f0cf; text-align: center; }
td { padding: 9px 8px; border-top: 1px solid #efe8c6; text-align: center; vertical-align: middle; }
.users-table th { background: #eef2ef; }
.users-table td { border-top-color: var(--line); text-align: right; }
td.p { text-align: right; }
td.p small { display: block; margin-top: 3px; color: #8a968f; }
td.t { font-weight: 700; white-space: nowrap; }
td.n { direction: ltr; white-space: nowrap; }
.sheet tbody tr[data-edit] { cursor: pointer; }
.sheet tbody tr[data-edit]:hover { background: #faf7e6; }

.stack thead { display: none; }
.stack, .stack tbody { display: block; }
.stack tr { display: grid; gap: 6px; margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stack tr:first-child { margin-top: 0; }
.stack td { display: flex; justify-content: space-between; gap: 14px; padding: 0; border: 0; text-align: right; }
.stack td[data-label]::before { content: attr(data-label); flex: none; color: var(--muted); font-weight: 700; }
.stack td.p small { display: inline; margin: 0 6px 0 0; }
.stack td:empty { display: none; }

/* ---------- لوحة المتابعات ---------- */
.board-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 12px; margin-bottom: 14px; padding-bottom: 8px; border-bottom: 2px solid var(--teal); }
.board-head h2 { color: var(--teal); font-size: 18px; }
.board-head span { color: #6b7c75; font-size: 13px; }
.urgent-row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 16px; }
.urgent-card { padding: 14px 16px; border-right: 5px solid #e5534b; border-radius: var(--radius); background: var(--teal); color: #fff; cursor: pointer; }
.urgent-card h3 { margin: 6px 0 4px; font-size: 16px; }
.urgent-card p { margin: 0; font-size: 13px; opacity: .9; }
.urgent-card .tag { padding: 2px 8px; border-radius: 4px; background: #e5534b; font-size: 11px; font-weight: 700; }
.board-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
.board-panel { margin-bottom: 14px; padding: 14px; border: 1px solid #dfe9e3; border-radius: var(--radius); background: #f7faf8; }
.board-panel h3 { margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid #cfe0d8; color: var(--teal); font-size: 15px; }
.group { margin-bottom: 12px; }
.group h4 { margin-bottom: 6px; color: var(--green); font-size: 14px; }
.tasks { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.task.urgent { border-right: 4px solid #e5534b; }
.task.session { border-right: 4px solid var(--teal); }
.task.done b { color: #98a69f; text-decoration: line-through; }
.task input { margin-top: 3px; }
.task div { flex: 1; min-width: 0; }
.task b { font-size: 14px; overflow-wrap: anywhere; }
.task small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.task small.due { color: #a0762a; }
.task-actions { display: flex; flex: none; }

/* ---------- الفواتير ---------- */
.inv-summary { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 14px; }
.inv-card { padding: 14px 16px; border: 1px solid #dfe9e3; border-radius: var(--radius); background: #f7faf8; }
.inv-card.alert { border-color: #efc9c4; background: #fdf2f0; }
.inv-card h3 { margin-bottom: 6px; color: var(--teal); font-size: 14px; }
.inv-card .big { color: var(--green); font-size: 24px; font-weight: 800; }
.inv-card .big small { color: var(--muted); font-size: 12px; font-weight: 400; }
.inv-lines { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin-top: 8px; color: #5f716a; font-size: 13px; }

/* ---------- الإعدادات وتسجيل الدخول ---------- */
.settings-grid { display: grid; gap: 24px; grid-template-columns: 1fr; line-height: 1.9; font-size: 14px; }
.settings-grid h3 { margin: 18px 0 8px; }
.settings-grid h3:first-child { margin-top: 0; }
.settings-grid p { overflow-wrap: anywhere; }
.settings-grid .btn { margin: 4px 0; }
.status-row { display: flex; justify-content: space-between; gap: 14px; margin: 0; padding: 9px 0; border-bottom: 1px solid #edf1ed; }
.status-row span { color: #7b9083; }
.status-row strong { font-weight: 500; text-align: left; }
.login-screen { display: grid; place-items: center; min-height: 100dvh; padding: 20px; background: #edf2ec; }
.login-card { width: 100%; max-width: 420px; padding: 28px 22px; }
.login-card .brand { color: #245343; }
.login-card h1 { margin: 10px 0 4px; font-size: 24px; }
.login-card label { margin-top: 18px; }
.login-card .btn { width: 100%; margin-top: 16px; }
.login-card .link { display: block; margin: 8px auto 0; }
.login-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 12px; margin-top: 14px; }
.login-row .inline-check { font-weight: 400; }
.login-row .link { margin: 0; }
#loginError, #forgotMessage, #resetMessage, #formError, #taskError, #userError, #invError { color: var(--danger); }
#loginError.ok, #forgotMessage.ok, #resetMessage.ok { color: #23683c; }
.demo-bar { position: sticky; top: 0; z-index: 60; padding: 6px 12px; background: #8a5a10; color: #fff; font-size: 13px; font-weight: 700; text-align: center; }

/* ---------- الحاسوب ---------- */
@media (min-width: 700px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .settings-grid { grid-template-columns: 1fr 1fr; gap: 40px; }
  .board-grid { grid-template-columns: 1fr 1fr; }
  .top { flex-direction: row; justify-content: space-between; align-items: center; }
  .eyebrow, .top .sub { display: block; }
  .top h1 { font-size: 24px; margin: 4px 0; }
  .top-actions .btn { flex: none; }
  .actions .btn { flex: none; }
  .week-controls { display: flex; flex-wrap: wrap; align-items: center; }
  .week-controls > *, .week-controls > .compact { grid-column: auto; }
  .week-controls .spacer { display: block; }
  .week-controls select, .week-controls input[type=date], .week-controls input[type=month] { width: auto; min-width: 170px; }
  dialog { width: min(560px, 94vw); max-height: 90dvh; margin: auto; border-radius: 16px; box-shadow: 0 20px 80px #122a2444; }
  .modal { padding: 26px; }
  .panel { padding: 22px; }
  .sheet { padding: 22px; }
  .sheet-head h2 { font-size: 21px; }

  .stack thead { display: table-header-group; }
  .stack { display: table; }
  .stack tbody { display: table-row-group; }
  .stack tr { display: table-row; margin: 0; padding: 0; border: 0; border-radius: 0; background: none; }
  .stack td { display: table-cell; padding: 9px 8px; border-top: 1px solid #efe8c6; text-align: center; }
  .stack td[data-label]::before { content: none; }
  .stack td:empty { display: table-cell; }
  .sheet td:empty::before { content: "-"; }
  .users-table td { text-align: right; }
}
@media (min-width: 1000px) {
  aside { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--side); flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 0; padding: 32px 22px; }
  .brand small { display: block; margin-top: 4px; }
  .aside-bottom { flex-direction: column; align-items: flex-start; gap: 4px; margin-top: auto; font-size: 12px; line-height: 1.8; color: #9db4a7; }
  .aside-note { display: block; }
  .logout { padding: 0; margin-top: 10px; }
  .nav { position: static; display: grid; gap: 8px; height: auto; margin-top: 48px; padding: 0; border: 0; background: none; }
  .nav button { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 13px 16px; border-radius: 10px; color: #bbccc3; font-size: 15px; }
  .nav button i { font-size: 17px; }
  .nav button.active { background: var(--green-2); color: #fff; box-shadow: none; }
  main { margin-inline-start: var(--side); padding: 36px 5%; }
}

/* ---------- الطباعة: الجدول الأسبوعي فقط ---------- */
@media print {
  aside, .nav, .top, .week-controls, .notice, dialog, .voice-status { display: none !important; }
  main { margin: 0 !important; padding: 0 !important; max-width: none; }
  body { background: #fff; }
  #boardView, #invoicesView, #usersView, #settings { display: none !important; }
  .panel { padding: 0; border: 0; }
  .sheet { max-width: none; padding: 0; border: 0; }
  .day-bar, th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-day { break-inside: avoid; }
  @page { size: A4 portrait; margin: 12mm; }
}
