:root {
  --bg: #0e1116;
  --bg2: #161b22;
  --card: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}
.brand {
  font-size: 18px;
  font-weight: 600;
  display: flex; align-items: center; gap: 10px;
}
.brand small {
  color: var(--muted);
  font-weight: 400;
  font-size: 13px;
  margin-left: 4px;
}
.logo { font-size: 22px; }

nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
nav a {
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--muted);
}
nav a:hover { color: var(--text); background: var(--card); text-decoration: none; }
nav a.active { color: var(--text); background: var(--card); }

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.logout-btn:hover { color: var(--red); border-color: var(--red); }

main { padding: 24px 28px; max-width: 1280px; margin: 0 auto; }

h1, h2 { margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
p.hint { color: var(--muted); margin: 6px 0 14px; }
p.error { color: var(--red); }

.flashes { padding: 0 28px; margin-top: 12px; }
.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid;
  background: var(--card);
}
.flash.ok { border-color: var(--green); }
.flash.err { border-color: var(--red); }

/* sysbar */
.sysbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.metric {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.metric .label { color: var(--muted); font-size: 13px; }
.metric .value { font-size: 22px; font-weight: 600; margin: 4px 0; }
.metric .sub   { color: var(--muted); font-size: 12px; }
.bar {
  height: 6px; background: #2d333b; border-radius: 4px; overflow: hidden;
  margin: 4px 0;
}
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--green)); }

