:root {
  --font-scale: 1;
  --color-navy: #0f2340;
  --color-navy-light: #1c3a63;
  --color-gold: #c8992f;
  --color-green: #2e7d4f;
  --color-yellow: #b8860b;
  --color-red: #c0392b;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #1a1f2b;
  --muted: #6b7380;
  --border: #e1e5eb;
}

html[data-theme="dark"] {
  --bg: #10151d;
  --card-bg: #1a212c;
  --text: #eef1f5;
  --muted: #97a1ae;
  --border: #2a3441;
  --color-navy-light: #24466f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, "Cairo", "Noto Sans Arabic", sans-serif;
  font-size: calc(16px * var(--font-scale));
  direction: rtl;
}

#app { min-height: 100vh; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: 1em;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}

/* ---------------- Login ---------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--color-navy), var(--color-navy-light));
  padding: 20px;
}
.login-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.login-card h1 { font-size: 1.3em; color: var(--color-navy); margin-bottom: 4px; }
html[data-theme="dark"] .login-card h1 { color: var(--color-gold); }
.login-card input { margin: 8px 0; }
.login-card button {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: var(--color-navy);
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
}

/* ---------------- App shell ---------------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app-header {
  background: var(--color-navy);
  color: #fff;
  padding: 14px 16px;
  text-align: center;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 5;
}
.tab-content {
  flex: 1;
  padding: 16px;
  padding-bottom: 90px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.tab-bar {
  position: fixed;
  bottom: 0; right: 0; left: 0;
  display: flex;
  justify-content: space-around;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
.tab-btn {
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: .78em;
  padding: 6px 10px;
  border-radius: 10px;
}
.tab-btn.active { color: var(--color-navy); font-weight: 700; }
html[data-theme="dark"] .tab-btn.active { color: var(--color-gold); }
.tab-icon { font-size: 1.3em; }

/* Desktop: right sidebar instead of bottom bar */
@media (min-width: 1025px) {
  .app-shell { flex-direction: row-reverse; }
  .tab-bar {
    position: sticky;
    top: 0;
    height: 100vh;
    flex-direction: column;
    width: 190px;
    border-top: none;
    border-left: 1px solid var(--border);
    padding-top: 24px;
    gap: 6px;
  }
  .tab-btn { flex-direction: row; justify-content: flex-start; font-size: .95em; width: 100%; padding: 10px 16px; }
  .app-header { display: none; }
  .tab-content { padding: 32px; padding-bottom: 32px; max-width: 1100px; }
}
@media (min-width: 481px) and (max-width: 1024px) {
  .tab-content { max-width: 700px; }
}

/* ---------------- Search tab ---------------- */
.search-hero { text-align: center; }
.search-box { max-width: 480px; margin: 12px auto; font-size: 1.05em; padding: 14px 16px; }
.search-results { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; text-align: right; }
.result-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: right;
  transition: transform .1s ease;
}
.result-card:active { transform: scale(.98); }
.result-title { font-weight: 700; }
.result-subtitle { color: var(--muted); font-size: .85em; margin-top: 2px; }

.recent-wrap { max-width: 560px; margin: 20px auto 0; text-align: right; }
.recent-title { color: var(--muted); font-size: .85em; margin-bottom: 6px; }
.recent-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: .85em;
}

/* ---------------- Tenant profile overlay ---------------- */
.tenant-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
@media (min-width: 720px) {
  .tenant-overlay { align-items: center; justify-content: center; }
}
.tenant-sheet {
  background: var(--card-bg);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px;
  position: relative;
}
@media (min-width: 720px) {
  .tenant-sheet { border-radius: 18px; }
}
.close-btn {
  position: absolute; top: 12px; left: 12px;
  background: var(--bg);
  border-radius: 50%;
  width: 32px; height: 32px;
  font-size: 1em;
}
.tenant-id-card h2 { margin: 0 0 8px; color: var(--color-navy); }
html[data-theme="dark"] .tenant-id-card h2 { color: var(--color-gold); }
.id-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.id-grid div { display: flex; flex-direction: column; font-size: .85em; }
.id-grid span { color: var(--muted); }
.badge-danger {
  display: inline-block;
  background: var(--color-red);
  color: #fff;
  border-radius: 20px;
  padding: 4px 10px;
  font-size: .8em;
  margin-top: 6px;
}
.subtabs { display: flex; gap: 6px; overflow-x: auto; margin: 16px 0 10px; }
.subtab {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  white-space: nowrap;
  font-size: .85em;
}
.subtab.active { background: var(--color-navy); color: #fff; }
.tenant-subcontent { display: flex; flex-direction: column; gap: 8px; min-height: 80px; }
.list-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: .9em;
}
.list-row.archived { opacity: .55; }
.row-strong { font-weight: 700; margin-bottom: 4px; }
.chip-green, .chip-yellow, .chip-red {
  display: inline-block;
  border-radius: 20px;
  padding: 3px 10px;
  font-size: .8em;
  width: fit-content;
  color: #fff;
}
.chip-green { background: var(--color-green); }
.chip-yellow { background: var(--color-yellow); }
.chip-red { background: var(--color-red); }

