/* Hermes Painel — vanilla, dark-first, zero deps */
:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1d2230;
  --line: #2a3142;
  --fg: #e5e9f0;
  --fg-dim: #9aa3b2;
  --fg-faint: #5d6675;
  --accent: #7c9eff;
  --accent-2: #5b7dff;
  --ok: #3ecf8e;
  --warn: #f5a524;
  --err: #ff5d5d;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

/* ============== TOPBAR ============== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 22px; color: var(--accent); }
.brand .title { font-weight: 600; }
.brand .sub { color: var(--fg-faint); font-size: 12px; font-family: var(--mono); margin-left: 6px; }

.status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--fg-dim);
  padding: 4px 10px; border-radius: 999px; background: var(--bg-3);
}
.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-faint);
}
.status[data-state="ok"] .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status[data-state="err"] .dot { background: var(--err); box-shadow: 0 0 8px var(--err); }
.status[data-state="loading"] .dot { background: var(--warn); animation: pulse 1.2s infinite; }

@keyframes pulse { 50% { opacity: 0.3; } }

/* ============== TABS ============== */
.tabs {
  display: flex; gap: 0;
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--fg-dim);
  padding: 12px 18px; cursor: pointer; font-size: 14px;
  font-family: inherit;
}
.tab:hover { color: var(--fg); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ============== MAIN ============== */
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel { display: none; flex: 1; min-height: 0; padding: 16px; overflow: auto; }
.panel.active { display: flex; flex-direction: column; }

/* ============== CHAT ============== */
.chat-toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 8px 12px; margin-bottom: 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px;
}
.chat-toolbar label { display: flex; align-items: center; gap: 6px; color: var(--fg-dim); }
.chat-toolbar label.check { gap: 4px; }

.chat-log {
  flex: 1; min-height: 300px; max-height: calc(100vh - 320px);
  overflow-y: auto;
  padding: 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 14px;
}
.msg { margin-bottom: 14px; max-width: 90%; }
.msg .role {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--fg-faint); margin-bottom: 2px;
}
.msg .body {
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--bg-3); border: 1px solid var(--line);
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.user { margin-left: auto; }
.msg.user .body { background: rgba(124,158,255,0.10); border-color: rgba(124,158,255,0.3); }
.msg.assistant .body { background: var(--bg-3); }
.msg.system .body {
  background: rgba(245,165,36,0.10); border-color: rgba(245,165,36,0.3);
  color: var(--warn); font-style: italic;
}
.msg.error .body {
  background: rgba(255,93,93,0.10); border-color: rgba(255,93,93,0.3);
  color: var(--err);
}
.msg .meta {
  font-size: 11px; color: var(--fg-faint); margin-top: 4px;
  font-family: var(--mono);
}

.chat-input {
  display: flex; gap: 8px; margin-top: 12px;
  align-items: flex-end;
}
.chat-input textarea {
  flex: 1; resize: vertical; min-height: 60px; max-height: 240px;
  padding: 10px 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--fg); font: inherit;
  outline: none;
}
.chat-input textarea:focus { border-color: var(--accent); }

/* ============== TABLES ============== */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.hint { color: var(--fg-faint); font-size: 12px; margin-left: auto; }
.table-wrap {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: auto; flex: 1; min-height: 200px;
}
.table-wrap.small { max-height: calc(100vh - 280px); }
.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th, .grid td {
  text-align: left; padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.grid th {
  background: var(--bg-3);
  position: sticky; top: 0;
  color: var(--fg-dim);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.grid tr:last-child td { border-bottom: 0; }
.grid .empty { text-align: center; color: var(--fg-faint); padding: 24px; }
.grid code { font-family: var(--mono); font-size: 12px; color: var(--fg-dim); }
.grid .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.grid .truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============== GRID 2 ============== */
.grid-2 {
  display: grid; gap: 16px;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.grid-2 h3 { margin: 0 0 8px; font-size: 14px; color: var(--fg-dim); display: flex; align-items: center; gap: 8px; }

/* ============== KV ============== */
.kv { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 0; }
.kv-row { display: flex; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.kv-row:last-child { border-bottom: 0; }
.kv-row > span { width: 160px; color: var(--fg-faint); font-size: 12px; }
.kv-row > b { font-weight: 500; font-family: var(--mono); font-size: 13px; }

h3 { font-size: 14px; color: var(--fg-dim); margin: 18px 0 6px; }
.code {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; word-wrap: break-word; color: var(--fg-dim);
  max-height: 480px; overflow: auto;
}

/* ============== BUTTONS ============== */
button {
  font-family: inherit; font-size: 13px;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
button:hover { background: #242a3a; border-color: #3a4256; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
button.ghost { background: transparent; }
button.danger { background: var(--err); color: #fff; border-color: var(--err); }

input[type="text"], input[type="password"], select, textarea {
  font-family: inherit; font-size: 13px;
  background: var(--bg-2); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 10px; outline: none;
}
input[type="text"]:focus, input[type="password"]:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
select { min-width: 180px; }
textarea { font-family: var(--mono); }

/* ============== MODAL ============== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  width: 90%; max-width: 640px; max-height: 80vh; overflow: auto;
  display: flex; flex-direction: column;
}
.modal.small { max-width: 420px; }
.modal header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.modal header h3 { margin: 0; color: var(--fg); font-size: 15px; }
.modal-body { padding: 16px; flex: 1; overflow: auto; }
.modal-body p { margin: 0 0 8px; color: var(--fg-dim); }
.modal-body p.hint { font-size: 12px; color: var(--fg-faint); }
.modal-body code { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.modal-body input { width: 100%; margin-top: 8px; }
.modal-body pre { background: var(--bg); padding: 10px; border-radius: 4px; overflow: auto; font-size: 12px; max-height: 360px; }
.modal footer {
  padding: 10px 16px; border-top: 1px solid var(--line);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* ============== TOAST ============== */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  max-width: 80%;
  font-size: 13px;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--err); }
.toast[hidden] { display: none; }

/* ============== UTIL ============== */
code, pre { font-family: var(--mono); }
a { color: var(--accent); }
