:root {
  --accent: #ff5a4d;          /* HAL eye */
  --accent-soft: rgba(255,90,77,.15);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", monospace;
}

/* ---- dark (default) ---- */
[data-theme="dark"] {
  --bg: #0b0e13;
  --bg-2: #121722;
  --panel: #161c28;
  --panel-2: #1d2534;
  --line: #263041;
  --text: #e6ecf5;
  --muted: #8a97ad;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}
/* ---- light ---- */
[data-theme="light"] {
  --bg: #eef1f6;
  --bg-2: #e4e8f0;
  --panel: #ffffff;
  --panel-2: #f4f6fa;
  --line: #d5dbe6;
  --text: #1a2230;
  --muted: #5c6980;
  --shadow: 0 10px 30px rgba(30,40,60,.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1100px 600px at 80% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.icon { display: block; }
a { color: inherit; text-decoration: none; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 58px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700;
  letter-spacing: 2px; color: var(--accent); }
.topnav { display: flex; gap: 6px; margin-left: 8px; }
.topnav a { padding: 7px 13px; border-radius: 9px; color: var(--muted);
  font-size: 14px; font-weight: 500; }
.topnav a:hover { color: var(--text); background: var(--panel-2); }
.topnav a.active { color: var(--text); background: var(--accent-soft); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-size: 13px; font-family: var(--mono); }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.iconbtn:hover { border-color: var(--accent); color: var(--accent); }
.show-light { display: none; }
[data-theme="light"] .show-dark { display: none; }
[data-theme="light"] .show-light { display: inline-flex; }

/* ---------- login ---------- */
.login-main { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 340px; max-width: 92vw; padding: 34px 30px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow); text-align: center;
}
.login-eye {
  width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: radial-gradient(circle at 50% 40%, #ff8a80, var(--accent) 60%, #7a1a12);
  box-shadow: 0 0 26px var(--accent-soft), 0 0 0 6px rgba(255,90,77,.08);
}
.login-card h1 { margin: 0; letter-spacing: 4px; font-size: 24px; }
.login-card .sub { margin: 4px 0 20px; color: var(--muted); font-size: 13px;
  text-transform: uppercase; letter-spacing: 2px; }
.login-card label { display: block; text-align: left; font-size: 12px;
  color: var(--muted); margin-bottom: 12px; }
.login-card input {
  width: 100%; margin-top: 5px; padding: 11px 12px; border-radius: 10px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  font-size: 15px; font-family: var(--mono);
}
.login-card input:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button[type=submit] {
  width: 100%; margin-top: 8px; padding: 12px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
  cursor: pointer; letter-spacing: .5px;
}
.login-card button[type=submit]:hover { filter: brightness(1.08); }
.error { background: rgba(255,90,77,.14); border: 1px solid var(--accent);
  color: var(--accent); padding: 9px; border-radius: 9px; font-size: 13px;
  margin-bottom: 16px; }
.corner { position: fixed; bottom: 18px; right: 18px; }

/* ---------- menu ---------- */
.menu-main { padding: 46px 24px; max-width: 1080px; margin: 0 auto; }
.menu-grid {
  display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.tile {
  display: flex; flex-direction: column; gap: 8px;
  padding: 30px 26px; min-height: 190px; justify-content: flex-end;
  background: linear-gradient(160deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .16s ease, border-color .16s ease;
}
.tile:hover { transform: translateY(-4px); border-color: var(--accent); }
.tile-icon { color: var(--accent); }
.tile-icon .icon { filter: drop-shadow(0 0 10px var(--accent-soft)); }
.tile-title { font-size: 21px; font-weight: 700; letter-spacing: .3px; }
.tile-desc { color: var(--muted); font-size: 13px; }
.tile::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius);
  background: radial-gradient(400px 200px at 100% 0, var(--accent-soft), transparent 70%);
  opacity: .6; pointer-events: none;
}

/* ---------- generic page ---------- */
.page-main { padding: 30px 24px; max-width: 1200px; margin: 0 auto; }
.page-h1 { margin: 0 0 22px; font-size: 26px; letter-spacing: .5px; }
.placeholder { color: var(--muted); padding: 60px; text-align: center;
  border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- AI console ---------- */
.ai-main { padding: 22px; max-width: 1000px; margin: 0 auto; }
.ai-wrap { display: flex; flex-direction: column; height: calc(100dvh - 58px - 44px); }
.ai-tabs { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.ai-tab {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 16px; border-radius: 12px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  position: relative; min-width: 160px;
}
.ai-tab:hover { border-color: var(--accent); }
.ai-tab.active { border-color: var(--accent); background: var(--accent-soft); }
.ai-tab-dot { position: absolute; top: 12px; right: 12px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--muted); }
.ai-tab.active .ai-tab-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.ai-tab-label { font-weight: 700; font-size: 15px; }
.ai-tab-model { font-size: 12px; color: var(--muted); font-family: var(--mono); }

.chat { flex: 1; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; padding: 20px; display: flex;
  flex-direction: column; gap: 14px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 78%; padding: 11px 14px; border-radius: 13px;
  white-space: pre-wrap; word-wrap: break-word; line-height: 1.5; font-size: 14.5px; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--panel-2); border: 1px solid var(--line);
  border-bottom-left-radius: 4px; }
.bubble.streaming::after { content: "▋"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.chat-input { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--line);
  background: var(--panel); }
.chat-input textarea { flex: 1; resize: none; padding: 11px 13px; border-radius: 11px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 14.5px; line-height: 1.4; }
.chat-input textarea:focus { outline: none; border-color: var(--accent); }
.chat-input button { padding: 0 20px; border: 0; border-radius: 11px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.chat-input button:disabled { opacity: .5; cursor: default; }

/* ---------- 2FA wait / done ---------- */
.login-eye.pulse { animation: eyepulse 1.6s ease-in-out infinite; }
@keyframes eyepulse { 0%,100% { box-shadow: 0 0 20px var(--accent-soft), 0 0 0 4px rgba(255,90,77,.06); }
  50% { box-shadow: 0 0 40px var(--accent), 0 0 0 10px rgba(255,90,77,.12); } }
.wait-spinner { width: 34px; height: 34px; margin: 20px auto 14px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.wait-msg { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.wait-cancel { color: var(--muted); font-size: 13px; text-decoration: underline; }
.wait-cancel:hover { color: var(--accent); }
.done-mark { width: 64px; height: 64px; margin: 4px auto 14px; border-radius: 50%;
  display: grid; place-items: center; font-size: 32px; font-weight: 700; }
.done-mark.ok { background: rgba(80,200,120,.15); color: #46d17f; border: 1px solid #46d17f; }
.done-mark.bad { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); }

/* ---------- CCTV ---------- */
.cctv-grid { display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cctv-tile { padding: 0; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; background: #000; position: relative;
  box-shadow: var(--shadow); transition: transform .15s, border-color .15s; }
.cctv-tile:hover { transform: translateY(-3px); border-color: var(--accent); }
.cctv-thumb { display: block; width: 100%; aspect-ratio: 16/9; object-fit: cover;
  background: #0a0d12; }
.cctv-cap { position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  font-weight: 600; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.cctv-dot { width: 9px; height: 9px; border-radius: 50%; background: #46d17f;
  box-shadow: 0 0 8px #46d17f; }
.cctv-play { margin-left: auto; font-size: 12px; color: var(--accent);
  background: rgba(0,0,0,.5); padding: 3px 9px; border-radius: 20px; }
.cctv-modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(0,0,0,.82); padding: 20px; }
.cctv-modal[hidden] { display: none; }
.cctv-modal-inner { width: min(1100px, 96vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.cctv-modal-bar { display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.cctv-live { display: block; width: 100%; max-height: 78vh; object-fit: contain; background: #000; }

/* ---------- Network status ---------- */
.net-head { display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 8px; }
.net-meta { display: flex; align-items: center; gap: 14px; }
.net-summary { font-weight: 700; font-family: var(--mono); padding: 4px 12px;
  border-radius: 20px; background: var(--panel-2); border: 1px solid var(--line); }
.net-summary.ok { color: #46d17f; border-color: #46d17f; }
.net-summary.warn { color: var(--accent); border-color: var(--accent); }
.net-updated { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.net-groups { display: grid; gap: 22px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin-top: 8px; }
.net-group { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.net-group-title { margin: 0; padding: 12px 16px; font-size: 13px; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line);
  background: var(--panel-2); }
.net-rows { display: flex; flex-direction: column; }
.net-row { display: flex; align-items: center; gap: 12px; padding: 11px 16px;
  border-bottom: 1px solid var(--line); }
.net-row:last-child { border-bottom: 0; }
.net-status-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.net-row.up .net-status-dot { background: #46d17f; box-shadow: 0 0 8px #46d17f; }
.net-row.down .net-status-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent);
  animation: blink 1.2s steps(2) infinite; }
.net-name { font-weight: 600; }
.net-addr { color: var(--muted); font-size: 12px; font-family: var(--mono); margin-left: auto; }
.net-latency { font-family: var(--mono); font-size: 12.5px; min-width: 62px; text-align: right; }
.net-row.up .net-latency { color: var(--muted); }
.net-row.down .net-latency { color: var(--accent); font-weight: 700; }

/* ---------- Server status ---------- */
.srv-grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-top: 8px; }
.srv-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); }
.srv-card.span-all { grid-column: 1 / -1; }
.srv-card.span-2 { grid-column: span 2; }
@media (max-width: 720px) { .srv-card.span-2 { grid-column: 1 / -1; } }
.srv-card-title { margin: 0 0 14px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.gauge-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.gauge { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.gauge-ring { --p: 0; width: 120px; height: 120px; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(closest-side, var(--panel) 74%, transparent 75% 100%),
    conic-gradient(var(--g, var(--accent)) calc(var(--p) * 1%), var(--line) 0); }
.gauge-ring.ok   { --g: #46d17f; }
.gauge-ring.warn { --g: #f5b445; }
.gauge-ring.crit { --g: var(--accent); }
.gauge-val { font-size: 26px; font-weight: 700; font-family: var(--mono); }
.gauge-val span { font-size: 13px; color: var(--muted); }
.gauge-label { font-weight: 700; letter-spacing: .5px; }
.gauge-sub { font-size: 11.5px; color: var(--muted); font-family: var(--mono); text-align: center; }
.stat-line { display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.stat-line:last-child { border-bottom: 0; }
.stat-line span { color: var(--muted); }
.stat-line b { font-family: var(--mono); font-weight: 600; }
.stat-line b.warn { color: #f5b445; } .stat-line b.crit { color: var(--accent); } .stat-line b.ok { color: var(--text); }
.meter-row { margin: 12px 0; }
.meter-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.meter-right { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.meter { height: 9px; background: var(--bg-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.meter-fill { height: 100%; border-radius: 6px; transition: width .5s ease; }
.meter-fill.ok { background: #46d17f; } .meter-fill.warn { background: #f5b445; } .meter-fill.crit { background: var(--accent); }

/* ---------- OpenClaw button on AI page ---------- */
.ai-openclaw {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 16px; border-radius: 12px; cursor: pointer;
  min-width: 160px; position: relative; text-decoration: none;
  color: #fff; background: linear-gradient(150deg, var(--accent), #b3271c);
  border: 1px solid var(--accent);
  box-shadow: 0 4px 16px var(--accent-soft);
  transition: transform .15s ease, filter .15s ease;
}
.ai-openclaw:hover { transform: translateY(-2px); filter: brightness(1.08); }
.ai-openclaw .ai-tab-label { color: #fff; }
.ai-openclaw .ai-tab-model { color: rgba(255,255,255,.8); }
.ai-openclaw-mark { position: absolute; top: 10px; right: 12px; font-size: 14px;
  color: rgba(255,255,255,.9); }
.ai-openclaw-tip {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 40;
  width: 330px; padding: 11px 13px; border-radius: 10px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 12px; line-height: 1.55; font-weight: 400; text-align: left;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s;
  pointer-events: none; cursor: default; white-space: normal;
}
.ai-openclaw:hover .ai-openclaw-tip,
.ai-openclaw:focus-visible .ai-openclaw-tip { opacity: 1; visibility: visible; transform: translateY(0); }
.ai-openclaw-tip b { color: var(--accent); }
.ai-openclaw-tip code { font-family: var(--mono); font-size: 11px; }