.tenant-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.tenant-actions button {
  flex: 1;
  min-width: 100px;
  background: var(--color-navy);
  color: #fff;
  border-radius: 10px;
  padding: 10px;
  font-size: .85em;
}

/* ---------------- Calculator tab ---------------- */
.calc-menu { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; }
.calc-menu-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  white-space: nowrap;
  font-size: .88em;
}
.calc-menu-btn.active { background: var(--color-navy); color: #fff; }
.calc-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}
.calc-card.highlight { border-color: var(--color-gold); }
.calc-card h3 { margin-top: 0; }
.calc-card label { display: flex; flex-direction: column; gap: 4px; font-size: .85em; margin-bottom: 10px; color: var(--muted); }
.unit-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.unit-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; }
.remove-row {
  background: var(--bg);
  border-radius: 8px;
  width: 36px;
  color: var(--color-red);
  font-weight: 700;
}
.mini-btn {
  background: var(--color-navy-light);
  color: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: .85em;
}
.calc-result { margin-top: 10px; font-weight: 600; }
.calc-result.big { font-size: 1.3em; color: var(--color-navy); }
html[data-theme="dark"] .calc-result.big { color: var(--color-gold); }
.rent-year-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; align-items: end; }
.rent-year-row label { flex: 1; min-width: 140px; }

/* ---------------- Notes tab ---------------- */
.note-composer { background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 16px; }
.note-composer textarea { resize: vertical; }
.note-composer-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.note-composer-row input { flex: 1; min-width: 140px; }
#note-add-btn { background: var(--color-navy); color: #fff; border-radius: 8px; padding: 10px 18px; }
.tenant-suggestions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.notes-list { display: flex; flex-direction: column; gap: 10px; }
.note-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.note-card.pinned { border-color: var(--color-gold); }
.note-meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.tag { background: var(--bg); border-radius: 20px; padding: 3px 10px; font-size: .75em; color: var(--muted); }
.note-actions { display: flex; gap: 8px; }
.note-actions button { background: var(--bg); border-radius: 8px; padding: 6px 10px; font-size: .8em; }

/* ---------------- Account tab ---------------- */
.switch-row { display: flex !important; flex-direction: row !important; justify-content: space-between; align-items: center; }
.switch-row input { width: auto; }
.danger-btn {
  width: 100%;
  background: var(--color-red);
  color: #fff;
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
  font-weight: 600;
}

