:root {
  --navy: #0f2a44;
  --navy-2: #163a5c;
  --accent: #1f6feb;
  --accent-2: #e8f0fe;
  --ok: #12805c;
  --warn: #b26b00;
  --danger: #c62828;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #dfe4ea;
  --text: #1c2733;
  --muted: #6b7785;
  --yellow: #fff8d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; direction: rtl;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: embed; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff;
  color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; line-height: 1.4;
}
.btn:hover { background: #f7f9fb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a5fd0; }
.btn.danger { color: var(--danger); border-color: #f2c4c4; }
.btn.ok { color: var(--ok); border-color: #b7e2d2; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f > span { font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); border: 1px solid #c9d1da; border-radius: 7px; padding: 7px 10px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); border-color: var(--accent); }
input.key { background: var(--yellow); }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.check input { width: auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Cards & tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 14px; }
table.t { width: 100%; border-collapse: collapse; background: #fff; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
table.t th { background: #f0f3f7; font-weight: 600; font-size: 13px; color: #3b4855; position: sticky; top: 0; }
table.t tr.sel td { background: var(--accent-2); }
table.t tbody tr { cursor: default; }
table.t tbody tr.clickable { cursor: pointer; }
table.t tbody tr.clickable:hover td { background: #f6f9ff; }
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eef1f5; color: #3b4855; }
.badge.ok { background: #e3f5ee; color: var(--ok); }
.badge.off { background: #fdeaea; color: var(--danger); }
.badge.blue { background: var(--accent-2); color: var(--accent); }

/* Layout: app shell */
.shell { display: grid; grid-template-columns: 250px 1fr; grid-template-rows: 56px 1fr 30px; height: 100vh; }
.topbar {
  grid-column: 1 / -1; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 14px; padding: 0 16px;
}
.topbar .brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.topbar .brand img { height: 36px; border-radius: 6px; background: #fff; padding: 2px 6px; }
.topbar select { width: auto; background: var(--navy-2); color: #fff; border-color: #2d527a; }
.topbar .who { font-size: 13px; opacity: .9; }
.topbar .btn { background: transparent; color: #fff; border-color: #2d527a; }
.topbar .btn:hover { background: var(--navy-2); }
.side { background: #fff; border-left: 1px solid var(--line); overflow: auto; padding: 10px 8px; }
.side .grp { font-size: 12px; color: var(--muted); padding: 12px 10px 4px; font-weight: 600; }
.side a.item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 7px; color: var(--text); font-size: 13.5px;
}
.side a.item:hover { background: #f2f5f9; }
.side a.item.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.side a.item.soon { color: #9aa5b1; cursor: default; }
.side a.item.soon:hover { background: transparent; }
.side .soon-tag { font-size: 11px; background: #f1f3f6; color: #8a96a3; border-radius: 999px; padding: 1px 7px; }
.main { overflow: auto; padding: 18px 22px; }
.statusbar {
  grid-column: 1 / -1; background: #eef1f5; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted);
  display: flex; align-items: center; padding: 0 14px; gap: 18px;
}
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.page-head h1 { margin: 0; }

/* Split screen like the desktop app: list + form */
.split { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 14px; align-items: start; }
.listpane .tablewrap { max-height: calc(100vh - 230px); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button {
  border: 0; background: transparent; padding: 9px 14px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.actions { display: flex; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.permlist { max-height: calc(100vh - 330px); overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.permlist label { display: grid; grid-template-columns: 40px 1fr 30px; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid #eef1f4; cursor: pointer; }
.permlist label:hover { background: #f7f9fc; }
.permlist .n { color: var(--muted); font-size: 12px; text-align: center; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }

/* Auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #0f2a44 0%, #1d4c7a 60%, #2a6db0 100%); padding: 20px; }
.auth .box { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.auth .logo { text-align: center; margin-bottom: 18px; }
.auth .logo img { max-height: 110px; max-width: 100%; }
.auth .logo .name { font-size: 20px; font-weight: 700; margin-top: 6px; }
.auth .logo .sub { color: var(--muted); font-size: 13px; }
.auth form { display: grid; gap: 12px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* Landing */
.landing header { background: #fff; padding: 10px 28px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.landing header .logo img { height: 100px; display: block; }
.landing header .logo { font-size: 20px; font-weight: 700; }
.landing .hero { background: linear-gradient(160deg, #0f2a44, #2a6db0); color: #fff; padding: 70px 28px; text-align: center; }
.landing .hero h1 { font-size: 34px; margin-bottom: 12px; }
.landing .hero p { font-size: 17px; opacity: .9; max-width: 640px; margin: 0 auto 26px; }
.landing .go { display: flex; gap: 8px; justify-content: center; max-width: 480px; margin: 0 auto; direction: ltr; }
.landing .go input { direction: ltr; }
.landing .go .pre { background: rgba(255, 255, 255, .15); padding: 8px 10px; border-radius: 7px; white-space: nowrap; }
.landing .features { max-width: 1000px; margin: 40px auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 0 20px; }
.landing footer { text-align: center; color: var(--muted); padding: 30px; font-size: 13px; }

/* Modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 620px; max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal h2 { margin-bottom: 14px; }
.toast { position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%); background: #1c2733; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; font-size: 14px; }
.toast.err { background: var(--danger); }
.lock { position: fixed; inset: 0; z-index: 70; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr 30px; }
  .side { border-left: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .split, .g2, .g3, .g4, .stats, .landing .features { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .side, .statusbar, .actions, .no-print { display: none !important; }
  .shell { display: block; height: auto; }
}
.t tr.sel td { background: #e8f0fd; }
.auth .btn.primary { justify-content: center; text-align: center; }
