:root {
  color-scheme: dark;
  --bg: #0d0f10;
  --surface: #131619;
  --surface-raised: #191d20;
  --line: #30363a;
  --line-soft: #24292d;
  --text: #edf0f2;
  --muted: #9aa3a9;
  --green: #60c47b;
  --green-dark: #1d3525;
  --amber: #e2ad52;
  --amber-dark: #3b2d16;
  --red: #e16f6f;
  --red-dark: #3d2020;
  --cyan: #75b8c8;
  --font-mono: "Cascadia Mono", "Consolas", "Microsoft YaHei UI", monospace;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
.console-output:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.panel-shell {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  min-height: 520px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: #111315;
}

.instance-tabs {
  display: inline-flex;
  flex: 0 1 auto;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.instance-tab {
  min-width: 72px;
  padding: 7px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.instance-tab:last-child { border-right: 0; }
.instance-tab[aria-selected="true"] { background: #263b31; color: #d5f4df; }
.instance-tab:hover { color: var(--text); }

.instance-alert {
  margin: 5px 0 0;
  color: var(--amber);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.stats-section { display: flex; flex-direction: column; }
.stats-section .stats-content { flex: 1 1 auto; height: auto; }
.detail-memory-metric { margin-top: 8px; }
.process-memory-metric { margin-top: 12px; }
.status-uncertain { color: var(--amber); }
.status-uncertain .status-dot { background: var(--amber); }

.brand-block {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 14px;
}

.topbar-actions,
.auth-controls {
  display: flex;
  align-items: center;
}

.topbar-actions {
  flex: 0 0 auto;
  gap: 18px;
}

.auth-controls {
  min-width: 0;
  gap: 8px;
}

.auth-username {
  max-width: 160px;
  overflow: hidden;
  color: #cbd2d6;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-button {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid #41484d;
  border-radius: 3px;
  background: #1a1e21;
  color: #d5dbde;
  cursor: pointer;
}

.topbar-button:hover {
  border-color: #667077;
  background: #23282c;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  overflow: hidden;
  font-size: 17px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-subtitle,
.section-meta,
.socket-status {
  color: var(--muted);
  font-size: 12px;
}

.server-status {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  font-weight: 700;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgb(154 163 169 / 12%);
}

.status-online { color: var(--green); }
.status-online .status-dot { background: var(--green); box-shadow: 0 0 0 3px rgb(96 196 123 / 14%); }
.status-starting,
.status-stopping,
.status-restarting,
.status-external { color: var(--amber); }
.status-starting .status-dot,
.status-stopping .status-dot,
.status-restarting .status-dot,
.status-external .status-dot { background: var(--amber); box-shadow: 0 0 0 3px rgb(226 173 82 / 14%); }
.status-crashed { color: var(--red); }
.status-crashed .status-dot { background: var(--red); box-shadow: 0 0 0 3px rgb(225 111 111 / 14%); }
.status-disconnected,
.status-reconnecting { color: var(--amber); }
.status-disconnected .status-dot,
.status-reconnecting .status-dot { background: var(--amber); box-shadow: 0 0 0 3px rgb(226 173 82 / 14%); }
.status-offline { color: #a5aaad; }

.workspace {
  display: flex;
  min-width: 0;
  min-height: 0;
}

.main-panel {
  display: grid;
  grid-template-rows: minmax(185px, 7fr) minmax(210px, 5fr) minmax(96px, 3fr);
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.panel-section {
  min-width: 0;
  min-height: 0;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 25px;
  gap: 16px;
}

.section-heading h2,
.monitor-heading h2 {
  font-size: 14px;
  font-weight: 700;
}

.command-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.command-heading .section-meta {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-button {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 12px;
}

.stats-content {
  display: grid;
  grid-template-columns: minmax(150px, 0.28fr) minmax(220px, 1fr) minmax(155px, 0.4fr);
  align-items: stretch;
  gap: 18px;
  height: calc(100% - 25px);
  min-height: 0;
  padding-top: 10px;
}

.memory-summary {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.memory-metric {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.process-memory-metric {
  margin-top: 20px;
}

.metric-label,
.stat-item span {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: 19px;
  font-weight: 650;
}

.metric-value-secondary {
  margin-top: 6px;
  color: #c8ced2;
  font-size: 15px;
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  min-width: 0;
  min-height: 84px;
  border: 1px solid var(--line-soft);
  background: #101214;
}

#memoryChart {
  display: block;
  width: 100%;
  height: 100%;
}

.stat-strip {
  display: grid;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  min-height: 0;
  border-left: 1px solid var(--line-soft);
}

.stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 12px;
  padding-left: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.stat-item:last-child {
  border-bottom: 0;
}

.stat-item strong {
  overflow-wrap: anywhere;
  text-align: right;
  font-size: 13px;
}

.guest-control-section {
  display: grid;
}

.guest-control-layout {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(142px, 3fr);
  min-height: 0;
}

.guest-control-column {
  display: grid;
  grid-column: 2;
  grid-template-rows: repeat(3, minmax(32px, 1fr));
  gap: 4px;
  min-height: 0;
  padding-left: 16px;
  border-left: 1px solid var(--line-soft);
}

.guest-status-button {
  grid-row: 2;
}

.guest-status-button:disabled {
  border-color: #41484d;
  background: #22272a;
  color: #8d969b;
  opacity: 1;
}

.guest-control-feedback {
  grid-row: 3;
  align-self: start;
  min-width: 0;
  padding-top: 6px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.guest-control-feedback.error {
  color: #f1b5b5;
}

.command-content {
  display: grid;
  grid-template-rows: auto 36px minmax(0, 1fr);
  gap: 7px;
  height: calc(100% - 25px);
  min-height: 0;
  padding-top: 7px;
}

.command-content > label {
  color: var(--muted);
  font-size: 12px;
}

#commandInput {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 11px;
  border: 1px solid #444b50;
  border-radius: 3px;
  background: #0e1012;
  color: var(--text);
}

#commandInput:disabled {
  cursor: not-allowed;
  color: #747b80;
  background: #151719;
}

.command-lower {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(142px, 3fr);
  min-height: 0;
  border-top: 1px solid var(--line-soft);
}

.command-tools {
  display: grid;
  grid-template-rows: minmax(39px, auto) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  padding: 8px 16px 0 0;
}

.command-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.command-feedback {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 18px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  opacity: 0;
  transition: opacity 140ms ease;
}

.command-feedback.visible {
  opacity: 1;
}

.command-feedback.error {
  color: #f1b5b5;
}

.button {
  min-height: 32px;
  padding: 6px 15px;
  border: 1px solid #4a5156;
  border-radius: 3px;
  background: #22272a;
  color: var(--text);
  cursor: pointer;
}

.button:hover:not(:disabled) {
  border-color: #697278;
  background: #2a3034;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.button.primary {
  border-color: #4d7883;
  background: #20343a;
}

.button.start {
  border-color: #3f7350;
  background: var(--green-dark);
  color: #b6ebc4;
}

.button.stop,
.button.danger {
  border-color: #794444;
  background: var(--red-dark);
  color: #f3b8b8;
}

.button.restart {
  border-color: #765c2d;
  background: var(--amber-dark);
  color: #f1d19b;
}

.history-block {
  min-width: 0;
  min-height: 0;
}

.history-block h3 {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.command-history {
  height: calc(100% - 20px);
  overflow: auto;
  color: #c9d0d4;
  font-size: 12px;
  line-height: 1.6;
  scrollbar-color: #4c5358 transparent;
}

.history-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-line::before {
  color: var(--cyan);
  content: "> ";
}

.server-controls {
  display: grid;
  grid-template-rows: repeat(3, minmax(32px, 1fr));
  gap: 4px;
  min-height: 0;
  padding: 0 0 0 16px;
  border-left: 1px solid var(--line-soft);
}

.lifecycle {
  width: 100%;
  min-height: 32px;
}

.players-section {
  display: grid;
  grid-template-rows: 25px minmax(0, 1fr);
}

.player-list {
  display: block;
  min-height: 0;
  padding-top: 9px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-color: #4c5358 transparent;
}

.player-row {
  display: grid;
  grid-template-columns: 7px minmax(0, 1fr) 52px;
  align-items: center;
  width: 250px;
  max-width: 100%;
  min-height: 29px;
  gap: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.player-row:last-child {
  border-bottom: 0;
}

.player-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.player-name {
  min-width: 0;
  overflow: hidden;
  color: #d8dde0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-ping {
  color: #b8c0c5;
  text-align: right;
  white-space: nowrap;
}

.empty-state {
  color: #70787d;
  font-size: 12px;
}

.monitor-panel {
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
  flex: 0 0 0;
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-left: 0 solid var(--line);
  visibility: hidden;
  background: #0b0d0e;
  transition: flex-basis 160ms ease, width 160ms ease, border-width 160ms ease;
}

.workspace.monitor-open .monitor-panel {
  flex-basis: 32%;
  width: 32%;
  border-left-width: 1px;
  visibility: visible;
}

.monitor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 260px;
  padding: 0 14px 0 16px;
  border-bottom: 1px solid var(--line);
  background: #111315;
}

.monitor-heading > div {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.socket-status.connected { color: var(--green); }
.socket-status.disconnected { color: var(--red); }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--line);
  color: var(--text);
  background: var(--surface-raised);
}

.console-output {
  min-width: 260px;
  min-height: 0;
  margin: 0;
  padding: 13px 15px 24px;
  overflow: auto;
  color: #cbd2d6;
  font: 12px/1.55 var(--font-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-color: #4c5358 #111315;
}

.modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
}

.modal.open {
  display: grid;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 68%);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  padding: 22px;
  border: 1px solid #4a5054;
  border-radius: 5px;
  background: #181b1e;
  box-shadow: 0 18px 60px rgb(0 0 0 / 45%);
}

.modal-dialog h2 {
  font-size: 16px;
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  gap: 16px;
}

.modal-dialog p {
  margin-top: 13px;
  color: #b5bdc2;
  line-height: 1.7;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 22px;
}

.login-dialog {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.login-dialog > label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.login-dialog > input {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid #444b50;
  border-radius: 3px;
  background: #0e1012;
  color: var(--text);
}

.login-error {
  min-height: 20px;
  margin-top: 4px !important;
  color: #f1b5b5 !important;
  font-size: 12px;
  line-height: 1.5 !important;
}

.login-dialog .modal-actions {
  margin-top: 8px;
}

.backups-dialog {
  width: min(680px, 100%);
  max-height: min(760px, calc(100dvh - 40px));
  overflow-y: auto;
}

.backup-operation-status {
  min-height: 22px;
  margin-top: 12px;
  color: #c1c9cd;
  font-size: 12px;
  line-height: 1.6;
}

.backup-operation-status.error,
.backup-feedback.error,
.restore-warning {
  color: #f1b5b5;
}

.backup-feedback {
  min-height: 22px;
  margin-top: 2px !important;
  color: #b9d5dc !important;
  font-size: 12px;
  line-height: 1.5 !important;
}

.backup-feedback.error {
  color: #f1b5b5 !important;
}

.backup-menu {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.backup-action-button {
  width: 100%;
  min-height: 48px;
  text-align: left;
}

.button.danger-outline {
  border-color: #704141;
  background: #241b1c;
  color: #efb3b3;
}

.backup-view {
  margin-top: 10px;
}

.backup-view-heading {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.backup-view-heading h3 {
  font-size: 13px;
}

.backup-view > label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.backup-view > input {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid #444b50;
  border-radius: 3px;
  background: #0e1012;
  color: var(--text);
}

.snapshot-actions {
  margin-top: 12px;
}

.restore-list {
  max-height: min(470px, 52dvh);
  overflow-y: auto;
  scrollbar-color: #4c5358 transparent;
}

.restore-list h4 {
  padding: 10px 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.restore-point {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  min-height: 48px;
  gap: 14px;
  padding: 8px 4px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.restore-point:hover:not(:disabled) {
  background: #202428;
}

.restore-point:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.restore-point strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.restore-point span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.restore-confirm-label {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.restore-warning {
  margin-top: 12px !important;
  font-size: 12px;
}

.backup-confirm-actions {
  margin-top: 18px;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .panel-shell {
    display: block;
    min-height: 100dvh;
    height: auto;
  }

  .topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    min-height: 86px;
    height: auto;
    flex-wrap: wrap;
    gap: 6px;
    padding: 7px 13px;
  }

  .instance-tabs { order: 3; width: 100%; }
  .instance-tab { flex: 1 1 50%; padding: 5px 8px; }
  .brand-block { flex: 1 1 auto; }
  .topbar-actions { flex: 0 0 auto; }

  .topbar-actions {
    gap: 7px;
  }

  .auth-controls {
    gap: 5px;
  }

  .auth-username {
    max-width: 64px;
    font-size: 11px;
  }

  .topbar-button {
    min-height: 28px;
    padding: 4px 6px;
    font-size: 11px;
  }

  .brand-block {
    display: block;
  }

  h1 {
    max-width: 46vw;
    font-size: 14px;
  }

  .brand-subtitle {
    display: none;
  }

  .server-status {
    font-size: 12px;
  }

  .server-status {
    gap: 6px;
  }

  .status-dot {
    width: 8px;
    height: 8px;
  }

  .workspace,
  .main-panel {
    display: block;
  }

  .panel-section {
    padding: 14px 13px;
  }

  .stats-section {
    min-height: 330px;
  }

  .stats-content {
    grid-template-columns: 1fr;
    grid-template-rows: auto 130px auto;
    height: auto;
    gap: 12px;
  }

  .memory-summary {
    min-height: 120px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px 16px;
  }

  .memory-metric { flex: 1 1 calc(50% - 8px); }
  .detail-memory-metric { margin-top: 0; }

  .process-memory-metric {
    margin-top: 0;
  }

  .metric-value {
    font-size: 17px;
  }

  .stat-strip {
    grid-template-rows: repeat(4, 34px);
    border-top: 1px solid var(--line-soft);
    border-left: 0;
  }

  .stat-item {
    padding-left: 0;
  }

  .command-section {
    min-height: 400px;
  }

  .command-heading {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  .command-heading .section-meta {
    font-size: 10px;
  }

  .compact-button {
    padding-right: 7px;
    padding-left: 7px;
  }

  .guest-control-section {
    min-height: 240px;
  }

  .guest-control-layout {
    grid-template-columns: minmax(0, 1fr) 112px;
  }

  .guest-control-column {
    grid-template-rows: repeat(3, minmax(40px, 1fr));
    gap: 7px;
    padding-left: 10px;
  }

  .command-content {
    height: 340px;
  }

  .command-lower {
    grid-template-columns: minmax(0, 1fr) 112px;
  }

  .command-tools {
    padding-right: 10px;
  }

  .server-controls {
    grid-template-rows: repeat(3, minmax(40px, 1fr));
    gap: 7px;
    padding: 8px 0 0 10px;
  }

  .lifecycle { min-height: 40px; }

  .button {
    padding-right: 10px;
    padding-left: 10px;
  }

  .players-section {
    min-height: 150px;
  }

  .monitor-panel,
  .workspace.monitor-open .monitor-panel {
    position: fixed;
    z-index: 40;
    inset: 0;
    display: grid;
    width: 100%;
    height: 100dvh;
    border-left: 0;
    transform: translateX(100%);
    transition: transform 170ms ease;
  }

  .workspace.monitor-open .monitor-panel {
    transform: translateX(0);
  }

  .monitor-heading,
  .console-output {
    min-width: 0;
  }

  .backups-dialog {
    max-height: calc(100dvh - 24px);
    padding: 17px;
  }

  .restore-point {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
