:root {
  --primary: #1B6B93;
  --primary-dark: #134e6b;
  --primary-soft: #e7f3f8;
  --accent: #2a9d8f;
  --success: #0f9d58;
  --warning: #e6a700;
  --danger: #d93025;
  --info: #1a73e8;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --text: #1c2834;
  --muted: #5d6d7e;
  --border: #e3eaf0;
  --sidebar: #0d3b4f;
  --sidebar-text: #d7e6ee;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(13, 59, 79, 0.07);
  --header-h: 64px;
  --sidebar-w: 248px;
  --bottom-h: 64px;
}

[data-theme="dark"] {
  --bg: #0f1720;
  --surface: #17202a;
  --text: #e8eef3;
  --muted: #9aabba;
  --border: #2a3947;
  --sidebar: #0b2836;
  --sidebar-text: #c5d6e0;
  --primary-soft: #163544;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { direction: rtl; }
html, body {
  font-variant-numeric: tabular-nums lining-nums;
}
body {
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums lining-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
button, input, select, textarea { font-family: inherit; font-variant-numeric: tabular-nums; }

.icon {
  flex-shrink: 0;
  display: block;
  opacity: .92;
}
.nav-item .icon, .nav-group summary .icon { opacity: .85; }
.nav-item.active .icon, .nav-group[open] > summary .icon:first-child { opacity: 1; }
.nav-group summary .icon:last-child {
  margin-inline-start: auto;
  opacity: .55;
  transition: transform .15s ease;
}
.nav-group[open] > summary .icon:last-child { transform: rotate(90deg); }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-text);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 16px 10px 72px;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 16px;
  color: #fff; font-weight: 700; font-size: 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: 10px;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}
.brand-logo { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; background: #fff; }
.nav-item, .nav-sub a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 10px; color: var(--sidebar-text);
  font-size: 15px; font-weight: 600;
}
.nav-item:hover, .nav-sub a:hover, .nav-item.active {
  background: rgba(255,255,255,.08); color: #fff;
}
.nav-item.active { background: var(--primary); }
.nav-group summary {
  list-style: none; cursor: pointer;
  padding: 9px 11px; border-radius: 10px;
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 600; color: var(--sidebar-text);
}
.nav-group summary:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-sub { padding: 2px 4px 8px 4px; display: grid; gap: 1px; }
.nav-sub a { padding-inline-start: 38px; font-weight: 500; font-size: 14px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  min-height: var(--header-h);
  height: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 8px 18px; position: sticky; top: 0; z-index: 20;
}
.topbar-start {
  display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;
}
.topbar-user { min-width: 0; flex: 1; }
.topbar-greet {
  display: block;
  font-size: 15px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.topbar-role { font-size: 12px; line-height: 1.3; margin-top: 1px; }
.topbar-actions {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}
.topbar-add { white-space: nowrap; }
.icon-btn {
  width: 38px; height: 38px; border: 1px solid var(--border);
  background: var(--surface); border-radius: 10px; cursor: pointer;
  display: grid; place-items: center; color: var(--text); position: relative;
  flex-shrink: 0;
}
.icon-btn .icon { opacity: .8; }
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.icon-btn .dot {
  position: absolute; top: 7px; left: 7px; width: 7px; height: 7px;
  background: var(--danger); border-radius: 50%;
}
.content { padding: 18px 18px 88px; max-width: 1280px; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 23px; font-weight: 800; letter-spacing: -.01em; }
.page-head .muted { margin: 4px 0 0; font-size: 14px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
}
.card h3 { margin: 0 0 12px; font-size: 16px; font-weight: 800; }

.stat {
  display: flex; flex-direction: column; gap: 8px;
  min-height: 92px; justify-content: space-between;
}
.stat .label { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat .value {
  font-size: 22px; font-weight: 800; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.25;
  word-break: break-word;
}
.stat .value.sm { font-size: 17px; }

.btn {
  border: 0; background: var(--primary); color: #fff;
  padding: 10px 15px; border-radius: 10px; cursor: pointer; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px; font-size: 15px;
}
.btn:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-warning { background: var(--warning); color: #1c2834; }
.btn-sm { padding: 6px 10px; font-size: 14px; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }

.input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--text);
  font-size: 16px; font-family: inherit;
}
.input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,107,147,.15);
}
.input.js-money, .input.num {
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
  text-align: left;
  direction: ltr;
}
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 700; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .input, .filters select { width: auto; min-width: 140px; }

.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
  padding: 10px 8px; border-bottom: 1px solid var(--border);
  text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.data th { font-size: 13px; color: var(--muted); font-weight: 700; }
