/* portal — shared styles (admin + friend). Dark, minimal, no frameworks. */
:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #0f1319;
  --text: #e6edf3;
  --muted: #8b949e;
  --border: #30363d;
  --green: #3fb950;
  --gray: #6e7681;
  --amber: #d29922;
  --red: #f85149;
  --blue: #58a6ff;
  --accent: #2f81f7;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* layout */
header.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
header.top h1 { font-size: 18px; margin: 0; font-weight: 600; }
header.top .sub { color: var(--muted); font-size: 14px; }
main { max-width: 1080px; margin: 0 auto; padding: 24px; }

section { margin-bottom: 28px; }
section > h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 10px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; gap: 10px; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* state pills */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-ready { color: var(--green); border-color: rgba(63, 185, 80, 0.4); background: rgba(63, 185, 80, 0.12); }
.pill-stopped { color: var(--gray); border-color: rgba(110, 118, 129, 0.5); background: rgba(110, 118, 129, 0.15); }
.pill-creating { color: var(--amber); border-color: rgba(210, 153, 34, 0.5); background: rgba(210, 153, 34, 0.12); }
.pill-error, .pill-deleting { color: var(--red); border-color: rgba(248, 81, 73, 0.5); background: rgba(248, 81, 73, 0.12); }
.pill-unknown { color: var(--muted); border-color: var(--border); }

/* agent health dot */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.dot-up { background: var(--green); box-shadow: 0 0 5px rgba(63, 185, 80, 0.7); }
.dot-down { background: var(--red); }
.dot-unknown { background: var(--gray); }

/* progress bars */
.bar { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; height: 10px; overflow: hidden; min-width: 110px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.bar-warn > i { background: var(--amber); }
.bar-crit > i { background: var(--red); }
.bar-label { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* forms + buttons */
form.inline, .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="number"] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
}
input:focus { outline: 1px solid var(--accent); }
button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--blue); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--red); border-color: rgba(248, 81, 73, 0.5); }
button.danger:hover:not(:disabled) { border-color: var(--red); background: rgba(248, 81, 73, 0.12); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* errors + messages */
.error {
  color: var(--red);
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.4);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}
.error:empty { display: none; }
.ok-msg { color: var(--green); font-size: 13px; }

/* one-shot plaintext key */
.key-once {
  border: 1px solid var(--red);
  background: rgba(248, 81, 73, 0.08);
  border-radius: 8px;
  padding: 14px;
}
.key-once .warn { color: var(--red); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.key-once .value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 10px 0;
  word-break: break-all;
  user-select: all;
}
.key-once .note { color: var(--muted); font-size: 12px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs button {
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
}
.tabs button.active { background: var(--panel); border-color: var(--border); color: var(--text); }
.workspace-tabs { margin-bottom: 0; }
.workspace-tabs button { font-size: 15px; padding: 10px 22px; }
.tab-panel { flex: 1; min-height: 0; display: none; }
.tab-panel.active { display: block; }
.tab-panel > iframe {
  width: 100%;
  height: calc(100vh - 220px);
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  background: #fff;
}

/* workspace (friend) layout */
.workspace-body { display: flex; flex-direction: column; min-height: calc(100vh - 90px); }

/* stopped-state start-it view */
.start-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 55vh;
  text-align: center;
}
.start-view p { color: var(--muted); margin: 0; }
.start-view button { font-size: 16px; padding: 12px 28px; }

/* key block (admin detail) */
.key-block .kv { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.key-block .kv span.k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; min-width: 110px; }

/* components map */
.comp { font-size: 12px; }
.comp .ok { color: var(--green); }
.comp .bad { color: var(--red); }

/* delete */
.delete-zone { border-color: rgba(248, 81, 73, 0.45); }
.delete-zone input { max-width: 320px; }

/* event log */
.event-ok { color: var(--green); }
.event-bad { color: var(--red); }

@media (max-width: 640px) {
  main { padding: 16px; }
  header.top { padding: 12px 16px; }
  th, td { padding: 6px 6px; }
}

/* ---- friend terminal page (xterm) ---- */
body.terminal-page{margin:0;height:100vh;display:flex;flex-direction:column;background:#0b0e14}
.term-status{padding:6px 10px;font:12px/1.4 ui-monospace,Menlo,Consolas,monospace;color:#8b949e;background:#11151c;border-bottom:1px solid #1f2630}
.term-status.ok{color:#3fb950}
.term-status.err{color:#f85149}
#term{flex:1;min-height:0;padding:6px 8px}
#term .xterm{height:100%}

/* workspace tabs: iframe fills the panel */
.tab-panel iframe{width:100%;height:calc(100vh - 130px);border:1px solid #21262d;border-radius:6px}

/* ---- friend Agent chat (native widget; replaces the opencode iframe) ---- */
.chat-view { display: flex; flex-direction: column; height: calc(100vh - 130px); min-height: 420px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.chat-top { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.chat-top select { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 13px; }
.chat-top .ghost { border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 6px; padding: 5px 12px; font-size: 12px; cursor: pointer; }
.chat-top .ghost:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.chat-top .ghost:disabled { opacity: 0.4; cursor: default; }
.chat-msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; }
.msg-user { align-self: flex-end; }
.msg-assistant { align-self: flex-start; }
.bubble { padding: 9px 13px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; font-size: 14px; }
.msg-user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-assistant .bubble { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); display: inline-block; animation: chdot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes chdot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.chat-inputrow { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--panel-2); align-items: flex-end; }
.chat-inputrow textarea { flex: 1; resize: none; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; font-size: 14px; font-family: inherit; line-height: 1.4; max-height: 160px; }
.chat-inputrow textarea:focus { outline: none; border-color: var(--accent); }
.chat-inputrow .primary { height: 38px; }
.chat-hint { font-size: 12px; padding: 4px 14px 8px; color: var(--muted); }
.chat-hint.err { color: var(--red); }
