:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --border: #e3e6eb;
  --text: #1c2430; --muted: #6b7584; --accent: #1f6feb; --accent-ink: #ffffff;
  --accent-soft: #e8f0fe; --ok: #1a7f4b; --ok-soft: #e4f5ec; --warn: #b4540a; --warn-soft: #fdf0e2;
  --err: #c0322b; --err-soft: #fdeaea; --info-soft: #eef2f7;
  --cam: #7c4dff; --pc: #0f8b8d; --other: #8a6d3b; --free: #eceff3;
  --side: #121a26; --side-ink: #c8d0dc; --side-active: #1f6feb;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171e28; --surface-2: #1c2531; --border: #2a3441;
    --text: #e6eaf0; --muted: #94a0b1; --accent: #4b8cf5; --accent-soft: #1b2a44;
    --ok: #4cc386; --ok-soft: #133024; --warn: #f0a04b; --warn-soft: #33240f;
    --err: #f07a72; --err-soft: #3a1c1b; --info-soft: #1c2531; --free: #222c38;
    --side: #0b1017;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif; font-size: 15px; line-height: 1.6;
  background: var(--bg); color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; font-weight: 400; }
.strong { font-weight: 700; }
.err { color: var(--err); }

/* القائمة الجانبية */
.side {
  position: fixed; inset: 0 0 0 auto; width: 230px; background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; z-index: 20; transition: transform .2s;
}
.side .brand { font-weight: 700; font-size: 1.2rem; color: #fff; padding: 18px 20px 10px; }
.side nav { flex: 1; overflow-y: auto; padding: 0 10px 10px; }
.side nav a { display: block; color: var(--side-ink); padding: 7px 12px; border-radius: 8px; }
.side nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.side nav a.active { background: var(--side-active); color: #fff; }
.nav-h { font-size: .75rem; color: #7d8898; padding: 14px 12px 4px; }
.me { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: .9rem; }
.me a { color: #fff; }
.me form { display: inline; }
.linkbtn { background: none; border: 0; color: #f59b94; cursor: pointer; font: inherit; padding: 0 6px; }

main { padding: 20px 28px 60px; max-width: 1400px; }
main.with-side { margin-right: 230px; }
.top { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.burger { display: none; font-size: 1.4rem; cursor: pointer; padding: 2px 8px; }
.search { flex: 1; max-width: 560px; }
.search input { width: 100%; }
.scrim { display: none; }

@media (max-width: 900px) {
  main.with-side { margin-right: 0; }
  main { padding: 14px 16px 50px; }
  .side { transform: translateX(100%); }
  #nav-toggle:checked ~ .side { transform: none; }
  #nav-toggle:checked ~ .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
  .burger { display: block; }
}

/* عناصر عامة */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 2px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.card-head p { margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .two { grid-template-columns: 1fr; } }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: .92rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.danger { color: var(--err); border-color: var(--err-soft); background: var(--err-soft); }
.btn.sm { padding: 3px 10px; font-size: .85rem; }
.btn.block { width: 100%; justify-content: center; margin-top: 8px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[disabled], select[disabled], textarea[disabled] { background: var(--surface-2); color: var(--muted); }

.flashes { display: grid; gap: 8px; margin-bottom: 14px; }
.flash { padding: 10px 14px; border-radius: 8px; background: var(--info-soft); }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--err-soft); color: var(--err); }

/* الجداول */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card .table-wrap { border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: .85rem; position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.k-textarea { white-space: normal; min-width: 200px; }
.row-act { text-align: left; }

.badge { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: .8rem; font-weight: 600; }
.st-installed { background: var(--ok-soft); color: var(--ok); }
.st-spare { background: var(--accent-soft); color: var(--accent); }
.st-broken { background: var(--err-soft); color: var(--err); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[name=q] { flex: 1; min-width: 200px; max-width: 360px; }

/* الفورم */
.form .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-weight: 600; font-size: .9rem; }
.field.wide { grid-column: 1 / -1; }
.field small { font-size: .78rem; }
.field.off { opacity: .45; }
.req { color: var(--err); }
.form-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.conn-note { font-size: .82rem; margin: 12px 0 0; }
.danger-zone { margin-top: -4px; }
.narrow { max-width: 420px; display: grid; gap: 12px; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.login { min-height: 80vh; display: grid; place-items: center; }
.login .card { width: 100%; max-width: 380px; display: grid; gap: 12px; }
.steps { margin: 0 0 14px; padding-right: 20px; }
.upload { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* الأرقام */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; color: var(--text); box-shadow: var(--shadow);
}
a.kpi:hover { border-color: var(--accent); text-decoration: none; }
.kpi b { font-size: 1.7rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: .88rem; }
.kpi.warn b { color: var(--err); }

.meter { height: 10px; background: var(--free); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter.sm { height: 6px; width: 90px; }
.meter.hot i { background: var(--warn); }
.mini { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }

.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: .9rem; }
.feed li { border-bottom: 1px dashed var(--border); padding-bottom: 6px; }

/* خريطة البورتات */
.ports { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 5px; margin: 6px 0 10px; }
.port {
  display: grid; place-items: center; height: 34px; border-radius: 6px; font-size: .8rem; font-weight: 600;
  background: var(--other); color: #fff; font-variant-numeric: tabular-nums;
}
.port:hover { text-decoration: none; outline: 2px solid var(--accent); }
.port.t-camera { background: var(--cam); }
.port.t-pc, .port.t-laptop { background: var(--pc); }
.port.free { background: var(--free); color: var(--muted); font-weight: 400; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i.port { width: 14px; height: 14px; display: inline-block; border-radius: 3px; }

@media print {
  .side, .top, .no-print, .flashes, .filters, .danger-zone { display: none !important; }
  main.with-side { margin: 0; }
  body { background: #fff; }
  .card, .table-wrap { box-shadow: none; border-color: #ccc; }
  th { position: static; }
}

/* اختيار المشروع */
.proj { margin: 4px 14px 8px; padding: 10px 12px; background: rgba(255,255,255,.05); border-radius: 10px; display: grid; gap: 6px; }
.proj label { font-size: .75rem; color: #7d8898; }
.proj select { width: 100%; background: #1c2635; color: #fff; border-color: #2c394b; font-weight: 600; }
.proj a { font-size: .8rem; color: #8fb4ff; }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.proj-card { display: grid; gap: 10px; align-content: start; }
.proj-card.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.proj-card .nums { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .88rem; color: var(--muted); }
.proj-card .nums b { color: var(--text); }
details summary { cursor: pointer; color: var(--muted); font-size: .88rem; }

/* المهام */
.nav-badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-inline-start: 6px; border-radius: 99px; background: #e5484d; color: #fff; font-size: .75rem; text-align: center; line-height: 1.6; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tab { padding: 7px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.pr-low { background: var(--free); color: var(--muted); }
.pr-normal { background: var(--info-soft); color: var(--text); }
.pr-high { background: var(--warn-soft); color: var(--warn); }
.pr-urgent { background: var(--err); color: #fff; }
.ts-new { background: var(--accent-soft); color: var(--accent); }
.ts-in_progress { background: var(--warn-soft); color: var(--warn); }
.ts-waiting { background: var(--free); color: var(--muted); }
.ts-done { background: var(--ok-soft); color: var(--ok); }
.ts-cancelled { background: var(--free); color: var(--muted); text-decoration: line-through; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0; }
.meta dt { color: var(--muted); font-size: .88rem; }
.meta dd { margin: 0; }
.desc { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; white-space: normal; line-height: 1.8; }
.timeline { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 10px; }
.timeline li { border-inline-start: 3px solid var(--accent); padding: 4px 12px; }
.timeline li.sys { border-color: var(--border); color: var(--muted); font-size: .88rem; }
.timeline .who { font-size: .85rem; }
.note-form { display: grid; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.note-form textarea { width: 100%; }
@media print { .tabs { display: none; } }