table.data td.num, table.data th.num { text-align: left; direction: ltr; }

.badge { display: inline-flex; padding: 3px 8px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.badge-success { background: #e6f7ee; color: #0b7a42; }
.badge-warning { background: #fff6dc; color: #8a6a00; }
.badge-danger { background: #fdecea; color: #b3261e; }
.badge-info { background: #e8f1fd; color: #1558b0; }
.badge-muted { background: #eef2f5; color: #5d6d7e; }
[data-theme="dark"] .badge-success { background: #163528; color: #7dcea0; }
[data-theme="dark"] .badge-warning { background: #3a3114; color: #f0d078; }
[data-theme="dark"] .badge-danger { background: #3a1c1a; color: #f0a39c; }
[data-theme="dark"] .badge-info { background: #1a2a3d; color: #8eb7ef; }
[data-theme="dark"] .badge-muted { background: #24303a; color: #9aabba; }

.avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
}
.person { display: flex; align-items: center; gap: 10px; }

.tabs { display: flex; gap: 4px; overflow: auto; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab { padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; font-size: 15px; }
.tab.active { color: var(--primary); border-color: var(--primary); font-weight: 800; }

.alert { padding: 11px 13px; border-radius: 10px; margin-bottom: 12px; font-weight: 600; }
.alert-success { background: #e6f7ee; color: #0b7a42; }
.alert-error { background: #fdecea; color: #b3261e; }
.alert-warning { background: #fff6dc; color: #8a6a00; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.toast-wrap { position: fixed; top: 16px; left: 16px; z-index: 80; display: grid; gap: 8px; }
.toast { background: #113445; color: #fff; padding: 12px 16px; border-radius: 12px; min-width: 220px; }
.toast.ok { background: #0f9d58; }
.toast.err { background: #d93025; }

.overlay { position: fixed; inset: 0; background: rgba(10,20,28,.45); display: none; z-index: 60; }
.overlay.open { display: block; }
.modal {
  position: fixed; inset-inline: 0; top: 10vh; margin: auto;
  width: min(520px, calc(100% - 24px)); background: var(--surface);
  border-radius: 14px; z-index: 80; display: none; padding: 18px;
  box-shadow: var(--shadow);
}
.modal.open { display: block; }
.drawer {
  position: fixed; top: 0; bottom: 0; right: 0; width: min(420px, 100%);
  background: var(--surface); z-index: 80; display: none; overflow: auto;
  box-shadow: var(--shadow); padding: 18px;
}
.drawer.open { display: block; }

.bottom-nav {
  display: none; position: fixed; bottom: 0; inset-inline: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  height: var(--bottom-h); z-index: 40;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav a {
  display: grid; place-items: center; color: var(--muted);
  font-size: 12px; gap: 2px; font-weight: 600; padding-top: 6px;
}
.bottom-nav a .icon { opacity: .7; }
.bottom-nav a.active { color: var(--primary); font-weight: 800; }
.bottom-nav a.active .icon { opacity: 1; }
.fab {
  position: fixed; bottom: 78px; left: 16px; width: 52px; height: 52px;
  border-radius: 50%; background: var(--primary); color: #fff; border: 0;
  z-index: 31; display: none; box-shadow: var(--shadow);
  place-items: center;
}
.search-modal .results { display: grid; gap: 8px; max-height: 60vh; overflow: auto; }
.search-group { font-size: 13px; color: var(--muted); margin-top: 8px; }

.attn { display: grid; gap: 0; }
.attn a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 0; border-bottom: 1px solid var(--border); color: inherit;
  font-weight: 600; font-size: 15px;
}
.attn a:last-child { border-bottom: 0; }
.attn a span {
  color: var(--primary); font-size: 13px; font-weight: 800;
  background: var(--primary-soft); padding: 3px 8px; border-radius: 999px;
}
.quick { display: flex; gap: 8px; flex-wrap: wrap; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0d3b4f, #1B6B93); }
.login-card { width: min(420px, 100%); background: #fff; border-radius: 18px; padding: 28px; }
.stepper { display: flex; gap: 8px; margin-bottom: 16px; }
.step { flex: 1; height: 6px; background: var(--border); border-radius: 99px; }
.step.on { background: var(--primary); }
.attend-btn { border: 0; border-radius: 10px; padding: 8px 10px; cursor: pointer; font-weight: 800; }
.att-present { background: #e6f7ee; color: #0b7a42; }
.att-absent { background: #fdecea; color: #b3261e; }
.att-late { background: #fff6dc; color: #8a6a00; }
.att-excused { background: #e8f1fd; color: #1558b0; }
.mobile-card { display: none; }
.pag { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.menu-toggle { display: none; }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; font-size: 12px; color: var(--muted); }
.bar { width: 100%; max-width: 26px; background: var(--primary); border-radius: 7px 7px 0 0; }
.barcode { max-width: 100%; height: auto; display: block; margin: 8px 0; }

@media (max-width: 1100px) {
  .grid-6 { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 768px) {
  body.menu-open { overflow: hidden; }

  .sidebar {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(300px, 86vw);
    height: 100%;
    max-height: 100dvh;
    z-index: 70;
    padding: 14px 10px calc(18px + env(safe-area-inset-bottom, 0));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: -8px 0 28px rgba(0,0,0,.28);
  }
  .sidebar.open { display: block; }

  .menu-toggle { display: grid; }
  .bottom-nav { display: grid; }
  .fab {
    display: grid;
    bottom: calc(72px + env(safe-area-inset-bottom, 0));
    left: 14px;
    z-index: 45;
  }

  .topbar {
    padding: 8px 10px;
    gap: 8px;
    min-height: 56px;
  }
  .topbar-greet {
    font-size: 13px;
    max-width: min(46vw, 180px);
  }
  .topbar-role { display: none; }
  .topbar-actions { gap: 5px; }
  .topbar-actions .icon-btn { width: 36px; height: 36px; }
  .topbar-add {
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: 10px;
  }
  .topbar-add-label { display: none; }

  .content {
    padding: 12px 12px calc(88px + env(safe-area-inset-bottom, 0));
  }
  .page-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
  }
  .page-head h1 {
    font-size: 20px;
    line-height: 1.3;
    width: 100%;
  }
  .page-head .row,
  .page-head .quick {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .page-head .row .btn,
  .page-head .quick .btn,
  .quick .btn {
    justify-content: center;
    width: 100%;
  }
  .quick {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .grid-2, .grid-3, .grid-4, .grid-6 { grid-template-columns: 1fr; }
  .desktop-only { display: none !important; }
  .mobile-card { display: grid; gap: 10px; }

  .filters, .filters.card {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    align-items: stretch;
  }
  .filters .input,
  .filters select,
  .filters.card .field {
    width: 100%;
    min-width: 0;
    flex: none;
  }
  .filters .btn { width: 100%; justify-content: center; }

  .card { padding: 12px; }
  .stat .value { font-size: 20px; }
  table.data th, table.data td { font-size: 13px; padding: 8px 6px; }

  .nav-item, .nav-group summary, .nav-sub a {
    min-height: 44px;
    padding-top: 11px;
    padding-bottom: 11px;
  }
}
@media (max-width: 380px) {
  .topbar-actions #theme-toggle { display: none; }
  .bottom-nav a span { font-size: 11px; }
}
[data-theme="dark"] .login-card { background: var(--surface); color: var(--text); }
[data-theme="dark"] .login-card .brand { color: var(--text); }
[data-theme="dark"] .login-wrap { background: linear-gradient(160deg, #071820, #0d3b4f); }
.login-card .brand { color: var(--text); }
.hidden { display: none !important; }
.w-full { width: 100%; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.mb-0 { margin-bottom: 0; }

/* Reports */
.reports-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.reports-nav {
  padding: 10px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 100px);
  overflow: auto;
}
.reports-group { margin-bottom: 12px; }
.reports-group:last-child { margin-bottom: 0; }
.reports-group-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  padding: 6px 10px 8px;
  letter-spacing: .02em;
}
.reports-link {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
}
.reports-link:hover { background: var(--primary-soft); color: var(--primary); }
.reports-link.active {
  background: var(--primary);
  color: #fff;
}
.report-title { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.report-summary .stat.ok .value { color: var(--success); }
.report-summary .stat.warn .value { color: var(--warning); }
.report-summary .stat.bad .value { color: var(--danger); }
.report-table th { white-space: nowrap; }
.filters.card { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; padding: 12px 14px; }
.filters.card .field { min-width: 140px; flex: 1; }

@media (max-width: 900px) {
  .reports-layout { grid-template-columns: 1fr; }
  .reports-nav {
    position: static;
    max-height: none;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px;
  }
  .reports-group { display: contents; }
  .reports-group-title {
    flex: 0 0 100%;
    padding: 8px 4px 4px;
  }
  .reports-link { margin: 0; }
}

@media print {
  .reports-layout { display: block; }
  .reports-nav, .no-print, .sidebar, .topbar, .bottom-nav, .fab { display: none !important; }
  .reports-main { width: 100%; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
