:root {
  color-scheme: light;
  --bg: #edf1f5;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --line: #d8dee6;
  --text: #1f2933;
  --muted: #64707d;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --success: #16834b;
  --success-soft: #dcfce7;
  --danger: #c93434;
  --danger-soft: #fee2e2;
  --warning: #b7791f;
  --warning-soft: #fef3c7;
  --log-bg: #111827;
  --log-text: #d1d5db;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

/* hidden 属性必须压过下面各容器显式的 display（.login-overlay/.app/.view 等有
   display:flex|grid，否则 UA 默认的 [hidden]{display:none} 会被盖掉、藏不住）。 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  border-color: #aab5c4;
}

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

button.primary {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(420px, 1fr) 340px;
  overflow: hidden;
}

.sidebar,
.inspector {
  min-width: 0;
  overflow: auto;
  padding: 14px;
}

.sidebar {
  background: #f3f6f9;
  border-right: 1px solid var(--line);
}

.inspector {
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.content {
  min-width: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 10px;
  padding: 14px;
}

.brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  margin-bottom: 14px;
}

.brand-title {
  font-weight: 700;
}

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

.panel {
  margin-bottom: 14px;
}

.panel-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.host-filter {
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 8px;
  background: var(--panel);
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.batch-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.batch-actions button {
  flex: 1;
}

.account-card,
.date-item {
  width: 100%;
  min-width: 0;
  margin-bottom: 7px;
  padding: 9px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.account-card {
  cursor: default;
}

.account-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
}

.character {
  display: block;
  width: 100%;
  min-height: 32px;
  margin-top: 6px;
  padding-left: 12px;
  text-align: left;
}

.selected {
  background: var(--accent-soft);
  border-color: #93bdf8;
}

.content-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.selection {
  min-width: 0;
}

h1 {
  margin: 0 0 4px;
  font-size: 20px;
  line-height: 1.25;
}

.toolbar,
.filters,
.task-actions,
.status-head {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toolbar {
  flex: 0 0 auto;
}

.filters {
  min-width: 0;
}

.filters label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.filters input[type="search"] {
  flex: 1;
  min-width: 0;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.messages {
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.message.me {
  align-items: flex-end;
}

.message.system {
  align-items: center;
}

.message-meta {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.bubble {
  max-width: min(720px, 78%);
  border-radius: 7px;
  padding: 9px 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.eve .bubble {
  background: #f1f5f9;
}

.me .bubble {
  background: var(--accent-soft);
}

.system .bubble {
  max-width: min(680px, 92%);
  background: var(--warning-soft);
  color: #6b4a0f;
  text-align: center;
}

.type-share .bubble,
.type-card .bubble,
.type-image .bubble {
  border: 1px solid #bfdbfe;
}

.type-share .message-meta,
.type-card .message-meta,
.type-image .message-meta {
  color: var(--accent);
  font-weight: 600;
}

.type-event .message-meta {
  color: var(--warning);
  font-weight: 600;
}

.status-pill {
  border-radius: 999px;
  padding: 4px 9px;
  background: #e5e7eb;
  color: var(--muted);
  font-size: 12px;
}

.status-pill.running {
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.stale,
.status-pill.conflict {
  background: var(--danger-soft);
  color: var(--danger);
}

.task-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.metric {
  min-width: 0;
  min-height: 58px;
  padding: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.metric-label {
  color: var(--muted);
  font-size: 11px;
}

.metric-value {
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.latest-label {
  margin: 8px 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.latest-box {
  min-height: 36px;
  max-height: 120px;
  overflow: auto;
  padding: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.log-panel {
  min-height: 0;
}

.logs {
  height: 240px;
  margin: 0;
  overflow: auto;
  background: var(--log-bg);
  color: var(--log-text);
  border-radius: 7px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.error-text {
  min-height: 18px;
  margin-top: 8px;
  color: var(--danger);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--muted);
  padding: 14px;
}

/* ============================================================ P3：登录 / 应用外壳 / 标签 */
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 50;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 300px;
  padding: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .08);
}

.login-title { font-size: 20px; font-weight: 700; }
.login-sub { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.login-card input {
  height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar .brand { font-weight: 700; margin: 0; min-height: 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  min-height: 32px;
}
.tab.active { background: var(--accent-soft); border-color: #93bdf8; color: var(--accent); font-weight: 600; }

.global-error {
  padding: 8px 14px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* 消息视图沿用三栏，但装进 .view-messages */
.view-messages {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(420px, 1fr) 340px;
  overflow: hidden;
}
.view-page {
  min-height: 0;
  overflow: auto;
  padding: 16px 20px;
}
.view-page h2 { font-size: 16px; margin: 0; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 12px;
}
.row-actions { display: flex; gap: 8px; }

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.inline-form input { height: 34px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }

button.small { min-height: 28px; padding: 0 9px; font-size: 12px; }

/* 主机卡片 + 资源条 + 实例格 */
.cards { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}
.card-head { display: flex; align-items: center; gap: 10px; }
.card-title { font-weight: 700; }
.card-head .primary { margin-left: auto; }

.light { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; display: inline-block; }
.light.on { background: var(--success); box-shadow: 0 0 6px var(--success); }
.light.off { background: var(--danger); }

.res-row { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; }
.res { min-width: 160px; flex: 1; }
.res-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.res-track { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.res-fill { height: 100%; background: var(--accent); }
.res-fill.hot { background: var(--danger); }

.inst-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.inst {
  width: 200px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}
.inst.running { border-left: 3px solid var(--success); }
.inst.down, .inst.creating, .inst.deleting { border-left: 3px solid var(--warning); }
.inst-name { font-weight: 600; margin-bottom: 4px; }
.inst-acts { display: flex; gap: 6px; margin-top: 8px; }

/* 表格 */
.table-wrap { overflow-x: auto; margin-bottom: 20px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--panel); }
table.grid th, table.grid td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
}
table.grid th { background: var(--panel-soft); color: var(--muted); font-size: 12px; white-space: nowrap; }
table.grid tr.conflict td { background: var(--danger-soft); }
table.grid tr.lvl-error td { color: var(--danger); }
table.grid tr.lvl-warn td { color: var(--warning); }
table.grid input, table.grid textarea { border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; }

.status-pill.crashed, .status-pill.failed { background: var(--danger-soft); color: var(--danger); }
.status-pill.pending, .status-pill.starting { background: var(--warning-soft); color: var(--warning); }
.status-pill.done { background: var(--success-soft); color: var(--success); }

@media (max-width: 980px) {
  .view-messages {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .sidebar,
  .inspector {
    border: 0;
  }

  .content {
    min-height: 70vh;
  }
}

@media (max-width: 560px) {
  .content-header,
  .filters,
  .task-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar button {
    flex: 1;
  }

  .bubble {
    max-width: 100%;
  }
}
