@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+Arabic:wght@400;500;600;700&display=swap");

:root {
  --bg: #f4f6f8;
  --paper: #ffffff;
  --ink: #1c1f24;
  --muted: #8b939e;
  --text: #3d4450;
  --line: #e7eaee;
  --line-strong: #dfe3e8;
  --sidebar: #ffffff;
  --active: #f2f4f7;
  --accent: #17191c;
  --good: #17803d;
  --good-bg: #eef8f1;
  --warn: #9a6700;
  --warn-bg: #fbf6ea;
  --bad: #c2413b;
  --bad-bg: #fdf1f0;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  --sans: Inter, "Noto Sans Arabic", "Segoe UI", sans-serif;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
}
html[dir="rtl"] body { font-family: "Noto Sans Arabic", Inter, "Segoe UI", sans-serif; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid #c5ccd6; outline-offset: 2px; }

.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  border-inline-end: 1px solid var(--line);
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  text-decoration: none;
  color: var(--ink);
  margin: 2px 8px 22px;
}
.brand strong { display: block; font-size: 14px; font-weight: 600; }
.brand small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: #17191c;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.nav-label {
  margin: 14px 10px 6px;
  color: #a0a7b1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.nav { display: grid; gap: 2px; }
.nav a {
  text-decoration: none;
  color: #4b5563;
  padding: 9px 10px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 14px;
}
.nav a:hover { background: #f7f8fa; }
.nav a.active { background: var(--active); color: var(--ink); font-weight: 600; }
.logout {
  margin-top: auto;
  color: #4b5563;
  text-decoration: none;
  padding: 10px;
  border-radius: 10px;
  font-weight: 500;
}
.logout:hover { background: #f7f8fa; }
.lang-switch { display: flex; gap: 4px; align-items: center; }
.lang-switch a {
  text-decoration: none;
  color: #4b5563;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}
.lang-switch a.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.login-card .lang-switch { margin: 0 0 14px; }

.main { min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 28px 0;
}
.topbar p { margin: 0; color: var(--muted); font-size: 13px; }
.top-meta { display: flex; gap: 14px; align-items: center; color: var(--text); font-size: 13px; }
.top-meta strong { font-weight: 600; color: var(--ink); }
.page { padding: 14px 28px 40px; display: grid; gap: 14px; }
.page > h1 {
  margin: 4px 0 2px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.card, .stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 16px 16px 18px; }
.card-head, .day-head, .row-actions, .month-form, .cat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.card-head { margin-bottom: 12px; }
.card-head a { color: var(--ink); font-weight: 600; font-size: 13px; text-decoration: none; }
.card-head a:hover { text-decoration: underline; }
.card h2, .card h3, .day-head h3, .modal-card h3, .result-card h3, .badge h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.day-head h3 { font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { padding: 14px 14px 12px; }
.stat span { display: block; color: var(--muted); font-size: 13px; }
.stat strong {
  display: block;
  margin-top: 10px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.stat strong.pos { color: var(--good); font-size: 22px; }
.stat em { display: block; margin-top: 6px; color: var(--muted); font-style: normal; font-size: 12px; font-weight: 500; }
.expense-stats { grid-template-columns: repeat(2, minmax(180px, 280px)); }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 12px; align-items: end; }
.filter-picks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.breakdown a { font-weight: 600; text-decoration: none; }
.breakdown a:hover { text-decoration: underline; }
.breakdown strong { color: var(--good); font-weight: 600; }

.split, .detail-grid, .scan-grid { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 12px; }
.expense-layout { display: grid; grid-template-columns: 260px 1fr; gap: 12px; align-items: start; }

.field { display: grid; gap: 6px; }
.field span, .person-meta span { color: var(--muted); font-size: 12px; font-weight: 500; }
.field input, .field select, .field textarea, .search, .month-form select,
.month-form input {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
}
.field input:focus, .field select:focus, .field textarea:focus, .search:focus {
  outline: none;
  border-color: #c5ccd6;
}
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-items: end; }
.field.wide { grid-column: 1 / -2; }
.stack { display: grid; gap: 12px; }
.stack.tight { margin-top: 14px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
}
.btn.primary { background: var(--accent); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: #f7f8fa; }
.btn.danger { background: #fff; color: var(--bad); border-color: #f3d4d1; }
.btn.wide { width: 100%; }
.text-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 4px 6px; font-size: 13px; }
.text-btn:hover { color: var(--bad); }

.people { display: grid; gap: 8px; }
.person {
  display: grid;
  grid-template-columns: auto minmax(140px, 1.3fr) minmax(100px, 0.8fr) minmax(100px, 0.8fr) minmax(140px, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 8px;
  border-radius: 12px;
}
.person:hover { background: #f7f8fa; }
.person a, .timeline a { font-weight: 600; text-decoration: none; }
.person small, .timeline small, td small { display: block; color: var(--muted); font-size: 12px; }
.person-meta strong { display: block; font-size: 13px; font-weight: 600; }
.person-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.person-actions form { margin: 0; }
.person-actions .btn { padding: 7px 10px; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #eef1f4;
  color: #3d4450;
  font-size: 12px;
  font-weight: 600;
}
.avatar.lg { width: 52px; height: 52px; font-size: 16px; margin: 0 auto 8px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.timeline li:last-child { border-bottom: 0; }
.timeline time, .end time { color: var(--muted); font-size: 12px; }
.end { text-align: end; display: grid; justify-items: end; gap: 2px; }
.end b, td.num { font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 99px; }
.tag { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 600; }
.tag.in { background: var(--good-bg); color: var(--good); }
.tag.out { background: #f3f4f6; color: #4b5563; }
.tag.open { background: var(--warn-bg); color: #8a5a12; }
.tag.miss { background: var(--bad-bg); color: var(--bad); }
.row-actions .btn { min-width: 108px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: start; color: var(--muted); font-size: 12px; font-weight: 500; padding: 8px; }
td { padding: 12px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
td.num, th:last-child { text-align: end; font-variant-numeric: tabular-nums; }
.total-line { margin: 0 0 8px; color: var(--muted); }
.total-line strong, .card-head > strong, .day-head span { color: var(--good); font-weight: 600; }
.plain-list { list-style: none; margin: 12px 0 0; padding: 0; }
.plain-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.plain-list small { color: var(--muted); }

.badge { text-align: center; padding: 8px 8px 4px; }
.badge h3 { font-size: 18px; margin-top: 8px; }
.badge p { margin: 4px 0 12px; color: var(--muted); }
.qr-box { display: grid; place-items: center; min-height: 180px; }
.door-qr { min-height: 300px; }
.door-timer { text-align: center; color: var(--muted); margin: 8px 0 0; }
.door-card { text-align: center; }
.qr-box img, .qr-box canvas { border-radius: 8px; }

.lead { margin: 0 0 14px; color: var(--muted); }
.reader-wrap { margin-top: 12px; border-radius: 12px; overflow: hidden; background: #111; border: 1px solid var(--line); }
#reader { min-height: 260px; }
.result-card {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.result-card h3 { font-size: 16px; }
.result-card p, .result-card span { margin: 2px 0 0; color: var(--text); }
.result-card.good { background: var(--good-bg); border-color: #d7efdf; }
.result-card.warn { background: var(--warn-bg); border-color: #f0e6cc; }
.result-card.bad { background: var(--bad-bg); border-color: #f3d6d4; }
.manual { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 10px; }

.cats { display: grid; gap: 6px; align-content: start; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  border-radius: 10px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  font-weight: 500;
}
.chip:hover { background: #f7f8fa; }
.chip.on { background: var(--active); color: var(--ink); font-weight: 600; }
.chip i { width: 8px; height: 8px; border-radius: 99px; display: block; }
.day-block + .day-block { margin-top: 8px; }
.day-head { margin: 8px 0 0; }
.day-head span { font-size: 13px; }

.flash { padding: 10px 12px; border-radius: 10px; font-size: 13px; }
#fault-warn { margin-top: 12px; }
.flash.good { background: var(--good-bg); color: var(--good); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.empty { color: var(--muted); margin: 4px 0 8px; }
.muted { color: var(--muted); }
.search { max-width: 220px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 19, 22, 0.35);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 18px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(16, 24, 40, 0.12);
}
.modal-card h3 { font-size: 18px; margin-top: 8px; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
}
.login-card h1 {
  margin: 8px 0 4px;
  font-size: 20px;
  font-weight: 600;
}
.login-card form { display: grid; gap: 12px; }

@media (max-width: 980px) {
  .shell { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    z-index: 5;
    border-inline-end: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }
  .nav { display: flex; gap: 4px; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .nav-label, .logout, .brand small { display: none; }
  .brand { margin: 0 0 8px; }
  .topbar, .page { padding-left: 16px; padding-right: 16px; }
  .stats, .expense-stats, .split, .detail-grid, .scan-grid, .expense-layout, .form-grid, .filter-grid { grid-template-columns: 1fr; }
  .person { grid-template-columns: auto 1fr; }
  .person-meta, .person-actions { grid-column: 2; }
  .person-actions { justify-content: flex-start; }
  .field.wide { grid-column: auto; }
}

@media print {
  body * { visibility: hidden; }
  .print-sheet, .print-sheet * { visibility: visible; }
  .print-sheet { position: absolute; left: 0; top: 0; display: flex; gap: 24px; background: #fff; }
  .badge-print { box-shadow: none; }
  .no-print { display: none !important; }
}