/* service grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card.secret { border-color: var(--amber); }
.service header {
  background: none;
  border: none;
  padding: 0 0 8px;
  display: flex; justify-content: space-between; align-items: center;
}
.service .title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.service .icon { font-size: 22px; }
.service .desc { color: var(--muted); font-size: 13px; min-height: 36px; margin: 0 0 10px; }
.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--red);
}
.service.running .dot { background: var(--green); }
.service.created .dot, .service.exited .dot { background: var(--amber); }

dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  font-size: 13px;
  margin: 0 0 12px;
}
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.actions {
  display: flex; gap: 8px;
  border: none; padding: 0;
}

/* buttons */
.btn, button.btn, button {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--accent);
  color: #0e1116;
  font-weight: 500;
  border: 1px solid var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  box-shadow: none;
}
.btn:focus, button.btn:focus, button:focus,
.btn:focus-visible, button.btn:focus-visible, button:focus-visible {
  outline: none;
  box-shadow: none;
}
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.danger { background: var(--red); border-color: var(--red); color: white; }
.btn.disabled { background: #444; border-color: #444; color: #888; cursor: not-allowed; pointer-events: none; }
button.copy {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 9px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
}
button.copy:hover { background: var(--border); }

/* tables */
table.userlist, table.params {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.userlist th, table.userlist td,
table.params th, table.params td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.userlist th, table.params th {
  color: var(--muted);
  font-weight: 500;
  background: var(--bg2);
}
table.userlist tr:hover { background: rgba(88, 166, 255, 0.04); }

code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  font-family: "JetBrains Mono", "Consolas", "Menlo", monospace;
}
code.mask {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}
code.mask:hover { color: var(--text); }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: var(--border);
}
.tag.green { background: var(--green); color: #0e1116; }
.tag.red   { background: var(--red);   color: #fff; }
.tag.amber { background: var(--amber); color: #0e1116; }

.row { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline input[type=email], form.inline input[type=text], form.inline input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

ul.tips {
  margin: 0;
  padding-left: 20px;
}
ul.tips li { margin-bottom: 6px; }

details > summary {
  cursor: pointer;
  color: var(--accent);
  margin-bottom: 8px;
}

footer {
  text-align: center;
  padding: 18px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

@media (max-width: 720px) {
  main { padding: 16px; }
  header { padding: 10px 16px; }
  .grid { grid-template-columns: 1fr; }
}

/* Mask for secrets page */
.mask-secure {
  background: #333;
  color: #333;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  user-select: none;
  transition: none;
}
.mask-secure:hover {
  background: #555;
}
.mask-secure.revealed,
.mask-secure[class*='revealed'] {
  background: transparent;
  color: inherit;
  cursor: text;
  user-select: text;
}

/* Secret inline row (token + copy button side by side) */
.secret-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.param-item-wide {
  grid-column: 1 / -1;
}

/* Remote access legend */
.remote-legend {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.remote-legend p {
  margin: 4px 0;
  font-size: 13px;
  color: var(--muted);
}
.remote-legend b {
  color: var(--text);
}

/* Horizontal parameter grid - responsive */
.param-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px 14px;
}
.param-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
}
.param-item .tag,
.param-item code {
  width: fit-content;
}
.param-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Scrollable tables on mobile */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll table {
  min-width: 480px;
}

/* Responsive adjustments */
@media (max-width: 600px) {
  .param-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  header nav {
    flex-wrap: wrap;
    gap: 2px 6px;
    font-size: 13px;
  }
  header nav a {
    padding: 4px 6px;
  }
  .sysbar {
    flex-direction: column;
    gap: 8px;
  }
  .sysbar .metric {
    padding: 8px 12px;
  }
  .grid {
    grid-template-columns: 1fr;
  }
}

/* Muted tag for deleted users */
.tag.muted {
  background: #444;
  color: #888;
}
tr:has(.tag.muted) {
  opacity: 0.55;
}
/* Ensure hover doesn't override */
tr:has(.tag.muted):hover {
  opacity: 0.7;
}

/* Deleted row styling */
.row-deleted td {
  color: #777 !important;
}
.row-deleted td .btn-tiny.green {
  color: #4caf50 !important;
  border-color: #4caf50 !important;
  opacity: 1 !important;
}

/* Dim text */
.dim { color: #888; }

/* Rename inline editor */
.rename-input {
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 13px;
  width: 140px;
}
.btn-rename {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 4px;
}
.btn-rename:hover { color: var(--text); border-color: var(--accent); }
.btn-rename.confirm { color: var(--green); border-color: var(--green); }
.btn-rename.cancel { color: var(--red); border-color: var(--red); }

/* Tiny button */
.btn-tiny {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 1px 6px;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-tiny:hover { background: var(--hover); }
.btn-tiny.green { border-color: #4caf50; color: #4caf50; }
.btn-tiny.green:hover { background: #1a3a1a; }
.btn-tiny.danger { border-color: #f44336; color: #f44336; }
.btn-tiny.danger:hover { background: #3a1a1a; }

/* Unified input styles */
.inp, input:not([type=checkbox]):not([type=submit]):not([type=hidden]) {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
}
.inp-small {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 12px;
  width: 80px;
}
.inp:focus, .inp-small:focus, input:focus:not([type=checkbox]) {
  outline: none;
  border-color: var(--accent);
}

/* Room member list */
.member-list summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
}
.member-items {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.member-item {
  font-size: 12px;
  padding: 2px 6px;
  background: var(--hover);
  border-radius: 3px;
}

/* Room member fixed-width column */
.room-table th:nth-child(2),
.room-table td:nth-child(2) {
  max-width: 200px;
  min-width: 140px;
}
.member-item {
  font-size: 12px;
  padding: 2px 6px;
  background: var(--hover);
  border-radius: 3px;
  word-break: break-all;
}

/* Fix room table member column */
.room-table th:nth-child(2),
.room-table td:nth-child(2) {
  width: 170px;
  min-width: 150px;
  max-width: 200px;
  word-break: break-all;
}
.member-list summary {
  font-size: 13px;
  cursor: pointer;
  color: var(--accent);
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #555;
  border-radius: 22px;
  cursor: pointer;
  transition: 0.2s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: #4caf50; }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(20px); }

/* Room table - narrow name column */
.room-table th:first-child,
.room-table td:first-child {
  max-width: 160px;
  word-break: break-all;
}

/* Room table column widths */
.room-table th:nth-child(1),
.room-table td:nth-child(1) { width: 220px; min-width: 180px; word-break: break-all; }
.room-table th:nth-child(2),
.room-table td:nth-child(2) { width: 200px; min-width: 180px; }
.room-table th:nth-child(3),
.room-table td:nth-child(3) { width: 100px; }

/* Remove old fixed room column widths - replace with proportional */
.room-table th:nth-child(1), .room-table td:nth-child(1) { width: 35%; min-width: 260px; }
.room-table th:nth-child(2), .room-table td:nth-child(2) { width: 22%; min-width: 200px; }
.room-table th:nth-child(3), .room-table td:nth-child(3) { width: 15%; }
.room-table th:nth-child(4), .room-table td:nth-child(4) { width: 10%; }
.room-table th:nth-child(5), .room-table td:nth-child(5) { width: 10%; }
.room-table th:nth-child(6), .room-table td:nth-child(6) { width: 8%; }

.btn.warn { background: var(--red); color: #fff; border-color: var(--red); }
.btn.warn:hover { opacity: 0.85; }
.btn.ghost.warn { background: transparent; color: var(--red); border-color: var(--red); }
.btn.ghost.warn:hover { background: var(--red); color: #fff; }
form.inline { display: inline-block; margin: 0; padding: 0; vertical-align: middle; }
form.inline + form.inline { margin-left: 4px; }

.config-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.config-card .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.config-actions { margin-top: 12px; }
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-box { position: relative; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 24px; max-width: 480px; width: 90%; }
.modal-box h3 { margin: 0 0 8px; }
.modal-box p { margin: 0 0 8px; color: var(--muted); }
@media (max-width: 640px) {
  .config-table th:nth-child(4),
  .config-table td:nth-child(4),
  .config-table th:nth-child(5),
  .config-table td:nth-child(5) { display: none; }
  .config-table td[data-label]::before { content: attr(data-label) ": "; font-weight: bold; font-size: 11px; color: var(--muted); }
  .config-table-wrap { margin: 0 -12px; }
  .config-table { font-size: 13px; }
  .config-table input { width: 100%; min-width: 80px; }
}

/* Settings page */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.settings-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.settings-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  flex: 1;
  min-width: 180px;
}
.settings-row input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
}
.settings-row input:focus {
  outline: none;
  border-color: var(--accent);
}
.settings-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.settings-toggle input[type=checkbox] {
  width: 16px;
  height: 16px;
}
.settings-checks {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}
.settings-checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.settings-checks input[type=checkbox] {
  width: 16px;
  height: 16px;
}
.settings-checks input[type=text] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 13px;
}
.settings-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}
@media (max-width: 768px) {
  .settings-row {
    flex-direction: column;
  }
  .settings-row label {
    min-width: 100%;
  }
  .settings-actions {
    flex-direction: column;
  }
  .settings-actions .btn {
    width: 100%;
    text-align: center;
  }
}
