:root {
  --bg: #05070d;
  --bg1: #090d17;
  --bg2: #0e1422;
  --bg3: #151d30;
  --line: #1d2941;
  --line2: #2a3a5b;
  --text: #d7e2f4;
  --muted: #7d8fab;
  --faint: #41516e;
  --green: #36f3a5;
  --blue: #51a7ff;
  --red: #ff5877;
  --amber: #ffbf55;
  --shadow: 0 20px 70px rgba(0, 0, 0, .35);
  --ui: "Syne", sans-serif;
  --mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 10%, rgba(54, 243, 165, .12), transparent 28rem),
    radial-gradient(circle at 88% 0%, rgba(81, 167, 255, .16), transparent 34rem),
    linear-gradient(135deg, #04050a, #080b13 45%, #070913);
  font-family: var(--ui);
  overflow: hidden;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

.shell { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(9, 13, 23, .92);
  backdrop-filter: blur(18px);
}

.brand { display: flex; gap: 13px; align-items: center; padding: 22px 18px; border-bottom: 1px solid var(--line); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  color: #02120b; font-weight: 900; font-size: 1.1rem;
  background: linear-gradient(135deg, var(--green), var(--blue));
  box-shadow: 0 0 30px rgba(54, 243, 165, .22);
}
.brand-name { color: #fff; font-size: 1.05rem; font-weight: 800; letter-spacing: .01em; }
.brand-sub { color: var(--green); font-family: var(--mono); font-size: .62rem; text-transform: uppercase; letter-spacing: .12em; margin-top: 2px; }

.nav { padding: 14px 10px; display: grid; gap: 4px; }
.nav-item {
  width: 100%;
  display: flex; align-items: center; gap: 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  padding: 11px 12px;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  font-weight: 700;
  transition: .16s ease;
}
.nav-item span { color: var(--faint); font-family: var(--mono); font-size: .65rem; min-width: 22px; }
.nav-item:hover { color: var(--text); background: var(--bg2); }
.nav-item.active {
  color: var(--green);
  border-color: rgba(54, 243, 165, .22);
  background: linear-gradient(135deg, rgba(54, 243, 165, .10), rgba(81, 167, 255, .08));
}

.sidebar-bottom { margin-top: auto; padding: 14px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.connection-card {
  display: flex; gap: 10px; align-items: center;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg2);
}
.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); box-shadow: 0 0 14px rgba(255, 88, 119, .55); }
.connection-dot.ok { background: var(--green); box-shadow: 0 0 14px rgba(54, 243, 165, .55); }
.connection-title { font-weight: 800; color: #fff; font-size: .78rem; }
.connection-meta { color: var(--muted); font-family: var(--mono); font-size: .62rem; margin-top: 2px; }

.main { overflow: auto; height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 26px;
  background: rgba(5, 7, 13, .78);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 2px 0 0; color: #fff; font-size: 1.18rem; letter-spacing: -.02em; }
.eyebrow { color: var(--green); font-family: var(--mono); font-size: .62rem; text-transform: uppercase; letter-spacing: .14em; }
.topbar-actions { display: flex; gap: 9px; align-items: center; }

.page { display: none; padding: 24px 26px 38px; animation: rise .28s ease; }
.page.active { display: block; }
.chat-page.active { display: block; height: calc(100vh - 78px); padding: 18px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.btn {
  border: 0; border-radius: 10px; padding: 9px 14px;
  cursor: pointer; font-weight: 800; font-size: .78rem;
  transition: .16s ease;
}
.btn.primary { color: #04110b; background: var(--green); box-shadow: 0 8px 28px rgba(54, 243, 165, .18); }
.btn.primary:hover { transform: translateY(-1px); background: #5dffba; }
.btn.ghost { color: var(--muted); background: var(--bg2); border: 1px solid var(--line2); }
.btn.ghost:hover { color: #fff; border-color: var(--blue); }
.btn.full { width: 100%; }
.btn.danger { background: rgba(255, 88, 119, .10); color: var(--red); border: 1px solid rgba(255, 88, 119, .28); }
.mini-link {
  border: 0; background: transparent; color: var(--blue); cursor: pointer;
  font-family: var(--mono); font-size: .68rem; font-weight: 700;
}

.hero-panel {
  display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(54, 243, 165, .10), transparent 38%),
    linear-gradient(160deg, rgba(81, 167, 255, .10), rgba(9, 13, 23, .90));
  border-radius: 24px;
  padding: 26px;
  box-shadow: var(--shadow);
}
.hero-panel h2 { margin: 6px 0 10px; max-width: 800px; color: #fff; font-size: clamp(1.65rem, 4vw, 3.2rem); line-height: .98; letter-spacing: -.05em; }
.hero-panel p { max-width: 700px; margin: 0; color: var(--muted); line-height: 1.65; }
.hero-status { display: grid; gap: 8px; align-content: end; }
.status-line {
  display: flex; justify-content: space-between; gap: 14px;
  border: 1px solid var(--line);
  background: rgba(5, 7, 13, .46);
  border-radius: 13px;
  padding: 11px 12px;
  font-family: var(--mono);
  font-size: .72rem;
}
.status-line span { color: var(--faint); }
.status-line strong { color: #fff; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin: 18px 0; }
.stat-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 17px;
  background: rgba(9, 13, 23, .80);
  position: relative;
  overflow: hidden;
}
.stat-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, transparent, var(--green), transparent); }
.stat-card span, .stat-card small { display: block; color: var(--muted); font-family: var(--mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; }
.stat-card strong { display: block; margin: 8px 0 3px; color: #fff; font-family: var(--mono); font-size: 1.8rem; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(9, 13, 23, .82);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 16px; border-bottom: 1px solid var(--line); }
.panel-head.compact { padding: 13px 14px; }
.panel h3, .section-head h2 { margin: 0; color: #fff; }
.section-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-end; margin-bottom: 16px; }
.section-head p { color: var(--muted); margin: 7px 0 0; }
.list { display: grid; }
.row {
  display: grid; gap: 8px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
}
.row.as-button {
  width: 100%;
  border-width: 0 0 1px;
  border-style: solid;
  border-color: var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.row.as-button:hover,
.row.as-button.selected {
  background: rgba(81, 167, 255, .07);
}
.row:last-child { border-bottom: 0; }
.row-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-title { color: #fff; font-weight: 800; }
.row-meta { color: var(--muted); font-family: var(--mono); font-size: .66rem; line-height: 1.6; }
.badge { border-radius: 999px; padding: 3px 8px; font-family: var(--mono); font-size: .62rem; font-weight: 800; white-space: nowrap; }
.badge.ok { color: var(--green); background: rgba(54, 243, 165, .10); border: 1px solid rgba(54, 243, 165, .25); }
.badge.info { color: var(--blue); background: rgba(81, 167, 255, .10); border: 1px solid rgba(81, 167, 255, .25); }
.badge.warn { color: var(--amber); background: rgba(255, 191, 85, .10); border: 1px solid rgba(255, 191, 85, .25); }
.badge.bad { color: var(--red); background: rgba(255, 88, 119, .10); border: 1px solid rgba(255, 88, 119, .25); }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card {
  border: 1px solid var(--line);
  border-radius: 19px;
  padding: 16px;
  background: rgba(9, 13, 23, .82);
  box-shadow: var(--shadow);
}
.card-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.avatar {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 900; color: #06130d;
  background: linear-gradient(135deg, var(--green), var(--blue));
}
.card-title-line { display: flex; gap: 10px; align-items: center; margin-bottom: 3px; }
.card h3 { margin: 0; color: #fff; font-size: .98rem; }
.card p { color: var(--muted); line-height: 1.55; font-size: .78rem; margin: 10px 0; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 13px; }
.tool-chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .62rem;
  margin: 3px 4px 0 0;
}

.switch {
  width: 42px; height: 24px;
  border: 1px solid var(--line2);
  border-radius: 999px;
  background: var(--bg3);
  padding: 3px;
  cursor: pointer;
}
.switch span { display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .16s ease; }
.switch.on { background: var(--green); }
.switch.on span { transform: translateX(18px); }

.tools-grid .card { min-height: 210px; }
.task-board { display: grid; grid-template-columns: 420px 1fr; gap: 16px; align-items: start; }
.task-detail { min-height: 520px; padding: 18px; }
.task-output {
  white-space: pre-wrap;
  color: var(--text);
  background: #03050a;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  font-family: var(--mono);
  font-size: .76rem;
  line-height: 1.7;
}
.empty { color: var(--faint); padding: 26px; text-align: center; }

.chat-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 14px; height: 100%; }
.chat-main, .conversation-list {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(9, 13, 23, .84);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-main { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.chat-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.chat-head h3 { margin: 0; color: #fff; }
.chat-head p { margin: 4px 0 0; color: var(--muted); font-family: var(--mono); font-size: .66rem; }
.messages { min-height: 0; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.message { max-width: 82%; display: flex; flex-direction: column; gap: 4px; animation: rise .2s ease; }
.message.user { align-self: flex-end; }
.bubble {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--text);
  background: var(--bg2);
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: .84rem;
}
.message.user .bubble { color: #04110b; background: var(--green); border-color: var(--green); }
.message-meta { color: var(--faint); font-family: var(--mono); font-size: .6rem; }
.message.user .message-meta { text-align: right; }
.composer { display: flex; gap: 10px; align-items: flex-end; padding: 13px; border-top: 1px solid var(--line); }
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 46px;
  max-height: 160px;
  border: 1px solid var(--line2);
  background: var(--bg2);
  color: #fff;
  border-radius: 14px;
  outline: 0;
  padding: 12px 13px;
  line-height: 1.45;
}
.composer textarea:focus { border-color: var(--green); }
.send {
  border: 0; border-radius: 13px;
  height: 46px; padding: 0 17px;
  color: #04110b; background: var(--green);
  font-weight: 900; cursor: pointer;
}

.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 90;
  transform: translateY(20px);
  opacity: 0; pointer-events: none;
  border: 1px solid var(--line2);
  background: var(--bg1);
  color: #fff;
  border-radius: 13px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: .18s ease;
  max-width: 360px;
}
.toast.show { opacity: 1; transform: none; }

.modal { border: 0; padding: 0; background: transparent; color: var(--text); }
.modal::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(5px); }
.modal-card {
  width: min(540px, calc(100vw - 28px));
  border: 1px solid var(--line2);
  border-radius: 20px;
  background: var(--bg1);
  padding: 18px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}
.modal-card.wide { width: min(760px, calc(100vw - 28px)); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.modal-head h3 { margin: 0; color: #fff; }
.icon-btn {
  border: 1px solid var(--line2);
  background: var(--bg2);
  color: var(--muted);
  border-radius: 10px;
  width: 32px; height: 32px;
  cursor: pointer;
}
label { color: var(--muted); font-family: var(--mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line2);
  background: var(--bg2);
  color: #fff;
  border-radius: 12px;
  outline: 0;
  padding: 10px 12px;
}
input:focus, textarea:focus { border-color: var(--green); }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 6px; }
.picker { display: flex; gap: 8px; flex-wrap: wrap; }
.pick {
  border: 1px solid var(--line2);
  background: var(--bg2);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: .68rem;
}
.pick.selected { color: var(--green); border-color: rgba(54, 243, 165, .45); background: rgba(54, 243, 165, .10); }

@media (max-width: 980px) {
  body { overflow: auto; }
  .shell { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .sidebar { position: sticky; top: 0; z-index: 30; }
  .brand { padding: 12px 14px; }
  .nav { display: flex; overflow-x: auto; padding: 8px; }
  .nav-item { min-width: 150px; }
  .sidebar-bottom { display: none; }
  .main { height: auto; min-height: 100vh; }
  .hero-panel, .grid-2, .task-board, .chat-wrap { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chat-page.active { height: auto; min-height: 720px; }
  .conversation-list { min-height: 260px; }
}

@media (max-width: 640px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; }
  .page { padding: 18px 14px 30px; }
  .stats-grid { grid-template-columns: 1fr; }
  .section-head { align-items: stretch; flex-direction: column; }
  .message { max-width: 95%; }
}

/* ═══════════════════════════════════════════
   OpenClaw section
═══════════════════════════════════════════ */

#page-openclaw { padding: 0; overflow: hidden; }

.oc-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100%;
  overflow: hidden;
}

/* Left column */
.oc-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 20px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.oc-server-panel { flex-shrink: 0; }

.oc-server-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0 14px;
}

.oc-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.oc-badge.online  { background: rgba(54,243,165,.15); color: var(--green); border: 1px solid rgba(54,243,165,.3); }
.oc-badge.offline { background: rgba(255,88,119,.15); color: var(--red);   border: 1px solid rgba(255,88,119,.3); }
.oc-badge.unknown { background: rgba(255,191,85,.12); color: var(--amber); border: 1px solid rgba(255,191,85,.3); }

.oc-server-meta { font-size: .8rem; color: var(--muted); line-height: 1.4; }

/* Remote agent chips */
.oc-remote-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--bg2);
  border: 1px solid var(--line);
  font-size: .82rem;
  font-family: var(--mono);
}
.oc-remote-chip .chip-id { color: var(--green); font-weight: 600; }
.oc-remote-chip .chip-status { margin-left: auto; font-size: .72rem; color: var(--muted); }

/* Bridge list items */
.oc-bridge-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg2);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color .18s, background .18s;
}
.oc-bridge-item:hover,
.oc-bridge-item.active { border-color: var(--blue); background: rgba(81,167,255,.06); }
.oc-bridge-item .bridge-id { font-family: var(--mono); font-size: .85rem; color: var(--text); }
.oc-bridge-item .bridge-sync { margin-left: auto; font-size: .7rem; font-family: var(--mono); }
.bridge-sync.synced  { color: var(--green); }
.bridge-sync.pending { color: var(--amber); }
.bridge-sync.failed  { color: var(--red); }

.oc-bridge-actions { display: flex; gap: 6px; margin-top: 6px; }

/* Right column */
.oc-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.oc-sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.oc-sessions-header h3 { margin: 0 0 2px; font-size: 1rem; }
.oc-sessions-header p  { margin: 0; font-size: .8rem; color: var(--muted); }

.oc-chat-wrap {
  display: grid;
  grid-template-columns: 240px 1fr;
  flex: 1;
  overflow: hidden;
}

.oc-session-list {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.oc-session-item {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color .18s, background .18s;
}
.oc-session-item:hover { background: var(--bg2); border-color: var(--line); }
.oc-session-item.active { background: rgba(81,167,255,.08); border-color: var(--blue); }
.oc-session-item .s-agent { font-size: .72rem; font-family: var(--mono); color: var(--blue); margin-bottom: 3px; }
.oc-session-item .s-title { font-size: .84rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oc-session-item .s-status { font-size: .68rem; color: var(--muted); margin-top: 3px; font-family: var(--mono); }

/* Active chat area */
.oc-chat-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.oc-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.oc-chat-head strong { font-size: .95rem; }

.oc-status-chip {
  display: inline-block;
  margin-left: 10px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .68rem;
  font-family: var(--mono);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  vertical-align: middle;
}
.oc-status-chip[data-status="open"]    { background: rgba(54,243,165,.15); color: var(--green); }
.oc-status-chip[data-status="waiting"] { background: rgba(255,191,85,.12); color: var(--amber); }
.oc-status-chip[data-status="closed"]  { background: rgba(125,143,171,.1); color: var(--muted); }
.oc-status-chip[data-status="error"]   { background: rgba(255,88,119,.15); color: var(--red);   }

.oc-messages { flex: 1; }

/* small/full button modifiers */
.btn.small { padding: 5px 12px; font-size: .78rem; }
.btn.full  { width: 100%; justify-content: center; }

/* ═══════════════════════════════════════════
   Login screen
═══════════════════════════════════════════ */

.login-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 18% 10%, rgba(54, 243, 165, .12), transparent 28rem),
    radial-gradient(circle at 88% 0%, rgba(81, 167, 255, .16), transparent 34rem),
    linear-gradient(135deg, #04050a, #080b13 45%, #070913);
}
.login-screen.hidden { display: none; }

.login-card {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--line2);
  border-radius: 24px;
  background: rgba(9, 13, 23, .92);
  backdrop-filter: blur(18px);
  padding: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 20px;
}

.login-brand { display: flex; gap: 13px; align-items: center; }

.login-form { display: grid; gap: 10px; }
.login-form button { margin-top: 6px; }

.login-error {
  background: rgba(255, 88, 119, .10);
  border: 1px solid rgba(255, 88, 119, .28);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--red);
  font-size: .82rem;
  line-height: 1.5;
}

/* User row in sidebar bottom */
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.user-name {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--green);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
