:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", "Dubai", Arial, sans-serif;
  font-family: var(--font);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; color: var(--text); background: var(--panel-2); font-family: var(--font); }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Auth screens ---------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 80% -10%, #334155 0%, #0b1220 55%);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 30px 32px 34px;
}
.auth-logo { display: block; width: 210px; max-width: 72%; margin: 2px auto 14px; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 4px 0 20px; text-align: center; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; background: #fff; color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
textarea { min-height: 74px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border: 1px solid transparent; border-radius: 10px;
  font-weight: 700; font-size: 14px; background: var(--primary); color: #fff;
  transition: background .15s, opacity .15s; font-family: inherit;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.success { background: var(--success); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 7px 11px; font-size: 13px; }

.msg { margin-top: 14px; font-size: 13px; padding: 10px 12px; border-radius: 10px; display: none; }
.msg.show { display: block; }
.msg.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.msg.ok { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }
.msg.info { background: #eff6ff; color: var(--primary-dark); border: 1px solid #bfdbfe; }

/* ---------- App shell (RTL: sidebar on the right) ---------- */
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg); color: #cbd5e1; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
}
.side-logo { width: 172px; max-width: 90%; margin: 4px auto 6px; display: block; }
.nav { margin-top: 16px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav a {
  color: #cbd5e1; padding: 10px 12px; border-radius: 9px; font-size: 14.5px; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
}
.nav a .ic { width: 22px; text-align: center; }
.nav a:hover { background: #1e293b; color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav .badge { margin-inline-start: auto; background: #ef4444; color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 999px; }
.nav-sep { font-size: 11px; letter-spacing: .04em; color: #64748b; margin: 14px 12px 4px; font-weight: 700; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: #64748b; padding: 10px 12px; text-align: center; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 39; }
.sidebar-overlay.show { display: block; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 62px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 22px; position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-size: 16px; font-weight: 800; }
.topbar .spacer { flex: 1; }
.bell { position: relative; background: none; border: none; font-size: 20px; padding: 6px; border-radius: 8px; }
.bell:hover { background: var(--panel-2); }
.bell .dot { position: absolute; top: 2px; inset-inline-end: 2px; width: 9px; height: 9px; background: #ef4444; border-radius: 50%; border: 2px solid #fff; display: none; }
.bell .dot.show { display: block; }
.bell .count { position: absolute; top: -2px; inset-inline-end: -2px; min-width: 18px; height: 18px; padding: 0 4px; background: #ef4444; color: #fff; border-radius: 999px; border: 2px solid #fff; font-size: 11px; font-weight: 700; line-height: 14px; text-align: center; display: none; }
.bell .count.show { display: inline-block; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 5px 8px; border-radius: 999px; cursor: pointer; }
.user-chip:hover { background: var(--panel-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg,#2563eb,#7c3aed); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; object-fit: cover; overflow: hidden; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.xl { width: 92px; height: 92px; font-size: 30px; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.profile-pic { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
table.kv { min-width: 0; }
table.kv th { width: 180px; background: transparent; color: var(--muted); font-weight: 700; }
table.kv td { font-weight: 600; }
.user-meta .u-name { font-size: 13px; font-weight: 700; }
.user-meta .u-role { font-size: 11px; color: var(--muted); }
.content { padding: 24px; max-width: 1120px; width: 100%; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat .num { font-size: 30px; font-weight: 800; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }
.section-title { font-size: 15px; font-weight: 800; margin: 26px 0 12px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 800; display: flex; align-items: center; gap: 10px; }
.panel-body { padding: 18px; }
.notif-line { padding: 8px 0; border-bottom: 1px solid var(--border); }
.notif-line:last-child { border-bottom: none; }

/* ---------- Toolbar & filters ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-inline-start: auto; }
.filters input, .filters select { width: auto; padding: 8px 10px; font-size: 13px; }
.filters .f-search { min-width: 240px; }
.filters .f-date { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; margin: 0; }
.filters .f-date input { padding: 7px 9px; }
.panel-head .btn.sm { font-weight: 600; }

/* ---------- Tables (scroll on small screens) ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
th, td { text-align: start; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; letter-spacing: .02em; color: var(--muted); background: var(--panel-2); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.tag.pending { background: #fef9c3; color: #854d0e; }
.tag.approved { background: #dcfce7; color: #166534; }
.tag.rejected { background: #fee2e2; color: #991b1b; }
.tag.cancelled, .tag.not_ready { background: #e2e8f0; color: #475569; }
.tag.l1_approved { background: #e0e7ff; color: #3730a3; }
.tag.assigned { background: #dbeafe; color: #1e40af; }
.tag.acknowledged { background: #e0e7ff; color: #3730a3; }
.tag.role { background: #f1f5f9; color: #334155; }
.tag.admin { background: #fae8ff; color: #86198f; }
.tag.director { background: #fef3c7; color: #92400e; }
/* ticket status */
.tag.ts-open { background: #dbeafe; color: #1e40af; }
.tag.ts-in_progress { background: #e0e7ff; color: #3730a3; }
.tag.ts-on_hold { background: #fef9c3; color: #854d0e; }
.tag.ts-resolved { background: #dcfce7; color: #166534; }
.tag.ts-closed { background: #e2e8f0; color: #475569; }
/* ticket priority */
.tag.tp-low { background: #e2e8f0; color: #475569; }
.tag.tp-medium { background: #dbeafe; color: #1e40af; }
.tag.tp-high { background: #ffedd5; color: #9a3412; }
.tag.tp-urgent { background: #fee2e2; color: #991b1b; }

/* ticket detail */
.tk-meta { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.tk-manage { margin-top: 12px; padding: 12px; border: 1px dashed var(--border); border-radius: 10px; }
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; padding: 4px; margin-bottom: 12px; }
.bubble { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.bubble.internal { background: #fffbeb; border-color: #fde68a; }
.bubble-head { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.bubble-time { margin-inline-start: auto; color: #94a3b8; font-size: 11px; }
.bubble-body { margin-top: 4px; font-size: 14px; white-space: pre-wrap; }
/* leave balances */
.bal-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.bal-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.bal-card .v { font-size: 26px; font-weight: 800; }
.bal-card .u { color: var(--muted); font-size: 12px; }
.bal-card .n { font-weight: 700; margin-bottom: 6px; }
.picker-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
/* calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { font-weight: 700; font-size: 12px; color: var(--muted); text-align: center; padding: 6px 0; }
.cal-cell { min-height: 96px; border: 1px solid var(--border); border-radius: 8px; padding: 6px; background: #fff; }
.cal-cell.weekend { background: #f1f5f9; }
.cal-cell.blank { border: none; background: transparent; }
.cal-day { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.cal-chip { font-size: 11px; border-radius: 6px; padding: 2px 6px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-more { font-size: 11px; color: var(--muted); }
@media (max-width: 640px) { .cal-cell { min-height: 66px; padding: 3px; } .cal-chip { font-size: 10px; } .cal-head { font-size: 10px; } }
/* analytics */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.chart { display: flex; flex-direction: column; gap: 8px; }
.chart-row { display: grid; grid-template-columns: 130px 1fr 44px; align-items: center; gap: 8px; }
.chart-label { font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-track { background: var(--panel-2); border-radius: 6px; height: 16px; overflow: hidden; }
.chart-bar { height: 100%; border-radius: 6px; min-width: 2px; transition: width .3s; }
.chart-val { font-size: 12px; font-weight: 700; text-align: start; }
@media (max-width: 520px) { .chart-row { grid-template-columns: 100px 1fr 38px; } }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: none; place-items: center; z-index: 50; padding: 20px; }
.modal-backdrop.show { display: grid; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); font-weight: 800; font-size: 16px; display: flex; align-items: center; }
.modal-head .x { margin-inline-start: auto; background: none; border: none; font-size: 22px; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Notifications drawer (RTL: bell sits on the left, drawer slides from the left) ---------- */
.drawer { position: fixed; top: 0; left: 0; right: auto; height: 100vh; width: min(360px, 90vw); background: #fff; box-shadow: 8px 0 30px rgba(0,0,0,.15); transform: translateX(-100%); transition: transform .2s; z-index: 60; display: flex; flex-direction: column; }
.drawer.show { transform: translateX(0); }
.drawer-head { padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 800; display: flex; align-items: center; }
.drawer-body { overflow-y: auto; flex: 1; }
.notif { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.notif.unread { background: #eff6ff; }
.notif .t { font-weight: 700; font-size: 14px; }
.notif .b { color: var(--muted); font-size: 13px; margin-top: 3px; }
.notif .time { color: #94a3b8; font-size: 11px; margin-top: 4px; }
.notif.clickable { cursor: pointer; transition: background .12s; position: relative; }
.notif.clickable:hover { background: #f1f5f9; }
.notif.clickable.unread:hover { background: #dbeafe; }
.notif .notif-go { color: var(--primary); font-weight: 700; margin-inline-start: 8px; }

.checks { display: grid; gap: 8px; margin-top: 8px; }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.check input { width: auto; margin-top: 3px; flex: none; }
.check .c-label { font-weight: 700; font-size: 14px; }
.check .c-desc { color: var(--muted); font-size: 12px; }
.priv-group { margin-bottom: 14px; }
.priv-group-title { font-weight: 800; font-size: 13px; color: var(--primary-dark); margin: 6px 0; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.muted { color: var(--muted); }
.pill-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.qr { display: block; margin: 12px auto; width: 190px; height: 190px; border: 1px solid var(--border); border-radius: 10px; }
.code { font-family: ui-monospace, Menlo, monospace; background: var(--panel-2); padding: 6px 10px; border-radius: 8px; font-size: 13px; word-break: break-all; display: inline-block; }
.hidden { display: none !important; }
.inline-form { display: flex; gap: 8px; align-items: center; }

/* ---------- Responsive ---------- */
.menu-toggle { display: none; background: none; border: none; font-size: 22px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed; z-index: 40; height: 100vh; width: 264px;
    top: 0; right: 0; left: auto;                          /* anchored to the physical right for RTL */
    transform: translateX(100%); transition: transform .22s ease;
  }
  .sidebar.show { transform: translateX(0); }
  .content { padding: 16px; }
}

@media (max-width: 560px) {
  .row { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px 26px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .user-meta { display: none; }
  .content { padding: 13px; }
  .section-title { margin: 20px 0 10px; }
  .stat .num { font-size: 26px; }
  .modal-foot { justify-content: stretch; }
  .modal-foot .btn { flex: 1; }
  .filters { width: 100%; margin-inline-start: 0; }
  .filters .f-search { min-width: 0; flex: 1 1 100%; }
  .panel-head { flex-wrap: wrap; }
}

/* ---------- Broadcasts (admin cards + acknowledgment detail) ---------- */
.check-line { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; font-size: 14px; color: var(--text); cursor: pointer; }
.check-line input { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.bc-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; background: var(--panel-2); }
.bc-card.stopped { opacity: .7; }
.bc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.bc-title { font-weight: 700; font-size: 15px; }
.bc-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.bc-body-txt { margin: 8px 0 12px; color: var(--text); white-space: pre-wrap; line-height: 1.6; }
.bc-progress { margin-bottom: 12px; }
.bc-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.bc-bar span { display: block; height: 100%; background: var(--success); border-radius: 999px; transition: width .3s; }
.bc-count { font-size: 12px; color: var(--muted); margin-top: 4px; }
.bc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ack-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.ack-cols h4 { margin: 0 0 8px; font-size: 14px; }
.ack-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.ack-row .time { color: var(--muted); font-size: 12px; }
.empty.sm { padding: 8px 0; font-size: 13px; }
@media (max-width: 640px) { .ack-cols { grid-template-columns: 1fr; } }

/* ---------- Broadcast login gate (blocking popup) ---------- */
.bc-gate {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 23, 42, .72);
  display: grid; place-items: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.bc-gate-box {
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  background: var(--panel); border-radius: 18px; box-shadow: var(--shadow);
  padding: 26px 28px 24px; animation: gate-in .18s ease-out;
}
@keyframes gate-in { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.bc-gate-head { font-size: 13px; font-weight: 700; color: var(--primary); letter-spacing: .3px; }
.bc-gate-title { font-size: 20px; font-weight: 800; margin: 8px 0 12px; }
.bc-gate-body { line-height: 1.8; color: var(--text); margin-bottom: 8px; }
.bc-gate .gate-check {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; align-items: flex-start; line-height: 1.5;
}
.bc-gate-foot { margin-top: 16px; }
.bc-gate-foot .btn { width: 100%; padding: 12px; font-size: 15px; }

/* ---------- Paged tables ("show more") ---------- */
.more-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; flex-wrap: wrap; }
.more-bar .muted { font-size: 13px; }
.more-bar .btn { margin-inline-start: auto; }

/* ---------- Leave-form remaining balance hint ---------- */
.bal-hint { margin: 8px 0 0; padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.bal-hint.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.bal-hint.low { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
