/* ============================================================
   CySA+ CS0-003 Simulator Lab — Main Stylesheet
   Multi-theme, RTL-aware, responsive
   By: Dr. Mohamed Al-Shamey
   ============================================================ */

:root {
  /* Default: Dark Cyber theme */
  --bg: #0a0e17;
  --bg-2: #121826;
  --panel: #161d2e;
  --panel-2: #1c2538;
  --border: #253046;
  --text: #e4ecf7;
  --text-dim: #8b9ab3;
  --accent: #00e5ff;
  --accent-2: #0091ea;
  --success: #00e676;
  --danger: #ff5252;
  --warning: #ffb300;
  --shadow: 0 8px 30px rgba(0,0,0,0.45);
  --radius: 14px;
  --font: 'Segoe UI', 'Tahoma', system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
  --bg: #eef2f7; --bg-2: #e3e9f2; --panel: #ffffff; --panel-2: #f4f7fb;
  --border: #d4dce8; --text: #1a2436; --text-dim: #5e6b82;
  --accent: #0077c8; --accent-2: #005fa3; --success: #1b9e5a;
  --danger: #d32f2f; --warning: #e08600; --shadow: 0 8px 30px rgba(0,60,120,0.12);
}
[data-theme="matrix"] {
  --bg: #000700; --bg-2: #04120a; --panel: #061a0e; --panel-2: #0a2414;
  --border: #0f3d20; --text: #b6ffcb; --text-dim: #4fae6d;
  --accent: #00ff6a; --accent-2: #00c853; --success: #76ff03;
  --danger: #ff3d00; --warning: #ffea00; --shadow: 0 8px 30px rgba(0,255,106,0.1);
}
[data-theme="midnight"] {
  --bg: #0a0f2b; --bg-2: #101840; --panel: #141c4a; --panel-2: #1b2660;
  --border: #2a3680; --text: #dfe6ff; --text-dim: #9099d0;
  --accent: #7c4dff; --accent-2: #536dfe; --success: #00e5a0;
  --danger: #ff5c8a; --warning: #ffc400; --shadow: 0 8px 30px rgba(50,30,130,0.4);
}
[data-theme="crimson"] {
  --bg: #15060a; --bg-2: #220a11; --panel: #2a0d16; --panel-2: #371019;
  --border: #4d1823; --text: #ffe4ea; --text-dim: #c48b96;
  --accent: #ff1744; --accent-2: #d50000; --success: #00e676;
  --danger: #ff8a80; --warning: #ffab00; --shadow: 0 8px 30px rgba(120,0,20,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background .3s, color .3s;
}
[dir="rtl"] body { font-family: 'Tahoma', 'Segoe UI', system-ui, sans-serif; }

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a; font-weight: 700; border: none;
  padding: 12px 22px; border-radius: 10px; font-size: 15px;
  transition: transform .15s, box-shadow .15s; display: inline-flex;
  align-items: center; gap: 8px; justify-content: center;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.btn:active { transform: translateY(0); }
.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); font-weight: 600;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: linear-gradient(135deg, var(--danger), #c62828); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; position: relative; overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(0,229,255,.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(0,145,234,.08), transparent 40%),
    var(--bg);
}
.login-grid-bg {
  position: absolute; inset: 0; z-index: 0; opacity: .25;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at center, black, transparent 75%);
}
.login-card {
  position: relative; z-index: 1; width: 100%; max-width: 420px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 38px 32px; box-shadow: var(--shadow);
}
.login-logo {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 18px;
  display: flex; align-items: center; justify-content: center; font-size: 34px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a; box-shadow: 0 8px 24px rgba(0,229,255,.3);
}
.login-card h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 4px; }
.login-card .author { text-align: center; color: var(--accent); font-size: 12px; margin-bottom: 24px; font-weight: 600; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text);
  font-size: 15px; font-family: inherit; transition: border-color .2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,229,255,.15);
}
.login-lang { display: flex; justify-content: center; margin-top: 18px; }
.login-lang select { max-width: 180px; }
.alert { padding: 11px 14px; border-radius: 9px; font-size: 14px; margin-bottom: 14px; }
.alert-error { background: rgba(255,82,82,.15); color: var(--danger); border: 1px solid rgba(255,82,82,.3); }
.alert-success { background: rgba(0,230,118,.14); color: var(--success); border: 1px solid rgba(0,230,118,.3); }