/* ---------------- Admin tab ---------------- */
.dashboard-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
@media (min-width: 720px) { .dashboard-grid { grid-template-columns: repeat(3, 1fr); } }
.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-card span { color: var(--muted); font-size: .8em; }
.kpi-card b { font-size: 1.2em; }
.kpi-card.danger { border-color: var(--color-red); }
.kpi-card.danger b { color: var(--color-red); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
@media (min-width: 720px) { .form-grid { grid-template-columns: repeat(4, 1fr); } }
.admin-table { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.row-actions { display: flex; gap: 6px; margin-top: 6px; }
.row-actions button { background: var(--bg); border-radius: 8px; padding: 6px 10px; font-size: .8em; }

.muted { color: var(--muted); }
.center-pad { padding: 40px 0; text-align: center; }

/* Print */
@page { size: A4; margin: 16mm 12mm; }
@media print {
  .tab-bar, .app-header, .tenant-actions, .close-btn, .report-modal-overlay { display: none !important; }
  .tenant-overlay { position: static; background: none; }
  .tenant-sheet { max-height: none; overflow: visible; box-shadow: none; }
  .list-row, .kpi-card, .id-card, .tenant-id-card { page-break-inside: avoid; }
  table, .admin-table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
}

/* ---------------- لوحة الإدارة: صف العنوان + زر التقرير العام ---------------- */
.admin-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ---------------- نافذة التقرير الديناميكي (reportModal.js) ---------------- */
.report-modal-sheet { max-width: 480px; }
.report-fieldset { border: 1px solid var(--border, #ddd); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.report-fieldset legend { padding: 0 6px; font-weight: 600; font-size: .9em; }
.report-fieldset label { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: .92em; }
.report-modal-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.report-result { margin-top: 14px; font-size: .9em; }
.report-result-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* ---------------- Toast (errorHandler.js) ---------------- */
.toast-container {
  position: fixed;
  bottom: 84px;
  inset-inline: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
  padding: 0 12px;
}
.toast {
  pointer-events: auto;
  max-width: 480px;
  width: 100%;
  background: var(--color-navy);
  color: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: .92em;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .25s ease, transform .25s ease;
  cursor: pointer;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--color-red); }
.toast-success { background: var(--color-green); }
.toast-warning { background: var(--color-yellow); color: #1a1f2b; }
.toast-info { background: var(--color-navy-light); }

/* ---------------- Pagination (pagination.js) ---------------- */
.paginated-rows { display: flex; flex-direction: column; gap: 8px; }
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.pagination-bar .page-info { color: var(--muted); font-size: .85em; text-align: center; flex: 1; }
.pagination-bar button {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: .85em;
  color: var(--text);
}
.pagination-bar button:disabled { opacity: .4; cursor: not-allowed; }
.pagination-bar button:not(:disabled):hover { border-color: var(--color-gold); }

/* ---------------- File upload (admin.js documents) ---------------- */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px 12px;
  text-align: center;
  margin-bottom: 8px;
  transition: border-color .2s ease, background .2s ease;
}
.file-drop.dragover { border-color: var(--color-gold); background: rgba(200, 153, 47, .08); }
.file-drop p { margin: 0; color: var(--muted); font-size: .9em; }
.file-drop #d-file-name { margin-top: 6px; font-size: .82em; }
.link-btn {
  background: none;
  border: none;
  color: var(--color-navy-light);
  text-decoration: underline;
  cursor: pointer;
  font-size: 1em;
  padding: 0;
}
html[data-theme="dark"] .link-btn { color: var(--color-gold); }

/* ---------------- Unified UI states (loading / empty / error) ---------------- */
.ui-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 22px 12px;
  color: var(--muted);
  font-size: .92em;
  text-align: center;
}
.ui-state-error { color: var(--color-red); }
.ui-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--color-gold);
  border-radius: 50%;
  animation: ui-spin .7s linear infinite;
  display: inline-block;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }
.ui-retry-btn {
  background: var(--card-bg);
  border: 1px solid var(--color-red);
  color: var(--color-red);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .85em;
  cursor: pointer;
}

/* ---------------- Router-aware admin subtabs (deep link highlight) ---------------- */
.subtab[data-sec] { cursor: pointer; }

/* ============================================================
   إضافات إصلاحات تقرير التدقيق (Phase 4)
   ============================================================ */

/* زر خطر مصغّر (استعادة نسخة احتياطية، إلغاء عمليات حسّاسة) */
.danger-btn-mini {
  background: var(--color-red);
  color: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: .85em;
  font-weight: 600;
}
.danger-btn-mini:hover { opacity: .9; }

/* نافذة تأكيد استعادة النسخة الاحتياطية (تعيد استخدام tenant-overlay/tenant-sheet) */
.restore-modal-sheet { max-width: 480px; }
.restore-modal-sheet .form-grid { grid-template-columns: 1fr; }
.restore-modal-sheet .switch-row { align-items: flex-start !important; gap: 10px; text-align: right; }
.restore-modal-sheet .switch-row input { margin-top: 4px; }

/* شريط تنبيه "غير متصل بالإنترنت" في تبويب البحث */
.offline-banner {
  max-width: 560px;
  margin: 8px auto 0;
  background: var(--color-yellow);
  color: #1a1f2b;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .85em;
  text-align: center;
}

