:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --pri: #1e40af; --pri-2: #1d4ed8; --danger: #b91c1c; --warn: #b45309; --ok: #15803d;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.center { text-align: center; justify-content: center; }
.loading { padding: 80px; text-align: center; color: var(--muted); }

/* ===== الشريط العلوي ===== */
.demo-bar { background: #fef3c7; color: #78350f; padding: 6px 16px; font-size: 13px; text-align: center; }
.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 20px; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; }
.brand small { color: var(--muted); display: block; }
.logo { width: 38px; height: 38px; border-radius: 9px; background: var(--pri); color: #fff; display: grid; place-items: center; font-size: 20px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav button { background: none; border: 0; padding: 8px 14px; border-radius: 8px; color: var(--muted); font-weight: 500; position: relative; }
.nav button.on { background: #eef2ff; color: var(--pri); font-weight: 700; }
.badge { background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; margin-inline-start: 6px; }
.user { display: flex; align-items: center; gap: 8px; }

main { padding: 18px 20px 60px; max-width: 1400px; margin: 0 auto; }

/* ===== عناصر عامة ===== */
.btn { background: var(--pri); color: #fff; border: 1px solid var(--pri); border-radius: 8px; padding: 8px 16px; font-weight: 500; }
.btn:hover { background: var(--pri-2); }
.btn.ghost { background: #fff; color: var(--pri); border-color: #c7d2fe; }
.btn.ghost:hover { background: #eef2ff; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--pri); text-decoration: underline; padding: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: color-mix(in srgb, var(--c) 12%, #fff); color: color-mix(in srgb, var(--c) 80%, #000); border: 1px solid color-mix(in srgb, var(--c) 35%, #fff); padding: 1px 10px; border-radius: 99px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--r); }
.count { background: #eef2ff; color: var(--pri); border-radius: 99px; font-size: 13px; padding: 0 9px; margin-inline-start: 6px; }
.page-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-h h2 { font-size: 20px; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.box h2 { font-size: 16px; margin-bottom: 12px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
select, input, textarea { border: 1px solid #d1d5db; border-radius: 8px; padding: 6px 10px; background: #fff; }
input:disabled { background: #f3f4f6; color: #374151; }

/* ===== شريط أدوات الجدول ===== */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; background: #e5e7eb; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 8px; color: #4b5563; font-weight: 500; display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.seg button small { font-weight: 400; color: var(--muted); }
.seg button.on { background: #fff; color: var(--pri); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 700; }
.seg.shift button { padding: 6px 20px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.days > button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 16px; }
.days > button.on { background: var(--pri); border-color: var(--pri); color: #fff; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; font-size: 13px; color: #4b5563; margin-bottom: 10px; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg .sw.free { background: #fff; border: 1px solid #d1d5db; }
.lg .sw.pend { background: #fff; border: 2px dashed #6b7280; }
.lg .sw.loan { background: linear-gradient(135deg, #86efac 0 50%, #93c5fd 50% 100%); }
.legend .sep { width: 1px; height: 16px; background: #d1d5db; }

/* ===== الجدول ===== */
.grid-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 860px; table-layout: fixed; }
.grid th, .grid td { border-bottom: 1px solid var(--line); border-inline-start: 1px solid var(--line); padding: 3px; vertical-align: middle; }
.grid thead th { background: #f9fafb; font-weight: 500; padding: 6px; text-align: center; }
.grid thead th b { display: block; }
.grid thead th small { color: var(--muted); }
.grid .sticky { position: sticky; inset-inline-start: 0; background: #fff; z-index: 2; width: 170px; }
.grid thead .sticky { background: #f9fafb; }
.room-h button { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; text-align: start; padding: 4px; border-radius: 6px; }
.room-h button:hover { background: #f3f4f6; }
.room-h b { display: block; font-size: 14px; }
.room-h small { color: var(--muted); }
.day-h { font-weight: 700; padding: 6px; display: block; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
td.free button { width: 100%; height: 54px; border: 1px dashed transparent; background: none; border-radius: 6px; color: #9ca3af; font-size: 13px; }
td.free button:hover { border-color: #93c5fd; background: #eff6ff; color: var(--pri); }
td.free.ro { height: 60px; }
td.bk button { width: 100%; min-height: 54px; border: 0; border-radius: 6px; padding: 5px 8px; text-align: start; display: flex; flex-direction: column; gap: 1px; justify-content: center; overflow: hidden; }
td.bk button:hover { filter: brightness(0.96); outline: 2px solid rgba(0,0,0,.12); }
td.bk b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td.bk small { color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 12px; font-weight: 700; color: color-mix(in srgb, var(--c, #92400e) 80%, #000); line-height: 1.3; }
.tag.warn { color: var(--warn); background: #fef3c7; border-radius: 4px; padding: 0 5px; width: fit-content; }

/* ===== النوافذ ===== */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(560px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-h h3 { font-size: 17px; }
.x { border: 0; background: none; font-size: 24px; color: var(--muted); line-height: 1; }
.modal-b { padding: 16px 18px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #374151; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.note { border-inline-start: 4px solid var(--c); background: color-mix(in srgb, var(--c) 8%, #fff); padding: 8px 12px; border-radius: 6px; font-size: 13.5px; }
dl.info { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0 0 8px; }
dl.info dt { color: var(--muted); font-size: 13.5px; }
dl.info dd { margin: 0; }
.warn-t { color: var(--warn); }
.bar { height: 7px; background: #f3f4f6; border-radius: 99px; overflow: hidden; margin: 6px 0 2px; }
.bar span { display: block; height: 100%; border-radius: 99px; }

/* ===== الطلبات ===== */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: grid; grid-template-columns: 1.3fr 1.2fr auto; gap: 12px; align-items: center; text-align: start; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.item:hover { border-color: #a5b4fc; }
.item small { display: block; color: var(--muted); }
.status { font-size: 12.5px; padding: 2px 10px; border-radius: 99px; white-space: nowrap; font-weight: 500; }
.status.pending { background: #fef3c7; color: #92400e; }
.status.active { background: #dcfce7; color: #166534; }
.status.rejected, .status.cancelled { background: #fee2e2; color: #991b1b; }
.status.expired, .status.returned { background: #f3f4f6; color: #4b5563; }
.status.return { background: #ffedd5; color: #9a3412; }

/* ===== القاعات ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.room-card { background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.room-card.off { opacity: .55; }
.room-card header { display: flex; justify-content: space-between; }
.room-card .cap span { font-size: 26px; font-weight: 700; }
.room-card footer { display: flex; gap: 6px; margin-top: 4px; }

/* ===== الإدارة ===== */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: start; color: var(--muted); font-weight: 500; font-size: 13px; padding: 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 5px 6px; border-bottom: 1px solid #f3f4f6; }
.tbl .in { width: 100%; }
.tbl input[type=color] { width: 44px; height: 32px; padding: 2px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; color: var(--muted); }

/* ===== الدخول ===== */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(440px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.06); }
.login hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
.accounts { display: flex; flex-direction: column; gap: 6px; }
.acct { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; text-align: start; }
.acct:hover { border-color: var(--c); background: color-mix(in srgb, var(--c) 6%, #fff); }
.acct i { width: 12px; height: 34px; border-radius: 4px; background: var(--c); }
.acct small { display: block; color: var(--muted); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120px); background: #111827; color: #fff; padding: 10px 18px; border-radius: 10px; transition: transform .25s, opacity .25s; z-index: 100; max-width: 90vw; opacity: 0; pointer-events: none; }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.error { background: var(--danger); }

@media (max-width: 720px) {
  .topbar { padding: 8px 12px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 12px; }
  .row2 { grid-template-columns: 1fr; }
  .item { grid-template-columns: 1fr; }
  dl.info { grid-template-columns: 1fr; gap: 2px; }
  dl.info dd { margin-bottom: 8px; }
  .grid .sticky { width: 120px; }
}
@media print {
  .topbar, .demo-bar, .toolbar .seg:not(.shift), td.free button { display: none !important; }
  .grid-wrap { overflow: visible; border: 0; }
}
