/* ===== Guard Dashboard — تصميم هادئ وواضح (v1.3) ===== */
:root {
  --bg: #0c111b;
  --card: #141b29;
  --card-2: #101725;
  --border: #243047;
  --border-soft: #1c2639;
  --text: #e8eef9;
  --muted: #93a1b8;
  --primary: #4c8dff;
  --primary-dim: rgba(76, 141, 255, .14);
  --danger: #e35d6a;
  --ok: #3ecf8e;
  --warn: #e8b44a;
  --radius: 14px;
  --gap: .85rem;
  --shadow: 0 8px 24px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Cairo", "Segoe UI", Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.hidden { display: none !important; }
h2 { margin: 0 0 .35rem; font-size: 1.02rem; font-weight: 700; letter-spacing: -.01em; }
h3 { margin: 0 0 .2rem; font-size: .92rem; font-weight: 700; color: #dce6f7; }

/* ===== شاشة الدخول — تبقى بسيطة ===== */
#auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1rem; background: var(--bg);
}
.auth-card {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: .75rem;
}
.auth-card input {
  width: 100%; padding: .85rem 1rem; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-family: inherit; font-size: 1rem; text-align: center;
  direction: rtl;
}
.auth-card input::placeholder { color: var(--muted); }
.auth-card input:focus { outline: none; border-color: var(--primary); }
.auth-card button {
  width: 100%; padding: .85rem; border-radius: 12px; font-size: 1rem;
  background: var(--primary); color: #fff; border: none;
  font-family: inherit; font-weight: 700; cursor: pointer;
}
.auth-card button:hover { filter: brightness(1.08); }
.link-btn {
  background: transparent !important; color: var(--muted) !important;
  font-size: .85rem !important; font-weight: 400 !important;
  padding: 0 !important; text-decoration: underline; cursor: pointer;
}
.link-btn:hover { color: var(--text) !important; filter: none !important; }

/* ===== صفحة الاستقبال «قريباً» ===== */
.coming {
  width: 100%; max-width: 760px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  padding: 1rem;
}
.coming-badge {
  font-size: clamp(2.6rem, 9vw, 5rem);
  font-weight: 700; letter-spacing: .01em; line-height: 1.15;
  color: var(--text);
}
.coming-title {
  margin: .1rem 0 0; font-size: clamp(1.05rem, 3.6vw, 1.5rem);
  font-weight: 700; color: var(--muted);
}
.coming-url {
  margin: .5rem 0 0; font-size: clamp(1.35rem, 5.5vw, 2.7rem);
  font-weight: 700; direction: ltr; letter-spacing: .01em;
}
#gate-key {
  cursor: pointer; border-radius: 8px; padding: 0 .08em;
  transition: background .15s ease, color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
#gate-key:hover, #gate-key:focus {
  background: var(--primary); color: #fff; outline: none;
}
.coming-sub { margin: .45rem 0 0; color: var(--muted); font-size: .95rem; }
#gate-form { margin-top: 1.6rem; }

/* نافذة تغيير كلمة المرور */
#pw-modal input {
  width: 100%; padding: .75rem .9rem; margin-top: .55rem;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--card-2); color: var(--text);
  font-family: inherit; font-size: .95rem; text-align: center; direction: rtl;
}
#pw-modal input:focus { outline: none; border-color: var(--primary); }
#pw-modal h3 { text-align: center; }

#app-screen { min-height: 100vh; display: flex; flex-direction: column; }

/* ===== الشريط العلوي ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  padding: .55rem 1rem;
  background: rgba(12, 17, 27, .96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; }
.brand-mark { font-size: 1.1rem; line-height: 1; }
.brand-name { letter-spacing: .04em; }
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); display: inline-block;
  transition: background .2s ease;
}
.conn-dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(62, 207, 142, .15); }
.conn-dot.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(227, 93, 106, .15); }
.user-chip { display: flex; align-items: center; gap: .55rem; min-width: 0; }

/* ===== التبويبات ===== */
.tabs { display: flex; gap: .15rem; padding: .35rem 1rem 0; }
.desktop-tabs {
  border-bottom: 1px solid var(--border-soft);
  background: rgba(12, 17, 27, .9);
  position: sticky; top: 47px; z-index: 40; overflow-x: auto;
  scrollbar-width: none;
}
.desktop-tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; padding: .5rem 1rem; border-radius: 10px 10px 0 0;
  background: transparent; color: var(--muted);
  font-family: inherit; font-size: .86rem; font-weight: 600;
  border: none; cursor: pointer; border-bottom: 2px solid transparent;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.tabs button.active {
  color: var(--text); border-bottom-color: var(--primary); background: var(--primary-dim);
}
.tabs button:hover:not(.active) { color: #c5d0e4; }

.mobile-tabs {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 50;
  display: none; justify-content: space-around;
  padding: .35rem .2rem calc(.35rem + env(safe-area-inset-bottom));
  background: rgba(12, 17, 27, .98);
  border-top: 1px solid var(--border-soft);
  backdrop-filter: blur(12px);
}
.mobile-tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0;
  background: transparent; border: none; color: var(--muted);
  font-family: inherit; cursor: pointer; padding: .3rem 0; border-radius: 10px;
}
.mobile-tabs button span { font-size: 1.1rem; line-height: 1.2; }
.mobile-tabs button small { font-size: .64rem; font-weight: 600; }
.mobile-tabs button.active { color: var(--primary); background: var(--primary-dim); }

