:root {
  --primary: #3dd9bd;
  --primary-hover: #58e6cc;
  --background: #0b1117;
  --surface: #111a22;
  --surface-raised: #16212b;
  --border: #27343e;
  --text-primary: #e8edef;
  --text-secondary: #91a0a8;
  --success: #47d7ac;
  --warning: #e7b85c;
  --danger: #ec7580;
  --info: #71a9e9;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.16), 0 4px 12px rgba(0,0,0,.12);
}

html[data-theme="light"] {
  --primary: #0a8877;
  --primary-hover: #087366;
  --background: #f4f7f8;
  --surface: #ffffff;
  --surface-raised: #eaf0f2;
  --border: #d5dfe3;
  --text-primary: #15242b;
  --text-secondary: #62747d;
  --success: #178c70;
  --warning: #a66b08;
  --danger: #c23e4a;
  --info: #2e6fb7;
  --shadow: 0 1px 2px rgba(24,40,48,.08), 0 6px 18px rgba(24,40,48,.07);
  color-scheme: light;
}
html[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--background); color: var(--text-primary); font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif; }
button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }
.hidden { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 40px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.brand-icon { display: block; width: 56px; height: 56px; margin-bottom: 24px; border-radius: var(--radius-md); object-fit: contain; }
.brand-icon.small { width: 40px; height: 40px; margin: 0; }
.eyebrow { margin: 0 0 8px; color: var(--primary); font-size: 11px; font-weight: 600; letter-spacing: .16em; }
.login-card h1, .topbar h1 { margin: 0 0 8px; font-size: 28px; font-weight: 700; }
.muted, .section-head p { color: var(--text-secondary); line-height: 1.6; }
.login-card form { display: grid; gap: 16px; margin-top: 24px; }
label { display: grid; gap: 8px; color: #bac5ca; font-size: 13px; font-weight: 500; }
input, select { width: 100%; height: 40px; padding: 0 12px; outline: none; border: 1px solid var(--border); border-radius: var(--radius-md); background: #0c141b; color: var(--text-primary); transition: border-color 150ms, box-shadow 150ms; }
input:focus, select:focus, button:focus-visible { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(61,217,189,.12); outline: none; }
.primary, .soft, .ghost { min-height: 40px; padding: 0 16px; border-radius: var(--radius-md); font-weight: 600; transition: background-color 150ms, border-color 150ms, color 150ms; }
.primary { background: var(--primary); color: #071915; }
.primary:hover { background: var(--primary-hover); }
.soft { border: 1px solid var(--border); background: var(--surface-raised); color: #c9d2d6; }
.soft:hover, .ghost:hover { border-color: #41515d; color: var(--text-primary); }
.ghost { width: 100%; border: 1px solid var(--border); background: transparent; color: var(--text-secondary); }
.form-error, .field-error { min-height: 18px; margin: 0; color: var(--danger); font-size: 12px; }
.form-message { min-height: 18px; margin: 0; color: var(--success); font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: 248px; padding: 24px 16px; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--background); }
.sidebar-overlay { display: none; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 32px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; font-weight: 650; }
.brand span { margin-top: 4px; color: var(--text-secondary); font-size: 9px; letter-spacing: .16em; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { padding: 12px 14px; border-radius: var(--radius-md); background: transparent; color: var(--text-secondary); font-weight: 550; text-align: left; }
.nav-item:hover { background: var(--surface); color: var(--text-primary); }
.nav-item.active { background: var(--surface-raised); color: var(--primary); box-shadow: inset 3px 0 var(--primary); }
.side-bottom { margin-top: auto; display: grid; gap: 16px; }
.server-state { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.server-state > i, .live i { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--success); }
.server-state b, .server-state span { display: block; font-size: 11px; }
.server-state span { margin-top: 4px; color: var(--text-secondary); }

.content { grid-column: 2; width: 100%; max-width: 1440px; margin: 0 auto; padding: 32px 40px 64px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 32px; }
.topbar-title { display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 28px; }
.menu-button { display: none; min-height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text-primary); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.theme-control { display: flex; grid-template-columns: auto auto; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 11px; }
.theme-control select { width: 112px; height: 34px; padding: 0 9px; }
.live { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text-secondary); font-size: 12px; }
.page-error { margin-bottom: 16px; padding: 12px 16px; border-left: 3px solid var(--danger); border-radius: var(--radius-sm); background: rgba(236,117,128,.09); color: #f0b0b6; font-size: 13px; }

.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 32px; }
.stat-card { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.stat-card span { color: var(--text-secondary); font-size: 12px; }
.stat-card strong { display: block; margin: 8px 0 4px; color: var(--tone); font-size: 30px; font-weight: 650; }
.tone-primary { --tone: var(--primary); }
.tone-info { --tone: var(--info); }
.tone-danger { --tone: var(--danger); }
.tone-warning { --tone: var(--warning); }
.stat-card small { color: #71818a; }
.skeleton { min-height: 112px; border-radius: var(--radius-lg); background: linear-gradient(90deg,var(--surface) 25%,var(--surface-raised) 50%,var(--surface) 75%); background-size: 200% 100%; animation: skeleton 1.4s infinite; }
.app-skeleton { min-height: 164px; }
@keyframes skeleton { to { background-position: -200% 0; } }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; margin: 24px 0 16px; }
.section-head.compact { margin: 0 0 16px; }
.section-head h2 { margin: 0 0 4px; font-size: 18px; font-weight: 650; }
.section-head p { margin: 0; font-size: 12px; }
.app-grid { display: grid; grid-template-columns: repeat(5, minmax(176px, 1fr)); gap: 12px; }
.app-card { min-height: 192px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); transition: border-color 150ms, background-color 150ms; }
.app-card:hover, .app-card.selected { border-color: #3b605d; background: #142029; }
.app-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-select { flex: 1; padding: 0; background: transparent; color: var(--text-primary); text-align: left; }
.card-body { display: block; width: 100%; }
.app-title-row h3 { min-height: 40px; margin: 0; font-size: 15px; font-weight: 600; line-height: 1.4; }
.rename { min-height: 32px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--text-secondary); font-size: 11px; }
.rename:hover { border-color: var(--border); color: var(--primary); }
.app-desc { margin: 4px 0 16px; overflow: hidden; color: var(--text-secondary); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.active-count { display: flex; align-items: baseline; gap: 8px; }
.active-count strong { font-size: 28px; font-weight: 650; }
.active-count span { color: var(--text-secondary); font-size: 11px; }
.mini-status { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.mini-status span { padding: 4px 8px; border-radius: 999px; background: #1a2730; color: var(--text-secondary); font-size: 10px; }
.mini-status .good { background: rgba(71,215,172,.09); color: var(--success); }
.mini-status .bad { background: rgba(236,117,128,.09); color: var(--danger); }
.instance-names { margin: 12px 0 0; overflow: hidden; color: var(--text-secondary); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.instance-head { margin-top: 32px; }
.table-tools { display: grid; grid-template-columns: minmax(240px,1fr) 160px 160px; gap: 12px; margin-bottom: 12px; }
.table-tools label { gap: 6px; color: var(--text-secondary); font-size: 11px; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
table { width: 100%; min-width: 900px; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 12px; text-align: left; }
th { background: #0e171e; color: var(--text-secondary); font-size: 11px; font-weight: 600; }
tbody tr:hover { background: #131f28; }
tbody tr:last-child td { border-bottom: 0; }
.machine b, .machine span { display: block; }
.machine b { font-weight: 600; }
.machine span, .cell-muted { margin-top: 4px; color: var(--text-secondary); font-size: 10px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 650; }
.status:before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.running { background: rgba(71,215,172,.09); color: var(--success); }
.status.starting { background: rgba(113,169,233,.09); color: var(--info); }
.status.warning { background: rgba(231,184,92,.09); color: var(--warning); }
.status.error { background: rgba(236,117,128,.09); color: var(--danger); }
.status.offline, .status.stopped { background: rgba(145,160,168,.09); color: var(--text-secondary); }
.empty { padding: 40px !important; color: var(--text-secondary); text-align: center !important; }
.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; color: var(--text-secondary); font-size: 11px; }
.pagination > div { display: flex; gap: 8px; }
.pagination .soft { min-height: 36px; }
.pagination button:disabled { opacity: .45; cursor: not-allowed; }

.event-list { display: grid; gap: 8px; }
.event-item { display: grid; grid-template-columns: 16px 1fr auto; gap: 12px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.event-item:first-child { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.event-item:last-child { border-bottom: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.event-icon { width: 8px; height: 8px; overflow: hidden; border-radius: 50%; background: var(--success); color: transparent; }
.event-item.error .event-icon { background: var(--danger); }
.event-item.warning .event-icon { background: var(--warning); }
.event-main b, .event-main span { display: block; }
.event-main b { font-size: 13px; font-weight: 600; }
.event-main span { margin-top: 4px; color: var(--text-secondary); font-size: 11px; }
.event-time { color: #71818a; font-size: 10px; }

.settings-grid { display: grid; grid-template-columns: minmax(520px,1.15fr) minmax(300px,.85fr); gap: 16px; }
.panel-card { padding: 24px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.channel { display: grid; gap: 12px; padding: 20px 0; border-top: 1px solid var(--border); }
.switch-row { position: relative; display: flex; align-items: center; justify-content: space-between; }
.switch-row span b, .switch-row span small { display: block; }
.switch-row span b { font-weight: 600; }
.switch-row span small { margin-top: 4px; color: var(--text-secondary); font-size: 11px; }
.switch-row input { position: absolute; width: 1px; opacity: 0; }
.switch-row i { position: relative; width: 40px; height: 24px; border-radius: 999px; background: #2d3a43; transition: background-color 150ms; }
.switch-row i:after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #77858d; transition: transform 150ms, background-color 150ms; }
.switch-row input:checked + i { background: rgba(61,217,189,.25); }
.switch-row input:checked + i:after { background: var(--primary); transform: translateX(16px); }
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.check-grid label { display: flex; align-items: center; gap: 8px; color: #a7b4ba; font-size: 12px; }
.check-grid input { width: auto; height: auto; accent-color: var(--primary); }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.guide-card h2 { margin: 8px 0 24px; font-size: 22px; font-weight: 650; }
.flow { display: flex; align-items: center; gap: 8px; margin-bottom: 24px; flex-wrap: wrap; }
.flow span { padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 11px; }
.flow i { color: var(--primary); font-style: normal; }
.guide-card li { margin: 8px 0; color: var(--text-secondary); font-size: 12px; line-height: 1.7; }
.guide-card li b { color: var(--text-primary); }
.integration-card { max-width: 960px; }
.integration-card h2 { margin: 8px 0 12px; font-size: 22px; font-weight: 650; }
.integration-card > p:not(.eyebrow) { color: var(--text-secondary); line-height: 1.8; }
.slug-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 20px 0; }
.slug { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.slug b { font-size: 11px; font-weight: 550; }
.slug code, code { color: var(--primary); font-family: "Cascadia Code", Consolas, monospace; font-size: 11px; }
pre { overflow: auto; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-md); background: #091017; line-height: 1.7; }
pre code { color: #b8c5ca; }
.notice { padding: 12px 16px; border-left: 3px solid var(--primary); background: rgba(61,217,189,.06); color: #a8b7bd; font-size: 12px; line-height: 1.6; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 40; padding: 12px 16px; border: 1px solid #2d675a; border-radius: var(--radius-md); background: #153128; color: #c2f1e4; box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(12px); transition: opacity 200ms, transform 200ms; }
.toast.show { opacity: 1; transform: none; }
.toast.error { border-color: #65333a; background: #321c20; color: #f1bbc0; }
.dialog { width: min(440px, calc(100% - 32px)); padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text-primary); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog form { padding: 24px; }
.dialog-head h2 { margin: 0 0 8px; font-size: 20px; font-weight: 650; }
.dialog-head p { margin: 0 0 20px; color: var(--text-secondary); font-size: 12px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

html[data-theme="light"] label { color: #42565f; }
html[data-theme="light"] input, html[data-theme="light"] select { background: #fff; }
html[data-theme="light"] .soft { color: #41545d; }
html[data-theme="light"] .app-card:hover, html[data-theme="light"] .app-card.selected { border-color: #83b6ae; background: #f1f8f7; }
html[data-theme="light"] .mini-status span { background: #eaf0f2; }
html[data-theme="light"] th { background: #f0f4f5; }
html[data-theme="light"] tbody tr:hover { background: #f6f9fa; }
html[data-theme="light"] pre { background: #f3f6f7; }
html[data-theme="light"] pre code { color: #354950; }
html[data-theme="light"] .page-error { color: #9e303a; }
html[data-theme="light"] .check-grid label { color: #4f626b; }
html[data-theme="light"] .toast { background: #e9f7f2; color: #176d59; }
html[data-theme="light"] .toast.error { background: #faecee; color: #9f303a; }

@media (max-width: 1200px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .app-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1023px) {
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform 200ms; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { position: fixed; inset: 0; z-index: 15; display: block; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity 200ms; }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }
  .content { padding: 24px; }
  .menu-button { display: block; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .topbar { align-items: flex-start; }
  .live { font-size: 0; }
  .table-tools { grid-template-columns: 1fr 1fr; }
  .search-label { grid-column: 1 / -1; }
  .slug-list { grid-template-columns: 1fr; }
}
@media (max-width: 639px) {
  .content { padding: 20px 16px 48px; }
  .summary-grid, .app-grid { grid-template-columns: 1fr; }
  .login-card { padding: 32px 24px; }
  .check-grid, .table-tools { grid-template-columns: 1fr; }
  .search-label { grid-column: auto; }
  .section-head { align-items: flex-start; gap: 12px; }
  .event-item { grid-template-columns: 12px 1fr; }
  .event-time { grid-column: 2; }
}
