:root {
  --primary: #ad1d37; --primary-dark: #8a1629; --primary-light: #fbe9ec; --accent: #213467; --navy: #213467;
  --bg: #f4f5f7; --card: #fff; --border: #e3e6ea; --text: #23272b; --muted: #6c757d;
  --success: #28a745; --warning: #ffc107; --danger: #dc3545; --info: #17a2b8;
  --radius: 8px; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.04);
  --font: 'Inter', 'Segoe UI', Tahoma, sans-serif;
}
html[dir=rtl] { --font: 'Cairo', 'Segoe UI', Tahoma, sans-serif; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 13.5px; color: var(--text); background: var(--bg); min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85em; } .center { text-align: center; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.mono { font-family: Consolas, monospace; }
[hidden] { display: none !important; }
.flex { display: flex; gap: .5rem; align-items: center; } .flex-wrap { flex-wrap: wrap; } .grow { flex: 1; } .space { justify-content: space-between; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; } .ml-auto { margin-inline-start: auto; }
.grid { display: grid; gap: 1rem; } .grid-2 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: .75rem; height: 56px; padding: 0 .9rem; background: #fff; border-bottom: 3px solid var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--primary); font-size: 1rem; white-space: nowrap; flex-shrink: 0; }
@media (max-width: 1250px) { .brand #brandName { display: none; } }
.brand:hover { text-decoration: none; }
.logo-badge { width: 54px; height: 54px; border-radius: 14px; background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 1.6rem; margin: 0 auto .6rem; }
.brand-logo { height: 40px; width: auto; }
.login-logo { max-width: 280px; height: auto; margin: 0 auto .5rem; display: block; }
.brand .brand-ar { font-family: 'Cairo', sans-serif; font-size: .8rem; color: var(--navy); display: block; line-height: 1; }
.logo-badge.small { width: 30px; height: 30px; border-radius: 8px; font-size: .95rem; margin: 0; }
.modules { display: flex; gap: .1rem; flex: 1; min-width: 0; overflow: hidden; align-items: center; }
.modules a { padding: .45rem clamp(.35rem, .6vw, .7rem); border-radius: 6px; color: var(--text); font-weight: 500; white-space: nowrap; font-size: clamp(.8rem, .85vw, .95rem); }
.nav-more { position: relative; }
.nav-more > a { padding: .45rem .6rem; border-radius: 6px; color: var(--primary); font-weight: 700; }
.nav-more-list { display: none; position: absolute; top: 110%; inset-inline-start: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 170px; padding: .3rem; z-index: 60; }
.nav-more.open .nav-more-list { display: block; }
.nav-more-list a { display: block; padding: .5rem .7rem; }
.nav-more-list a:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.modules a:hover, .modules a.active { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); }
.stat i { color: var(--primary); }
.megamenu .group h4 i { background: var(--navy); }
.section-title, .page-head h1 { color: var(--navy); }
.topbar-right { display: flex; align-items: center; gap: .5rem; margin-inline-start: auto; }
.global-search { display: flex; align-items: center; gap: .4rem; background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: .3rem .7rem; color: var(--muted); }
.global-search input { border: 0; background: transparent; outline: 0; width: clamp(90px, 11vw, 190px); font: inherit; }
.icon-btn { border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: .35rem .6rem; cursor: pointer; font: inherit; font-weight: 600; color: var(--primary); }
.icon-btn:hover { background: var(--primary-light); }
.nav-toggle { display: none; border: 0; background: transparent; font-size: 1.2rem; cursor: pointer; }
.user-menu { position: relative; display: flex; align-items: center; gap: .4rem; cursor: pointer; padding: .3rem .5rem; border-radius: 6px; font-weight: 500; }
.user-menu:hover { background: var(--bg); }
.user-menu .fa-circle-user { font-size: 1.4rem; color: var(--muted); }
.dropdown { display: none; position: absolute; top: 110%; inset-inline-end: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 190px; padding: .3rem; z-index: 60; }
.dropdown a { display: block; padding: .5rem .7rem; color: var(--text); border-radius: 6px; }
.dropdown a:hover { background: var(--bg); text-decoration: none; }
.user-menu.open .dropdown { display: block; }
@media (max-width: 1000px) { .global-search { display: none; } .nav-toggle { display: block; } .modules { display: none; position: absolute; top: 56px; left: 0; right: 0; background: #fff; flex-direction: column; align-items: stretch; padding: .5rem; box-shadow: var(--shadow); overflow: visible; } .modules.open { display: flex; } .modules a { font-size: .95rem; padding: .6rem .8rem; } .nav-more { display: none; } .brand #brandName { display: inline; } }

/* ---------- mega menu ---------- */
.megamenu { position: fixed; top: 55px; left: 50%; transform: translateX(-50%); width: min(1100px, 96vw); max-height: calc(100vh - 80px); overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.18); padding: 1rem 1.25rem; z-index: 55; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem 1.5rem; }
.megamenu .group h4 { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: .35rem; margin-bottom: .35rem; }
.megamenu .group h4 i { width: 26px; height: 26px; border-radius: 50%; background: var(--navy); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .7rem; }
.megamenu .group a { display: block; padding: .22rem .3rem .22rem 2.1rem; color: var(--primary); font-size: .86rem; border-radius: 4px; }
html[dir=rtl] .megamenu .group a { padding: .22rem 2.1rem .22rem .3rem; }
.megamenu .group a:hover { background: var(--primary-light); text-decoration: none; }
.megamenu-backdrop { position: fixed; inset: 0; z-index: 54; }

.breadcrumb { padding: .55rem 1.2rem 0; color: var(--primary); font-size: .85rem; display: flex; gap: .4rem; align-items: center; }
.breadcrumb a { color: var(--primary); }
.breadcrumb .sep { color: var(--muted); }
.main { padding: .75rem 1.2rem 2rem; }

/* ---------- cards / panels ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.card-title h2, .card-title h3 { margin: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: .5rem; color: var(--navy); }
.page-head h1 i { font-size: 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .6rem; }
.actions-bar { display: flex; flex-wrap: wrap; gap: .35rem; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--border); background: #fff; color: var(--text); padding: .42rem .8rem; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 500; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-sm { padding: .25rem .5rem; font-size: .82rem; }
.btn-xs { padding: .12rem .4rem; font-size: .78rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-link { border: 0; background: none; color: var(--primary); padding: .2rem .3rem; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-start-start-radius: 6px; border-end-start-radius: 6px; }
.btn-group .btn:last-child { border-start-end-radius: 6px; border-end-end-radius: 6px; }

/* ---------- forms ---------- */
.input, select.input, textarea.input { width: 100%; border: 1px solid #ccd1d6; border-radius: 6px; padding: .42rem .6rem; font: inherit; background: #fff; color: var(--text); }
.input:focus { outline: 2px solid rgba(155,28,58,.25); border-color: var(--primary); }
.input[readonly] { background: #f7f8fa; color: var(--muted); }
textarea.input { min-height: 70px; resize: vertical; }
label { display: block; font-size: .82rem; font-weight: 600; color: #444; margin: .5rem 0 .25rem; }
label .req { color: var(--danger); margin-inline-start: 2px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .25rem .9rem; }
.form-grid .field-textarea, .form-grid .field-json, .form-grid .field-perms, .form-grid .span-2 { grid-column: 1 / -1; }
.form-grid .field-textarea:not(.wide) { grid-column: span 2; }
@media (max-width: 700px) { .form-grid .field-textarea:not(.wide) { grid-column: 1 / -1; } }
.check { display: flex; align-items: center; gap: .4rem; margin-top: 1.55rem; font-weight: 500; }
.check input { width: 16px; height: 16px; }
.form-footer { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--border); padding: .6rem 0 0; margin-top: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.error-box { background: #fdecef; color: #8a1c1c; border: 1px solid #f5c2c7; padding: .5rem .7rem; border-radius: 6px; margin: .5rem 0; }
.hint { color: var(--muted); font-size: .78rem; }
.login-body { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #fff5f3 0%, #eef1f8 100%); }
.login-card { width: 380px; max-width: 94vw; background: #fff; border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.12); padding: 2rem; }
.login-brand { text-align: center; margin-bottom: 1rem; }
.login-brand h1 { color: var(--primary); }

/* tabs */
.tabs { display: flex; flex-wrap: wrap; gap: .15rem; border-bottom: 2px solid var(--border); margin-bottom: .75rem; }
.tabs button { border: 0; background: transparent; padding: .5rem .8rem; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 500; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs button:hover { color: var(--primary); }
.tab-pane { display: none; } .tab-pane.active { display: block; }

/* lookup (searchable select) */
.lookup { position: relative; }
.lookup .lookup-input { padding-inline-end: 3.2rem; }
.lookup .lookup-tools { position: absolute; top: 0; bottom: 0; inset-inline-end: .4rem; display: flex; align-items: center; gap: .2rem; color: var(--muted); }
.lookup .lookup-tools span { cursor: pointer; padding: 0 .2rem; }
.lookup .lookup-list { position: absolute; z-index: 40; top: 100%; left: 0; right: 0; max-height: 240px; overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); display: none; }
.lookup .lookup-list.open { display: block; }
.lookup .lookup-list div { padding: .4rem .6rem; cursor: pointer; }
.lookup .lookup-list div:hover, .lookup .lookup-list div.hl { background: var(--primary-light); }
.lookup .lookup-list .empty { color: var(--muted); cursor: default; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid #eef0f2; text-align: start; vertical-align: middle; }
.table th { background: #fafbfc; font-weight: 600; color: #444; white-space: nowrap; position: sticky; top: 0; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--primary); }
.table tbody tr:hover { background: #fcf6f7; }
.table td.num, .table th.num { text-align: end; font-variant-numeric: tabular-nums; }
.table tr.total td { font-weight: 700; background: #fafbfc; }
.table .row-actions { white-space: nowrap; text-align: end; }
.table .row-actions .btn { padding: .15rem .35rem; margin-inline-start: 2px; }
.table td a.rowlink { font-weight: 500; }
.table input.cell, .table select.cell { width: 100%; min-width: 60px; border: 1px solid #dde1e5; border-radius: 4px; padding: .25rem .4rem; font: inherit; }
.table-sm th, .table-sm td { padding: .3rem .45rem; }
.pager { display: flex; align-items: center; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.pager .btn { padding: .25rem .55rem; }
.thumb { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #eee; }
.avatar-lg { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; background: #eee; }
.avatar-ph { display: inline-flex; align-items: center; justify-content: center; color: #bbb; }

/* badges / chips */
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 12px; font-size: .76rem; font-weight: 600; background: #eef0f2; color: #444; white-space: nowrap; }
.badge-success { background: #e6f5ea; color: #1e7b34; } .badge-danger { background: #fdecef; color: #a32036; } .badge-warning { background: #fff5d6; color: #8a6400; } .badge-info { background: #e2f4f7; color: #0f6674; } .badge-primary { background: var(--primary-light); color: var(--primary); } .badge-muted { background: #eef0f2; color: #6c757d; }
.chip { display: inline-flex; align-items: center; gap: .35rem; background: #fff; border: 1px solid var(--border); border-radius: 4px; padding: .28rem .55rem; font-size: .82rem; font-weight: 600; }
.chip b { color: var(--primary); }
.chip .x { cursor: pointer; color: var(--danger); }
.filter-panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .9rem .9rem; margin-bottom: .6rem; }
.search-box { display: flex; align-items: center; border: 1px solid #ccd1d6; border-radius: 6px; background: #fff; overflow: hidden; }
.search-box input { border: 0; padding: .42rem .6rem; font: inherit; width: 240px; outline: 0; }
.search-box button { border: 0; background: var(--primary); color: #fff; padding: .45rem .7rem; cursor: pointer; }

/* dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem; display: flex; align-items: center; gap: .8rem; box-shadow: var(--shadow); }
.stat i { width: 42px; height: 42px; border-radius: 10px; background: var(--primary-light); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.stat .v { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .8rem; }
.stat.c-green i { background: #e6f5ea; color: #1e7b34; } .stat.c-red i { background: #fdecef; color: #a32036; } .stat.c-blue i { background: #e2f4f7; color: #0f6674; } .stat.c-amber i { background: #fff5d6; color: #8a6400; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.tile { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: .9rem .5rem; text-align: center; color: var(--text); font-size: .82rem; font-weight: 500; }
.tile i { display: block; font-size: 1.5rem; color: var(--primary); margin-bottom: .45rem; }
.tile:hover { border-color: var(--primary); text-decoration: none; background: #fffafb; }
.section-title { color: var(--primary); font-weight: 600; margin: 1rem 0 .5rem; display: flex; align-items: center; gap: .4rem; }
.chart-box { position: relative; height: 240px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: .4rem 0; border-bottom: 1px solid #f0f1f3; display: flex; gap: .5rem; align-items: center; }
.list-plain li:last-child { border: 0; }

/* timetable & sheets */
.tt-grid td { min-width: 130px; height: 62px; vertical-align: top; }
.tt-cell { font-size: .78rem; line-height: 1.25; }
.tt-cell b { display: block; color: var(--primary); }
.tt-cell select { width: 100%; font-size: .78rem; }
.status-btns { display: flex; gap: .2rem; flex-wrap: wrap; }
.status-btns button { border: 1px solid var(--border); background: #fff; border-radius: 4px; padding: .2rem .45rem; font: inherit; font-size: .78rem; cursor: pointer; font-weight: 600; }
.status-btns button.on { color: #fff; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; font-size: .88rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; }
.split { display: grid; grid-template-columns: 340px 1fr; gap: 1rem; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.side-list { max-height: 70vh; overflow: auto; }
.side-list .item { padding: .5rem .6rem; border-bottom: 1px solid #f0f1f3; cursor: pointer; display: flex; justify-content: space-between; gap: .5rem; }
.side-list .item:hover, .side-list .item.active { background: var(--primary-light); }
.side-list .item .sub { color: var(--muted); font-size: .78rem; }
.profile-head { display: flex; gap: 1.2rem; align-items: center; }
.profile-head h1 { margin: 0; }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; }
.totals div { background: #fafbfc; border: 1px solid var(--border); border-radius: 6px; padding: .5rem .6rem; }
.totals .l { color: var(--muted); font-size: .76rem; } .totals .v { font-weight: 700; font-size: 1.05rem; }
.print-only { display: none; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .3rem; }

/* toasts / modal */
.toasts { position: fixed; bottom: 1rem; inset-inline-end: 1rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: #23272b; color: #fff; padding: .6rem .9rem; border-radius: 8px; box-shadow: var(--shadow); min-width: 220px; animation: fade .2s; }
.toast.ok { background: #1e7b34; } .toast.err { background: #a32036; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90; display: flex; align-items: flex-start; justify-content: center; padding: 3rem 1rem; overflow: auto; }
.modal { background: #fff; border-radius: 10px; width: min(900px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: fade .15s; }
.modal.sm { width: min(480px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 1rem; max-height: 70vh; overflow: auto; }
.modal-foot { padding: .7rem 1rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; justify-content: flex-end; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid #eee; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 2rem; text-align: center; color: var(--muted); }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }
.progress { height: 8px; background: #eef0f2; border-radius: 4px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--primary); }

@media print {
  .topbar, .breadcrumb, .megamenu, .toasts, .no-print, .form-footer, .toolbar { display: none !important; }
  .main { padding: 0; } .card { box-shadow: none; border: 0; }
  .print-only { display: block; }
  body { background: #fff; }
}