@media (max-width: 899px) {
  .desktop-tabs { display: none; }
  .mobile-tabs { display: flex; }
  #content { padding-bottom: 72px; }
}

/* ===== المحتوى والبطاقات ===== */
#content {
  flex: 1; width: 100%; max-width: 980px;
  margin: 0 auto; padding: 1rem .95rem 1.5rem;
}
.panel { display: none; animation: fadein .18s ease; }
.panel.active { display: block; }
.panel .card { margin-bottom: var(--gap); }
.panel .card:last-child { margin-bottom: 0; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  margin-bottom: var(--gap);
  box-shadow: var(--shadow);
}

/* ===== بطاقات KPI — أبسط وأهدأ ===== */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .55rem;
  margin-bottom: var(--gap);
}
@media (max-width: 700px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: .7rem .8rem;
  box-shadow: none;
}
.kpi-icon { display: none; }
.kpi-card strong {
  display: block; font-size: 1.25rem; font-weight: 700;
  line-height: 1.2; color: var(--text); font-variant-numeric: tabular-nums;
}
.kpi-card small { color: var(--muted); font-size: .74rem; }

/* ===== عناصر عامة ===== */
label { display: block; margin: .45rem 0 .3rem; color: var(--muted); font-size: .82rem; }
input, select {
  width: 100%; padding: .6rem .75rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card-2); color: var(--text);
  font-family: inherit; font-size: .9rem;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }
.small-select { width: auto; min-width: 100px; padding: .42rem .6rem; font-size: .82rem; }

