/* ===================== THEMES ===================== */
:root, [data-theme="dark"] {
  --bg: #0b1220; --bg2: #111a2e; --card: #141f36; --card2: #1a2744; --border: #24345a;
  --text: #e6edf7; --muted: #8b9bb8; --primary: #3b82f6; --primary-2: #2563eb; --accent: #10b981;
  --danger: #ef4444; --warn: #f59e0b; --info: #06b6d4; --ok: #22c55e; --violet: #8b5cf6;
  --shadow: 0 8px 24px rgba(0,0,0,.35); --grid: rgba(59,130,246,.07);
}
[data-theme="light"] {
  --bg: #f1f5f9; --bg2: #ffffff; --card: #ffffff; --card2: #f8fafc; --border: #e2e8f0;
  --text: #0f172a; --muted: #64748b; --primary: #2563eb; --primary-2: #1d4ed8; --accent: #059669;
  --shadow: 0 4px 16px rgba(15,23,42,.08); --grid: rgba(37,99,235,.06);
}
[data-theme="cyber"] {
  --bg: #050a05; --bg2: #0a140b; --card: #0d1a0f; --card2: #112314; --border: #1d3d22;
  --text: #d1fae5; --muted: #6ee7b7; --primary: #22c55e; --primary-2: #16a34a; --accent: #a3e635;
  --shadow: 0 0 18px rgba(34,197,94,.15); --grid: rgba(34,197,94,.08);
}
[data-theme="ocean"] {
  --bg: #04202b; --bg2: #062b3a; --card: #083646; --card2: #0b4255; --border: #11566e;
  --text: #e0f7ff; --muted: #8cc8dc; --primary: #06b6d4; --primary-2: #0891b2; --accent: #2dd4bf;
  --shadow: 0 8px 24px rgba(0,0,0,.35); --grid: rgba(6,182,212,.08);
}
[data-theme="sunset"] {
  --bg: #1c0f1a; --bg2: #26131f; --card: #2e1726; --card2: #3a1d30; --border: #5a2b47;
  --text: #fde8f0; --muted: #d6a2bb; --primary: #f97316; --primary-2: #ea580c; --accent: #ec4899;
  --shadow: 0 8px 24px rgba(0,0,0,.4); --grid: rgba(249,115,22,.07);
}
[data-theme="purple"] {
  --bg: #120d24; --bg2: #19122f; --card: #1f173a; --card2: #281e4a; --border: #3b2d6b;
  --text: #ede9fe; --muted: #a79bd6; --primary: #8b5cf6; --primary-2: #7c3aed; --accent: #22d3ee;
  --shadow: 0 8px 24px rgba(0,0,0,.4); --grid: rgba(139,92,246,.08);
}
[data-theme="contrast"] {
  --bg: #000; --bg2: #000; --card: #0a0a0a; --card2: #141414; --border: #ffffff;
  --text: #ffffff; --muted: #ffd400; --primary: #ffd400; --primary-2: #ffea00; --accent: #00ffff;
  --danger: #ff3b3b; --warn: #ffa500; --shadow: none; --grid: rgba(255,255,255,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5; transition: background .25s, color .25s;
}
[dir="rtl"] body, [lang="ar"] body { font-family: 'Cairo', 'Inter', sans-serif; }
[hidden] { display: none !important; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.mono { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; }

/* ===================== INPUTS / BUTTONS ===================== */
.input, .select, .select-sm, textarea, input[type="text"], input[type="password"], input[type="search"], input[type="email"], input[type="number"], input[type="date"] {
  background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font: inherit; outline: none; width: 100%; transition: border .2s, box-shadow .2s;
}
.select-sm { width: auto; padding: 6px 8px; font-size: 13px; }
.select { width: auto; min-width: 140px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
textarea { min-height: 90px; resize: vertical; }
.input-icon { position: relative; }
.input-icon i { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }
.input-icon input { padding-inline-start: 36px; }
.grow { flex: 1; min-width: 200px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: .15s;
  background: var(--card2); color: var(--text);
}
.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #fff; }
[data-theme="contrast"] .btn-primary { color: #000; }
.btn-accent { background: var(--accent); color: #fff; }
[data-theme="contrast"] .btn-accent, [data-theme="cyber"] .btn-accent { color: #000; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-block { width: 100%; justify-content: center; padding: 11px; }
.btn-xs { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.icon-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 6px 8px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: var(--card2); }

/* ===================== LOGIN ===================== */
.login-screen { min-height: 100vh; display: grid; place-items: center; position: relative; overflow: hidden; padding: 20px;
  background: radial-gradient(ellipse at top, color-mix(in srgb, var(--primary) 18%, var(--bg)), var(--bg) 60%); }
.login-bg-grid { position: absolute; inset: 0; background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 40px 40px; mask-image: radial-gradient(circle at center, #000 30%, transparent 75%); }
.login-top-controls { position: absolute; top: 16px; inset-inline-end: 16px; display: flex; gap: 8px; z-index: 2; }
.login-card { position: relative; z-index: 1; width: 100%; max-width: 410px; background: color-mix(in srgb, var(--card) 92%, transparent);
  border: 1px solid var(--border); border-radius: 18px; padding: 34px 30px; box-shadow: var(--shadow); backdrop-filter: blur(8px); }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; text-align: center; }
.login-card > p { text-align: center; margin: 0 0 22px; }
.login-logo { width: 74px; height: 74px; margin: 0 auto; border-radius: 20px; display: grid; place-items: center; position: relative;
  background: linear-gradient(135deg, var(--primary), var(--accent)); font-size: 34px; color: #fff; box-shadow: 0 10px 30px color-mix(in srgb, var(--primary) 45%, transparent); }
.login-logo .bolt { position: absolute; font-size: 15px; bottom: 9px; right: 9px; color: #fde047; }
#loginForm label { display: block; margin-bottom: 14px; font-weight: 500; }
#loginForm label > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.form-error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.demo-box { margin-top: 18px; font-size: 12.5px; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 12px; }
.demo-box summary { cursor: pointer; }
.demo-box table { width: 100%; margin-top: 8px; font-family: 'JetBrains Mono', monospace; }
.demo-box td { padding: 3px 6px; }

/* ===================== SHELL ===================== */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 250px; flex-shrink: 0; background: var(--bg2); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30; transition: transform .25s; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--border); }
.brand i { font-size: 22px; color: var(--primary); }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 500; position: relative; }
.nav a i { width: 18px; text-align: center; }
.nav a:hover { background: var(--card); color: var(--text); }
.nav a.active { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.nav a.active::before { content: ""; position: absolute; inset-inline-start: -10px; top: 8px; bottom: 8px; width: 3px; background: var(--primary); border-radius: 3px; }
.nav-badge { margin-inline-start: auto; background: var(--danger); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.nav-badge:empty { display: none; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.live-dot { display: flex; align-items: center; gap: 8px; color: var(--ok); }
.live-dot span { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 70%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: color-mix(in srgb, var(--bg2) 85%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar-right { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.clock { font-family: 'JetBrains Mono', monospace; color: var(--muted); font-size: 12.5px; }
#menuToggle { display: none; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 6px; border: 1px solid var(--border); border-radius: 30px; background: var(--card); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta small { color: var(--muted); font-size: 11px; text-transform: capitalize; }

.content { padding: 22px; flex: 1; }
.view { animation: fade .25s; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===================== CARDS / KPI ===================== */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.card.no-pad { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 15px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 18px; }
.chart-box { position: relative; height: 270px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; position: relative; overflow: hidden; box-shadow: var(--shadow); }
.kpi::after { content: ""; position: absolute; inset-inline-end: -20px; top: -20px; width: 90px; height: 90px; border-radius: 50%; background: var(--c, var(--primary)); opacity: .1; }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .kpi-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--c, var(--primary)) 18%, transparent); color: var(--c, var(--primary)); }
.kpi .kpi-val { font-size: 28px; font-weight: 700; margin-top: 6px; }
.kpi .kpi-val small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .kpi-sub { font-size: 12px; color: var(--muted); }
.progress { height: 6px; border-radius: 4px; background: var(--card2); overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--c, var(--primary)); border-radius: 4px; transition: width .5s; }

/* ===================== BADGES ===================== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; text-transform: capitalize; white-space: nowrap;
  background: color-mix(in srgb, var(--bc, var(--muted)) 18%, transparent); color: var(--bc, var(--muted)); border: 1px solid color-mix(in srgb, var(--bc, var(--muted)) 35%, transparent); }
.b-critical, .b-fault { --bc: var(--danger); }
.b-high { --bc: #f97316; }
.b-medium, .b-maintenance, .b-pending { --bc: var(--warn); }
.b-low, .b-info, .b-standby { --bc: var(--info); }
.b-running, .b-resolved, .b-closed, .b-active { --bc: var(--ok); }
.b-new, .b-open { --bc: var(--danger); }
.b-acknowledged, .b-in_progress { --bc: var(--primary); }
.b-inactive { --bc: var(--muted); }
.b-admin { --bc: var(--violet); } .b-analyst { --bc: var(--info); } .b-operator { --bc: var(--warn); } .b-viewer { --bc: var(--muted); }

/* ===================== TABLES ===================== */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: start; padding: 11px 14px; background: var(--card2); color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: color-mix(in srgb, var(--primary) 5%, transparent); }
.data-table td.actions { white-space: nowrap; text-align: end; }
.data-table .empty td { text-align: center; color: var(--muted); padding: 40px; }
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: start; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; color: var(--muted); font-size: 12.5px; }
.pager .btns { display: flex; gap: 6px; }

/* ===================== ALERTS / TURBINES ===================== */
.alert-list { display: flex; flex-direction: column; gap: 8px; max-height: 330px; overflow-y: auto; }
.alert-item { display: flex; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--card2); border-inline-start: 3px solid var(--bc, var(--muted)); align-items: flex-start; }
.alert-item .ai-body { flex: 1; min-width: 0; }
.alert-item .ai-title { font-weight: 600; font-size: 13px; }
.alert-item .ai-meta { color: var(--muted); font-size: 11.5px; }
.turbine-mini { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tm { background: var(--card2); border-radius: 10px; padding: 10px 12px; border-top: 3px solid var(--bc); }
.tm b { display: block; font-size: 13px; }
.tm .v { font-size: 18px; font-weight: 700; }

.turbine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.turbine-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); position: relative; }
.turbine-card .tc-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.fan { font-size: 30px; color: var(--bc); }
.fan.spin { animation: spin var(--spd, 2s) linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tc-head h4 { margin: 0; font-size: 15px; }
.tc-head small { color: var(--muted); }
.tc-head .badge { margin-inline-start: auto; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric { background: var(--card2); border-radius: 8px; padding: 8px; }
.metric small { display: block; color: var(--muted); font-size: 11px; }
.metric b { font-size: 15px; }
.metric.warn b { color: var(--warn); } .metric.bad b { color: var(--danger); }
.tc-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 12px; color: var(--muted); gap: 6px; flex-wrap: wrap; }

.ticket-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.ts { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; border-inline-start: 4px solid var(--bc); cursor: pointer; }
.ts b { font-size: 22px; display: block; }
.ts small { color: var(--muted); }

/* ===================== MODAL ===================== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 100; padding: 16px; backdrop-filter: blur(3px); }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: fade .2s; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.form-grid .full { grid-column: 1 / -1; }
.card .form-grid { grid-template-columns: 1fr; }
.switch-row { flex-direction: row !important; align-items: center; gap: 10px !important; }
.switch-row span { display: flex; flex-direction: column; color: var(--text); }
.perm-checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg2); }
.perm-checks label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 400; }
.comments { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; max-height: 220px; overflow-y: auto; }
.comment { background: var(--card2); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.comment small { color: var(--muted); display: block; font-size: 11px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.detail-grid div small { display: block; color: var(--muted); font-size: 11.5px; }

.theme-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; margin-top: 18px; }
.swatch { border: 2px solid var(--border); border-radius: 10px; padding: 8px; cursor: pointer; text-align: center; font-size: 12px; background: var(--card2); color: var(--text); }
.swatch.active { border-color: var(--primary); }
.swatch .sw { height: 30px; border-radius: 6px; margin-bottom: 6px; display: flex; overflow: hidden; }
.swatch .sw span { flex: 1; }
.profile-box { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--border); font-size: 13px; }
.profile-box div { display: flex; justify-content: space-between; padding: 4px 0; }
.profile-box div span { color: var(--muted); }

.empty-state { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-state i { font-size: 48px; color: var(--danger); }

/* ===================== TOASTS ===================== */
.toast-wrap { position: fixed; bottom: 20px; inset-inline-end: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--card); border: 1px solid var(--border); border-inline-start: 4px solid var(--bc, var(--primary)); padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); min-width: 240px; animation: fade .2s; font-size: 13px; }
.toast.ok { --bc: var(--ok); } .toast.err { --bc: var(--danger); } .toast.warn { --bc: var(--warn); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .sidebar { position: fixed; inset-inline-start: 0; transform: translateX(-100%); box-shadow: var(--shadow); }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: none !important; }
  #menuToggle { display: inline-block; }
  .user-meta, .clock, #exportAllBtn span { display: none; }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .form-grid, .perm-checks, .detail-grid { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .select { min-width: 0; flex: 1; }
}
