:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --border: #e2e2de;
  --text: #17181a;
  --muted: #6e7178;
  --accent: #2f6f4f;
  --danger: #a33a3a;
  --warn: #b07d16;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --maxw: 1100px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1012;
    --surface: #17181b;
    --border: #25272b;
    --text: #e8e9ea;
    --muted: #8b8f96;
    --accent: #5aa37c;
    --danger: #c46b6b;
    --warn: #d9a13b;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header .bar {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
}

.brand { font-weight: 600; letter-spacing: -0.01em; padding: 14px 0; }

nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }

nav button {
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--muted);
  padding: 8px 15px;
  margin: 8px 0;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
nav button:hover { color: var(--accent); border-color: var(--accent); }
nav button[aria-selected="true"] {
  color: var(--text);
  border-color: var(--accent);
}

.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.up { background: var(--accent); }
.dot.warn { background: var(--warn); }
.dot.down { background: var(--danger); }

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 16px 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
}

.panel.controls { flex: none; }

main > section.panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

#view-console:not(.hidden) { display: flex; flex-direction: column; overflow: hidden; }

.panel h2 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  flex: none;
}

.panel h2:not(:first-child) { margin-top: 28px; }

button.action, a.action {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  padding: 8px 18px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.action:hover, a.action:hover { border-color: var(--accent); color: var(--accent); }
button.action:disabled { opacity: 0.45; cursor: default; }
button.action:disabled:hover { border-color: var(--border); color: var(--text); }
button.action.danger:hover { border-color: var(--danger); color: var(--danger); }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

#console, .filebody {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

#console { flex: 1; min-height: 0; }
.filebody { max-height: 55vh; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
td.muted, .muted { color: var(--muted); }

.avatar {
  width: 22px; height: 22px;
  image-rendering: pixelated;
  vertical-align: middle;
  margin-right: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }

.tree, .tree ul { list-style: none; }
.tree { padding-left: 0; margin: 0; }
.tree ul { padding-left: 16px; margin: 2px 0; }
.tree a {
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--r-sm);
}
.tree a:hover { color: var(--accent); background: var(--bg); }

input[type="text"], input[type="email"], textarea {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
}
textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 12.5px;
  min-height: 40vh;
  border-radius: var(--r-md);
}

body.login-body {
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.signin {
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 16px;
}

.hidden { display: none !important; }

@media (max-width: 640px) {
  header .bar { flex-wrap: wrap; gap: 8px; }
  .status { width: 100%; padding-bottom: 10px; }
}

.iconbtn {
  width: 38px;
  height: 38px;
  flex: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}
.iconbtn svg { width: 19px; height: 19px; display: block; }
.iconbtn:hover { border-color: var(--accent); color: var(--accent); }
.iconbtn.warn:hover { border-color: var(--warn); color: var(--warn); }
.iconbtn.danger:hover { border-color: var(--danger); color: var(--danger); }
.iconbtn:disabled { opacity: 0.45; cursor: default; }
.iconbtn:disabled:hover { border-color: var(--border); color: var(--text); }

[data-tip] { position: relative; }

[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 5px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
  letter-spacing: 0.01em;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 30;
}

[data-tip]::before {
  content: "";
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: var(--text);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 30;
}

[data-tip]:hover::after,
[data-tip]:hover::before,
[data-tip]:focus-visible::after,
[data-tip]:focus-visible::before {
  opacity: 1;
  visibility: visible;
}

.serverstate { margin-left: 6px; }

.status .iconbtn { width: 32px; height: 32px; }
.status .iconbtn svg { width: 16px; height: 16px; }

.grow { flex: 1; }
.mb-10 { margin-bottom: 10px; }
.mt-10 { margin-top: 10px; }
.mt-14 { margin-top: 14px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.ok { color: var(--accent); }

#view-logs:not(.hidden):has(#logDetail:not(.hidden)) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#logDetail:not(.hidden) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#logDetail > .row { flex: none; }

#logBody {
  flex: 1;
  min-height: 0;
  max-height: none;
}

.cmdrow {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex: none;
}

#cmdInput {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
  border-radius: 999px;
  padding: 9px 16px;
}

#view-monitor:not(.hidden) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tablescroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.tablescroll table { min-width: 100%; }
.tablescroll th, .tablescroll td { white-space: nowrap; }
.tablescroll thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  padding-top: 10px;
  padding-bottom: 10px;
}
td.cmd { font-family: var(--mono); font-size: 12.5px; }
td.kind-refused { color: var(--danger); }
td.kind-chat { color: var(--muted); }

#cmdInput:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cmdrow .iconbtn { width: 36px; height: 36px; align-self: center; }
.cmdrow .iconbtn svg { width: 17px; height: 17px; }
.cmdrow .iconbtn[data-tip]::after,
.cmdrow .iconbtn[data-tip]::before { top: auto; bottom: calc(100% + 9px); }
.cmdrow .iconbtn[data-tip]::before { border-bottom-color: transparent; border-top-color: var(--text); bottom: calc(100% + 4px); }

#view-files:not(.hidden) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#filesSplit {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
}

#filesSplit .tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

#filesSplit:has(#fileDetail:not(.hidden)) .tree {
  flex: 0 0 34%;
  border-right: 1px solid var(--border);
  padding-right: 12px;
}

#fileDetail:not(.hidden) {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#fileDetail > .row { flex: none; }
#fileDetail #fileBody { flex: 1; min-height: 0; max-height: none; }
#fileDetail textarea { flex: 1; min-height: 0; }
#fileTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 720px) {
  #filesSplit { flex-direction: column; }
  #filesSplit:has(#fileDetail:not(.hidden)) .tree {
    flex: 0 0 38%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 10px;
  }
}

.addr {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: none;
  color: var(--text);
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.addr code { font-family: var(--mono); font-size: 13px; color: inherit; }
.addr svg { width: 15px; height: 15px; flex: none; }
.addr:hover { border-color: var(--accent); color: var(--accent); }