button {
  padding: .52rem .95rem; border: none; border-radius: 10px;
  background: var(--primary); color: #fff;
  font-family: inherit; font-weight: 700; font-size: .88rem;
  cursor: pointer; transition: filter .12s ease, background .12s ease;
}
button:hover { filter: brightness(1.08); }
button:active { filter: brightness(.96); }
button.secondary { background: #2a354d; color: #dce6f7; }
button.secondary:hover { background: #33415c; filter: none; }
button.danger { background: var(--danger); }
button.ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
button.ghost:hover { color: var(--text); background: rgba(255,255,255,.04); filter: none; }
button.small { padding: .34rem .65rem; font-size: .78rem; border-radius: 8px; }
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0; font-size: .82rem; color: var(--muted); }
label.inline select { width: auto; min-width: 86px; padding: .4rem .5rem; font-size: .84rem; }

.msg { min-height: 1.2em; color: #8eb6ff; font-size: .86rem; margin: .35rem 0 0; }
.hint { color: var(--muted); font-size: .78rem; margin: .25rem 0 0; }
.select-hint { margin-top: .15rem; }

/* ===== كود العائلة ===== */
.family-card h2 { margin-bottom: .1rem; }
.family-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: .8rem; flex-wrap: wrap;
}
.code {
  display: inline-block; background: var(--card-2);
  border: 1px solid var(--border);
  padding: .35rem .95rem; border-radius: 10px;
  letter-spacing: .22em; font-size: 1.3rem; color: #a8c6ff;
  font-weight: 700;
}

.advanced-box { margin-top: .85rem; border-top: 1px solid var(--border-soft); padding-top: .6rem; }
.advanced-box summary {
  cursor: pointer; color: var(--muted); font-size: .8rem; font-weight: 600;
  list-style: none; user-select: none;
}
.advanced-box summary::-webkit-details-marker { display: none; }
.advanced-box summary::before { content: "▸ "; color: var(--primary); }
.advanced-box[open] summary::before { content: "▾ "; }
.advanced-box summary:hover { color: var(--text); }
.wake-links { margin-top: .6rem; display: flex; flex-direction: column; gap: .45rem; }
.wake-item { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.wake-item input { direction: ltr; text-align: left; font-size: .76rem; padding: .4rem .55rem; flex: 1; min-width: 160px; }

/* ===== التحكم — بطاقات إجراءات أنظف ===== */
.ctrl-head { display: flex; flex-direction: column; gap: .1rem; margin-bottom: .85rem; }
.ctrl-head label { margin-top: 0; }

.action-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem;
}
@media (max-width: 640px) { .action-grid { grid-template-columns: 1fr; } }

.action-card {
  display: flex; gap: .75rem; align-items: flex-start;
  background: var(--card-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: .85rem .9rem;
  transition: border-color .15s ease;
}
.action-card:hover { border-color: #2f3d58; }

.action-icon {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; background: rgba(255,255,255,.04);
  border: 1px solid var(--border-soft);
}
.action-card.video .action-icon { background: rgba(167, 139, 250, .1); }
.action-card.audio .action-icon { background: rgba(232, 180, 74, .1); }
.action-card.location .action-icon { background: rgba(62, 207, 142, .1); }
.action-card.photo .action-icon { background: rgba(76, 141, 255, .1); }

.action-body { flex: 1; min-width: 0; }
.action-body .row { margin-top: .5rem; }
.action-body button { font-size: .84rem; padding: .45rem .85rem; }

.info-strip {
  display: flex; gap: .65rem; align-items: flex-start;
  margin-top: .85rem; padding: .7rem .75rem;
  background: rgba(76, 141, 255, .05);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
}
.info-icon { font-size: 1.15rem; line-height: 1.3; }
.info-strip strong { font-size: .86rem; display: block; margin-bottom: .1rem; }
.info-strip .hint { margin: 0; }

/* ===== شبكة الأجهزة ===== */
.devices-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: .65rem; margin-top: .55rem;
}
.device-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: .75rem .8rem;
  background: var(--card-2);
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
  position: relative;
  display: flex; gap: .65rem; align-items: flex-start;
}
.device-card:hover { border-color: #2f3d58; }
.device-card.selected {
  border-color: rgba(76, 141, 255, .55);
  background: rgba(76, 141, 255, .07);
}
.device-avatar {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem; background: rgba(255,255,255,.04);
  border: 1px solid var(--border-soft);
}
.device-info { flex: 1; min-width: 0; padding-inline-end: 1.6rem; position: relative; z-index: 1; }
.device-name {
  font-weight: 700; font-size: .88rem;
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
}
.device-meta { color: var(--muted); font-size: .74rem; margin-top: .12rem; }
.device-del {
  position: absolute; top: .45rem; inset-inline-end: .45rem;
  z-index: 3; min-width: 30px; min-height: 30px;
  padding: .2rem .5rem; font-size: .8rem;
  background: rgba(12, 17, 27, .9); color: var(--muted);
  border: 1px solid var(--border); border-radius: 9px;
  cursor: pointer; line-height: 1.2;
}
.device-del:hover, .device-del:focus-visible {
  color: #ffb4bc; border-color: var(--danger);
  background: rgba(227, 93, 106, .15); filter: none;
}
.device-warn {
  margin-top: .35rem; padding: .3rem .45rem; border-radius: 8px;
  background: rgba(232, 180, 74, .1);
  border: 1px solid rgba(232, 180, 74, .28);
  color: #f0c56a; font-size: .74rem; line-height: 1.45;
}
#cmd-device-state.warn-line { color: var(--warn); }

.badge {
  display: inline-block; padding: .06rem .5rem; border-radius: 999px;
  font-size: .68rem; font-weight: 700; background: #2a354d; color: #b7c3d8;
}
.badge.online { background: rgba(62, 207, 142, .14); color: var(--ok); }
.badge.offline { background: #243047; color: var(--muted); }

/* ===== المعرض ===== */
.media-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: .7rem; margin-top: .6rem;
}
.g-item {
  border: 1px solid var(--border-soft);
  border-radius: 12px; overflow: hidden;
  background: var(--card-2); cursor: pointer;
  transition: border-color .12s ease;
}
.g-item:hover { border-color: #2f3d58; }
.g-thumb {
  width: 100%; height: 120px; object-fit: cover;
  display: block; background: #0a101c;
}
.g-audio, .g-loc {
  padding: .7rem; display: flex; align-items: center; gap: .5rem; min-height: 84px;
}
.g-icon { font-size: 1.5rem; }
.g-meta { padding: .45rem .55rem; font-size: .74rem; color: var(--muted); }
.g-type { color: var(--text); font-weight: 700; font-size: .78rem; display: block; margin-bottom: .05rem; }

/* ===== المواقع ===== */
.map-box {
  height: 300px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border-soft); background: #0a101c; margin-top: .6rem;
}
.loc-list {
  display: flex; flex-direction: column; gap: .45rem;
  margin-top: .65rem; max-height: 300px; overflow-y: auto;
}
.loc-item {
  border: 1px solid var(--border-soft); border-radius: 10px;
  padding: .55rem .7rem; background: var(--card-2);
  font-size: .82rem; display: flex; justify-content: space-between;
  gap: .6rem; flex-wrap: wrap; align-items: center;
}
.loc-item a { color: #8eb6ff; text-decoration: none; font-weight: 600; font-size: .78rem; }

/* ===== جدول السجل ===== */
.table-wrap { overflow-x: auto; margin-top: .6rem; }
.cmd-table {
  width: 100%; border-collapse: collapse;
  font-size: .82rem; min-width: 540px;
}
.cmd-table th, .cmd-table td {
  text-align: right; padding: .55rem .55rem;
  border-bottom: 1px solid var(--border-soft); white-space: nowrap;
}
.cmd-table th {
  color: var(--muted); font-weight: 700; font-size: .76rem;
  background: transparent;
}
.cmd-table tbody tr:hover { background: rgba(255,255,255,.025); }
.st {
  display: inline-block; padding: .1rem .55rem;
  border-radius: 999px; font-size: .72rem; font-weight: 700;
}
.st.pending { background: #2a354d; color: #c5d0e4; }
.st.running { background: rgba(232, 180, 74, .14); color: var(--warn); }
.st.success { background: rgba(62, 207, 142, .14); color: var(--ok); }
.st.failed { background: rgba(227, 93, 106, .14); color: #ff9aa5; }

/* ===== Lightbox ===== */
#lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.lb-backdrop { position: absolute; inset: 0; background: rgba(5, 8, 14, .86); backdrop-filter: blur(4px); }
.lb-box {
  position: relative; width: min(92vw, 860px);
  max-height: 92vh; overflow-y: auto; padding: .85rem;
}
#lb-media img, #lb-media video {
  width: 100%; max-height: 70vh; object-fit: contain;
  display: block; border-radius: 12px; background: #0a101c;
}
#lb-media audio { width: 100%; margin-top: .5rem; }
.lb-close {
  position: absolute; top: .5rem; inset-inline-start: .5rem;
  z-index: 2; padding: .28rem .6rem;
  background: rgba(12, 17, 27, .85);
}
.lb-actions { margin-top: .65rem; }

/* ===== تأكيد الحذف ===== */
#confirm-modal {
  position: fixed; inset: 0; z-index: 110;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
#confirm-modal .lb-backdrop { z-index: 0; }
.confirm-box {
  position: relative; z-index: 1;
  width: min(92vw, 380px); text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
  background: var(--card);
}
.confirm-box .row { justify-content: center; }
#confirm-text { margin: 0 0 .45rem; font-weight: 700; }

/* ===== Toasts ===== */
#toasts {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  inset-inline-start: 50%; transform: translateX(50%);
  z-index: 120; display: flex; flex-direction: column; gap: .4rem;
  align-items: center; pointer-events: none;
}
@media (min-width: 900px) { #toasts { bottom: auto; top: 58px; } }
.toast {
  background: #1a2438;
  border: 1px solid var(--border);
  color: var(--text);
  padding: .5rem 1rem; border-radius: 999px;
  font-size: .82rem; box-shadow: var(--shadow);
  animation: toastin .2s ease; max-width: 92vw; text-align: center;
}
.toast.ok { border-color: rgba(62, 207, 142, .45); }
.toast.err { border-color: rgba(227, 93, 106, .5); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Leaflet داكن ===== */
.leaflet-container { background: #0a101c !important; font-family: inherit; }

/* ===== حالات التحميل ===== */
.skeleton {
  background: linear-gradient(90deg, #182033 25%, #1f2a40 50%, #182033 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: 10px;
  min-height: 1.2em;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.loading-row { display: flex; flex-direction: column; gap: .45rem; margin-top: .5rem; }
.loading-row .skeleton { height: 48px; }
.empty-state {
  text-align: center; padding: 1.4rem .8rem;
  color: var(--muted); font-size: .86rem;
}
.empty-state .icon { font-size: 1.7rem; display: block; margin-bottom: .35rem; opacity: .85; }
.error-state { color: #ff9aa5; font-size: .85rem; margin-top: .45rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
