:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #1a2332;
  --muted: #5c6b7a;
  --border: #e2e8ee;
  --primary: #0e4a5a;
  --primary-2: #16697a;
  --primary-soft: #e6f2f4;
  --accent: #c8962e;
  --accent-soft: #f8efd8;
  --ok: #1b7a4e;
  --ok-soft: #e5f6ec;
  --warn: #c27803;
  --warn-soft: #fff4e0;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --info: #1d5f9a;
  --info-soft: #e7f1fa;
  --shadow: 0 10px 30px rgba(16, 36, 48, .06);
  --radius: 14px;
  --sidebar: 272px;
  --topbar: 64px;
  --font: "Cairo", "Segoe UI", Tahoma, sans-serif;
}

html[data-theme="dark"] {
  --bg: #10161c;
  --surface: #182128;
  --surface-2: #222c35;
  --text: #e8eef4;
  --muted: #93a1ae;
  --border: #2b3843;
  --primary: #3aa0b5;
  --primary-2: #2d8496;
  --primary-soft: #15343c;
  --accent: #d4ae55;
  --accent-soft: #3a3218;
  --ok: #4caf7a;
  --ok-soft: #173326;
  --warn: #e0a03a;
  --warn-soft: #3a2c12;
  --danger: #e06b63;
  --danger-soft: #3a1c1a;
  --info: #6aaee0;
  --info-soft: #173044;
  --shadow: 0 10px 30px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { direction: rtl; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.65;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 1rem; }
img { max-width: 100%; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  background: var(--primary);
  color: #f4fbfc;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--accent); color: #1a1404;
  display: grid; place-items: center; font-weight: 800;
}
.brand small { display: block; opacity: .75; font-size: 12px; }
.nav { padding: 10px 8px 28px; display: flex; flex-direction: column; gap: 1px; }
.nav-link, .nav-parent {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  color: rgba(255,255,255,.88);
  cursor: pointer;
  text-align: right;
  font: inherit;
}
.nav-label { flex: 1; }
.nav-caret { opacity: .55; display: grid; transition: transform .15s; }
.nav-group.is-open .nav-caret { transform: rotate(180deg); }
.nav-link:hover, .nav-parent:hover, .nav-group.is-open > .nav-parent { background: rgba(255,255,255,.08); }
.nav-link.is-active { background: rgba(255,255,255,.16); color: #fff; font-weight: 700; }
.nav-icon { width: 22px; height: 22px; display: grid; place-items: center; flex-shrink: 0; opacity: .95; }
.nav-icon .icon { display: block; color: inherit; }
.nav-children { display: none; padding: 2px 6px 8px 6px; }
.nav-group.is-open .nav-children { display: block; }
.nav-children a {
  display: block; padding: 7px 12px 7px 12px; margin-right: 22px; border-radius: 8px;
  color: rgba(255,255,255,.75); font-size: .9rem;
}
.nav-children a.is-active, .nav-children a:hover { background: rgba(255,255,255,.1); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.topbar-right, .topbar-left { display: flex; align-items: center; gap: 10px; }
.content { padding: 22px; }

.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; font-size: 1.45rem; }
.muted { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: .9rem; }
.kpi .value { font-size: 1.45rem; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.kpi.positive .value { color: var(--ok); }
.kpi.negative .value { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 700;
  background: var(--surface-2); color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); color: #1a1404; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-sm { padding: 6px 10px; font-size: .88rem; font-weight: 600; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 10px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search {
  flex: 1; min-width: 220px; position: relative;
}
.search input, .input, select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
textarea { min-height: 92px; resize: vertical; }
.search input:focus, .input:focus, select:focus, textarea:focus {
  border-color: var(--primary-2); box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-weight: 700; font-size: .92rem; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }

.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
table.data th { color: var(--muted); font-size: .82rem; font-weight: 800; background: var(--surface-2); }
table.data tr:hover td { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
.actions { display: flex; gap: 6px; }

.badge {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 2px 9px; font-size: .78rem; font-weight: 800;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--surface-2); color: var(--muted); }

.toast-wrap { position: fixed; top: 18px; left: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 260px; }
.toast.success { border-color: var(--ok); }
.toast.error { border-color: var(--danger); }

.empty { padding: 42px 18px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; }
.pager-pages { display: flex; gap: 6px; flex-wrap: wrap; }
.pager-link { min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); }
.pager-link.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(10,18,24,.45); display: none; align-items: center; justify-content: center; z-index: 70; padding: 18px; }
.modal-backdrop.is-open { display: flex; }
.modal { width: min(560px, 100%); background: var(--surface); border-radius: 16px; padding: 18px; }
.section { margin-top: 16px; }
.section h3 { margin: 0 0 10px; font-size: 1.05rem; display: flex; justify-content: space-between; align-items: center; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 500px at 80% -10%, #1a6b7c 0%, var(--primary) 45%, #08262e 100%); padding: 20px; }
.login-card { width: min(420px, 100%); background: #fff; color: #1a2332; border-radius: 18px; padding: 28px; }
.guest-error { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 800; }
.menu-toggle { display: none; }
.chart-box { height: 260px; padding: 8px 12px 16px; }
.ledger-net { font-size: 1.6rem; font-weight: 800; }
.print-sheet { max-width: 900px; margin: 24px auto; background: #fff; color: #111; padding: 28px; }
@media (max-width: 1100px) {
  .kpis, .log-totals { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; right: 0; transform: translateX(105%); z-index: 40; transition: .2s transform; }
  body.nav-open .sidebar { transform: none; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 14px; }
}
.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
.btn .icon { margin-inline-end: 2px; }
.btn-icon { width: 38px; height: 38px; padding: 0; }
.btn-icon .icon { margin: 0; }
.topbar-bell { position: relative; }
.topbar-bell .badge { position: absolute; top: 2px; left: 2px; min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px; }

.num, input.money, .kpi .value, .total-box b, table.data td.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}
input.money { letter-spacing: .01em; }

.log-sheet { display: flex; flex-direction: column; gap: 14px; }
.log-sheet > .page-head { margin-bottom: 0; }
.log-meta { padding: 16px 18px; }
.log-meta-grid { display: grid; grid-template-columns: 180px 1fr 1fr; gap: 14px; }
.log-block { overflow: hidden; }
.log-block .card-head { background: var(--surface-2); }
.section-title { display: inline-flex; align-items: center; gap: 8px; }
.log-totals { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; position: sticky; bottom: 12px; }
.total-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.total-box b { display: block; font-size: 1.12rem; margin-top: 4px; }
.total-box.is-net { border-color: var(--primary); background: var(--primary-soft); }
.log-block .table-wrap { min-height: 52px; }
.log-block table.data th, .log-block table.data td { padding: 8px 10px; }
.log-block table.data .input { min-width: 0; padding: 8px 10px; }
.log-block table.data .input.money { min-width: 112px; }
.log-block table.data th:last-child, .log-block table.data td:last-child { width: 52px; }
.search { position: relative; }
.search .icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-right: 38px; }

@media (max-width: 1100px) {
  .log-meta-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .log-meta-grid { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .topbar, .toolbar, .btn, .no-print { display: none !important; }
  .app, .main, .content { display: block; background: #fff; }
  .card { box-shadow: none; }
  .log-totals { position: static; }
}