/* ---------- App Shell ---------- */
.app { display: none; min-height: 100vh; }
.app.active { display: grid; grid-template-columns: 260px 1fr; grid-template-rows: 64px 1fr; grid-template-areas: "sidebar topbar" "sidebar main"; }

.topbar {
  grid-area: topbar; display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-size: 18px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar select { padding: 8px 10px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; }
.user-chip { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--accent-2));
  color: #04121a; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px;
}
.user-chip .uname { font-size: 13px; font-weight: 600; }
.user-chip .urole { font-size: 11px; color: var(--text-dim); }

/* ---------- Sidebar ---------- */
.sidebar {
  grid-area: sidebar; background: var(--panel); border-right: 1px solid var(--border);
  padding: 20px 14px; overflow-y: auto; display: flex; flex-direction: column;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; }
.sidebar-brand .logo {
  width: 42px; height: 42px; border-radius: 11px; font-size: 20px;
  background: linear-gradient(135deg,var(--accent),var(--accent-2)); color: #04121a;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-brand .bt { font-size: 15px; font-weight: 800; line-height: 1.2; }
.sidebar-brand .bs { font-size: 10px; color: var(--text-dim); }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px;
  color: var(--text-dim); font-weight: 600; font-size: 14px; margin-bottom: 4px;
  cursor: pointer; transition: all .18s; border: 1px solid transparent;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: linear-gradient(135deg, rgba(0,229,255,.18), rgba(0,145,234,.1)); color: var(--accent); border-color: var(--border); }
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.sidebar-footer { margin-top: auto; padding: 14px 8px 0; font-size: 11px; color: var(--text-dim); border-top: 1px solid var(--border); }

/* ---------- Main ---------- */
.main { grid-area: main; padding: 26px; overflow-y: auto; }
.view { display: none; animation: fade .3s; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.section-head { margin-bottom: 20px; }
.section-head h2 { font-size: 24px; margin-bottom: 4px; }
.section-head p { color: var(--text-dim); font-size: 14px; }

/* ---------- Cards / Grid ---------- */
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; transition: transform .18s, border-color .18s;
}
.card-hover:hover { transform: translateY(-4px); border-color: var(--accent); }

.stat-card { display: flex; align-items: center; gap: 16px; }
.stat-ico {
  width: 52px; height: 52px; border-radius: 13px; font-size: 24px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); color: var(--accent);
}
.stat-val { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-dim); margin-top: 5px; }

