@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

/* نفس رموز التصميم من لوحة NUI داخل اللعبة (cctv_admin/web/style.css)،
   منقولة إلى صفحة مستقلة بدل لوحة عائمة فوق اللعبة. */
:root {
    --accent: #325f83; --accent-soft: #6a9abd; --bg: #07090c;
    --panel: rgba(12, 17, 23, .96); --line: rgba(129, 173, 220, .22);
    --text: #f3f7fb; --muted: rgba(243, 247, 251, .58); --danger: #d55252; --warn: #cf893f;
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: Cairo, sans-serif; }
html, body { height: 100%; }
body {
    background: radial-gradient(circle at 20% 0%, #0d1520 0%, var(--bg) 55%);
    color: var(--text);
    direction: rtl;
    overflow: hidden;
}
.hidden { display: none !important; }
button, input, textarea, select { font: inherit; }
button {
    cursor: pointer; color: var(--text); border: 1px solid var(--line);
    background: #0d1721; padding: .65rem 1rem; transition: .15s;
}
button:hover { border-color: var(--accent-soft); background: #162739; }
button:disabled { opacity: .45; cursor: not-allowed; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--accent); }

/* ---------------------------------------------------------------- دخول */
#loginScreen {
    height: 100vh; display: grid; place-items: center;
    background-image: linear-gradient(#ffffff08 1px, transparent 1px), linear-gradient(90deg, #ffffff08 1px, transparent 1px);
    background-size: 34px 34px;
}
.login-card {
    width: 360px; background: var(--panel); border: 1px solid var(--line);
    border-right: 3px solid var(--accent); padding: 2rem 1.8rem;
    clip-path: polygon(0 18px, 18px 0, 100% 0, 100% 100%, 0 100%);
    box-shadow: 0 24px 70px #000;
}
.login-card .eyebrow { font-size: .72rem; color: var(--accent-soft); font-weight: 800; }
.login-card h1 { font-size: 1.35rem; margin: .3rem 0 1.6rem; }
.field { margin-bottom: 1.1rem; }
.field label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .4rem; }
.field input {
    width: 100%; padding: .7rem .8rem; background: #ffffff06; border: 0;
    border-bottom: 1px solid var(--line); color: #fff; outline: none;
}
.field input:focus { border-color: var(--accent-soft); }
.login-card button[type=submit] { width: 100%; background: var(--accent); margin-top: .6rem; padding: .75rem; }
.login-error {
    margin-top: 1rem; padding: .6rem .8rem; font-size: .8rem; color: #ec9a9a;
    background: rgba(213, 82, 82, .12); border: 1px solid rgba(213, 82, 82, .3);
}

/* ------------------------------------------------------------- التطبيق */
#app { height: 100vh; display: flex; flex-direction: column; }

.topbar {
    height: 4.6rem; padding: 0 1.5rem; display: flex; align-items: center; gap: 1.5rem;
    border-bottom: 2px solid var(--accent); background: #ffffff05; flex: none;
}
.topbar > div:first-child { flex: 1; }
.eyebrow { font-size: .72rem; color: var(--accent-soft); font-weight: 800; }
.topbar h1 { font-size: 1.25rem; }
.live-status { display: flex; align-items: center; gap: .55rem; color: #8cdfac; font-size: .85rem; }
.live-status.offline { color: var(--muted); }
.live-status i {
    width: 9px; height: 9px; border-radius: 50%; background: #31c76a;
    box-shadow: 0 0 12px #31c76a; animation: pulse 1.4s infinite;
}
.live-status.offline i { background: var(--muted); box-shadow: none; animation: none; }
#serverSelect {
    background: #0d1721; color: var(--text); border: 1px solid var(--line);
    padding: .55rem .8rem; min-width: 180px;
}
.whoami { font-size: .78rem; color: var(--muted); }
.whoami b { color: var(--text); }

.workspace { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 310px; }
.wall-wrap { padding: 1rem 1.2rem 10rem; min-height: 0; display: flex; flex-direction: column; }
.wall-head { height: 3.6rem; flex: none; display: flex; align-items: center; justify-content: space-between; }
.wall-head h2 { font-size: 1.05rem; }
.wall-head p { font-size: .75rem; color: var(--muted); }
.pager { display: flex; align-items: center; gap: .7rem; }
.pager button { padding: .35rem .75rem; }