/* Domain cards */
.domain-card { cursor: pointer; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.domain-card .dc-badge {
  position: absolute; top: 14px; inset-inline-end: 14px; font-size: 11px; font-weight: 700;
  padding: 4px 10px; border-radius: 20px; background: var(--panel-2); color: var(--accent);
}
.domain-card .dc-ico { font-size: 30px; }
.domain-card h3 { font-size: 17px; }
.domain-card .dc-weight { font-size: 12px; color: var(--text-dim); }
.domain-card .dc-bar { height: 7px; background: var(--panel-2); border-radius: 10px; overflow: hidden; margin-top: 4px; }
.domain-card .dc-bar span { display: block; height: 100%; background: linear-gradient(90deg,var(--accent),var(--accent-2)); }

/* ---------- Quiz ---------- */
.quiz-wrap { max-width: 820px; margin: 0 auto; }
.quiz-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.quiz-progress-bar { height: 8px; background: var(--panel-2); border-radius: 10px; overflow: hidden; margin-bottom: 22px; }
.quiz-progress-bar span { display: block; height: 100%; background: linear-gradient(90deg,var(--accent),var(--accent-2)); transition: width .3s; }
.q-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.chip { font-size: 11px; font-weight: 700; padding: 4px 11px; border-radius: 20px; background: var(--panel-2); color: var(--text-dim); }
.chip.accent { color: var(--accent); }
.timer { font-size: 15px; font-weight: 800; color: var(--warning); font-variant-numeric: tabular-nums; }
.q-text { font-size: 19px; font-weight: 600; margin-bottom: 20px; line-height: 1.5; }
.options { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.option {
  display: flex; align-items: center; gap: 14px; padding: 15px 18px; border-radius: 12px;
  background: var(--panel-2); border: 2px solid var(--border); cursor: pointer; transition: all .15s;
}
.option:hover { border-color: var(--accent); }
.option.selected { border-color: var(--accent); background: rgba(0,229,255,.1); }
.option.correct { border-color: var(--success); background: rgba(0,230,118,.14); }
.option.wrong { border-color: var(--danger); background: rgba(255,82,82,.14); }
.option .opt-letter {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; font-weight: 800;
  display: flex; align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--border);
}
.option.selected .opt-letter, .option.correct .opt-letter { background: var(--accent); color: #04121a; border: none; }
.option.wrong .opt-letter { background: var(--danger); color: #fff; border: none; }
.explain {
  padding: 15px 18px; border-radius: 12px; background: var(--panel-2);
  border-inline-start: 4px solid var(--accent); margin-bottom: 20px; font-size: 14px;
}
.explain strong { color: var(--accent); }
.quiz-nav { display: flex; justify-content: space-between; gap: 12px; }

/* ---------- Results ---------- */
.result-hero { text-align: center; padding: 30px 20px; }
.result-ring {
  width: 160px; height: 160px; margin: 0 auto 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; position: relative;
  background: conic-gradient(var(--accent) var(--pct,0%), var(--panel-2) 0);
}
.result-ring::before { content:''; position: absolute; inset: 12px; border-radius: 50%; background: var(--panel); }
.result-ring .rv { position: relative; font-size: 40px; font-weight: 800; }
.result-status { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.result-status.pass { color: var(--success); }
.result-status.fail { color: var(--danger); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 13px 16px; text-align: start; border-bottom: 1px solid var(--border); }
table.data th { background: var(--panel-2); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--panel-2); }
.badge { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px; }
.badge.on { background: rgba(0,230,118,.15); color: var(--success); }
.badge.off { background: rgba(255,82,82,.15); color: var(--danger); }
.badge.admin { background: rgba(124,77,255,.18); color: #b39dff; }
.badge.student { background: rgba(0,229,255,.14); color: var(--accent); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 480px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 18px; }
.modal-head .close { background: none; border: none; color: var(--text-dim); font-size: 24px; line-height: 1; }
.modal-body { padding: 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Lab ---------- */
.lab-card { cursor: pointer; display: flex; flex-direction: column; gap: 10px; }
.lab-card .lc-cat { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .5px; }
.lab-card h3 { font-size: 16px; }
.lab-card .lc-foot { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; }
.terminal {
  background: #05080f; border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  font-family: 'Consolas','Monaco',monospace; font-size: 13px; color: #9dffb0;
  max-height: 340px; overflow: auto; white-space: pre-wrap; line-height: 1.5; direction: ltr; text-align: left;
}
.terminal .tl-ts { color: #5e7fa8; }
.terminal .tl-warn { color: var(--warning); }
.terminal .tl-crit { color: var(--danger); font-weight: 700; }
.terminal .tl-ok { color: var(--success); }
.lab-task { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.lab-task .lt-q { font-weight: 600; margin-bottom: 12px; }
.lab-task.solved { border-color: var(--success); }

/* ---------- Progress list ---------- */
.activity-item { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-ico { width: 40px; height: 40px; border-radius: 10px; background: var(--panel-2); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.activity-meta { flex: 1; }
.activity-meta .am-t { font-weight: 600; font-size: 14px; }
.activity-meta .am-d { font-size: 12px; color: var(--text-dim); }
.activity-score { font-weight: 800; font-size: 18px; }

/* theme swatches */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap: 12px; }
.theme-swatch { border: 2px solid var(--border); border-radius: 12px; padding: 14px; cursor: pointer; text-align: center; transition: all .15s; }
.theme-swatch:hover { transform: translateY(-3px); }
.theme-swatch.active { border-color: var(--accent); }
.theme-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 10px; }
.theme-dots span { width: 20px; height: 20px; border-radius: 50%; }
.theme-swatch .ts-name { font-size: 13px; font-weight: 600; }

/* loading */
.spinner { width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty-state .es-ico { font-size: 48px; margin-bottom: 14px; opacity: .5; }

/* mobile menu button */
.menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 22px; }

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app.active { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  .sidebar {
    position: fixed; inset-inline-start: 0; top: 0; bottom: 0; width: 260px; z-index: 60;
    transform: translateX(-100%); transition: transform .25s;
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  .user-chip .uname, .user-chip .urole { display: none; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; display: none; }
  .sidebar-overlay.active { display: block; }
}