.camera-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: .65rem; }
.camera { position: relative; overflow: hidden; background: #050709; border: 1px solid var(--line); cursor: pointer; min-height: 0; }
.camera:hover, .camera.selected { border-color: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.camera img { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera.no-signal:after {
    content: attr(data-status); position: absolute; inset: 0; display: grid; place-items: center;
    color: var(--muted); font-size: .76rem; text-align: center; padding: 0 .6rem;
    background: radial-gradient(circle, #17232e, #070a0d);
}
.camera-info {
    position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between;
    padding: .38rem .55rem; background: linear-gradient(transparent, #000 40%); font-size: .72rem; padding-top: 1.4rem;
}
.camera-id { color: #8cdfac; }
.watchers-badge { position: absolute; top: .4rem; left: .4rem; background: #000a; padding: .1rem .45rem; font-size: .68rem; border-radius: 2px; }

.empty-state { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: .85rem; padding: 2rem; }
.empty-state b { display: block; color: var(--text); font-size: 1rem; margin-bottom: .5rem; }

.sidebar { border-right: 1px solid var(--line); background: #090d12; padding: .8rem; overflow: hidden; display: flex; flex-direction: column; }
.search-shell input {
    width: 100%; padding: .8rem; background: #ffffff06; border: 0; border-bottom: 1px solid var(--line);
    color: #fff; outline: none; text-align: right;
}
.search-shell input:focus { border-color: var(--accent-soft); }
.player-list { flex: 1; overflow: auto; padding-top: .6rem; }
.player { display: flex; align-items: center; gap: .7rem; padding: .65rem; border-bottom: 1px solid #ffffff0c; cursor: pointer; }
.player:hover, .player.selected { background: var(--accent); }
.player .dot { width: 8px; height: 8px; border-radius: 50%; background: #31c76a; flex: none; }
.player-info { flex: 1; min-width: 0; }
.player-info b, .player-info small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-info small { color: var(--muted); }
.player.selected small { color: #fff; }

.detail-panel {
    position: absolute; bottom: 1.2rem; left: 1.2rem; right: 332px; height: 8.4rem;
    background: rgba(9, 13, 18, .98); border: 1px solid var(--line); border-right: 3px solid var(--accent);
    padding: .8rem 1rem; display: grid; grid-template-columns: 1.2fr 1fr; gap: .7rem 1.3rem;
}
.detail-title { display: flex; justify-content: space-between; align-items: center; }
.detail-title p { color: var(--muted); font-size: .75rem; }
.live-chip { color: #79d99e; font-size: .7rem; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); font-size: .72rem; color: var(--muted); align-content: start; }
.stats b { color: #fff; }
.actions { grid-column: 1 / -1; display: flex; gap: .5rem; }
.actions button { flex: 1; padding: .4rem; font-size: .82rem; }
.primary { background: var(--accent); }
.danger { background: #692d32 !important; border-color: #a5454d !important; }
.warn { background: #55361f !important; }

/* ---------------------------------------------------------- عرض المباشر */
.theater {
    position: absolute; inset: 0; background: #000e; display: grid; place-items: center; z-index: 15;
}
.theater-box {
    width: min(90vw, 1100px); background: var(--panel); border: 1px solid var(--line); border-right: 3px solid var(--accent);
}
.theater-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1.1rem; border-bottom: 2px solid var(--accent); }
.theater video { width: 100%; aspect-ratio: 16/9; background: #050709; display: block; }
.theater-status { text-align: center; padding: .6rem; font-size: .78rem; color: var(--muted); }

.modal { position: absolute; inset: 0; background: #000b; display: grid; place-items: center; z-index: 20; }
.modal-card {
    width: 390px; background: var(--panel); border: 1px solid var(--line); border-right: 3px solid var(--accent);
    padding: 1.2rem; clip-path: polygon(0 12px, 12px 0, 100% 0, 100% 100%, 0 100%);
}
.modal-card h3 { padding-bottom: .8rem; border-bottom: 2px solid var(--accent); }
.modal-card label { display: block; color: var(--muted); font-size: .8rem; margin-top: 1rem; }
.modal-card select, .modal-card textarea {
    display: block; width: 100%; margin-top: .35rem; background: #ffffff08; color: #fff;
    border: 0; border-bottom: 1px solid var(--line); padding: .65rem; outline: 0;
}
.modal-card option { background: #111; }
.modal-card textarea { height: 90px; resize: none; }
.modal-actions { display: flex; gap: .6rem; margin-top: 1rem; }
.modal-actions button { flex: 1; }

.toast {
    position: fixed; top: 1.4rem; left: 50%; transform: translateX(-50%) translateY(-20px);
    padding: .65rem 1.2rem; background: #101a24; border: 1px solid var(--line); opacity: 0;
    transition: .2s; pointer-events: none; z-index: 30;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@keyframes pulse { 50% { opacity: .35; } }

@media (max-width: 1300px) {
    .camera-grid { grid-template-columns: repeat(3, 1fr); }
    .sidebar { width: 270px; }
    .workspace { grid-template-columns: 1fr 270px; }
    .detail-panel { right: 292px; }
}
