:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: rgba(15, 23, 42, 0.86);
  --surface-strong: #101827;
  --panel: rgba(17, 25, 40, 0.78);
  --border: rgba(148, 163, 184, 0.18);
  --text: #e5eefb;
  --muted: #91a1b7;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #eef4fb;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: #ffffff;
  --panel: rgba(255, 255, 255, 0.92);
  --border: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.24), transparent 34rem),
    radial-gradient(circle at 80% 20%, rgba(34, 197, 94, 0.12), transparent 26rem),
    var(--bg);
}

button, input, select, textarea { font: inherit; }

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 32px; }
.brand-mark { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 14px; background: linear-gradient(135deg, var(--accent), #22c55e); color: #00111d; font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand small, .eyebrow { color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }

.nav-list { display: grid; gap: 8px; }
.nav-list button {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.nav-list button:hover, .nav-list button.active { color: var(--text); background: rgba(56, 189, 248, 0.12); }

.deploy-card { position: absolute; left: 24px; right: 24px; bottom: 24px; padding: 16px; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); }
.deploy-card p { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

.main { padding: 28px; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
h1, h2 { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 44px); letter-spacing: -0.04em; }
h2 { font-size: 20px; }
.toolbar, .button-row, .send-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }

button { border: 0; border-radius: 12px; padding: 10px 14px; color: #eff6ff; background: var(--accent-strong); cursor: pointer; }
button.secondary, .ghost-btn { color: var(--text); border: 1px solid var(--border); background: var(--surface-strong); }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.primary-btn { box-shadow: 0 10px 28px rgba(14, 165, 233, 0.24); }
.link-btn { padding: 0; color: var(--accent); background: transparent; }

.notice { display: flex; gap: 8px; margin-bottom: 18px; padding: 14px 16px; border: 1px solid rgba(245, 158, 11, 0.32); border-radius: 16px; background: rgba(245, 158, 11, 0.08); color: var(--muted); }
.notice strong { color: var(--text); white-space: nowrap; }

.page { display: none; }
.page.active { display: block; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card, .panel { border: 1px solid var(--border); background: var(--panel); border-radius: 22px; box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.metric-card { padding: 18px; }
.metric-card span, .metric-card small { color: var(--muted); }
.metric-card strong { display: block; margin: 8px 0; font-size: 30px; letter-spacing: -0.04em; }

.panel { padding: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.status { border-radius: 999px; padding: 5px 10px; font-size: 12px; border: 1px solid currentColor; }
.online { color: var(--ok); }
.offline { color: var(--danger); }

.overview-panel { min-height: 320px; }
.workflow-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.workflow-grid div { min-height: 150px; padding: 18px; border: 1px solid var(--border); border-radius: 18px; background: rgba(148, 163, 184, 0.08); }
.workflow-grid strong, .workflow-grid span { display: block; }
.workflow-grid span { margin-top: 10px; color: var(--muted); line-height: 1.7; }

.comm-panel { min-height: calc(100vh - 190px); }
.form-grid { display: grid; gap: 12px; margin-bottom: 14px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, select, textarea { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; color: var(--text); background: var(--surface-strong); outline: none; }
textarea { resize: vertical; font-family: "Cascadia Code", Consolas, monospace; }

.terminal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 18px 0 14px; }
.terminal-box textarea { min-height: 360px; line-height: 1.6; }
.send-row { justify-content: space-between; padding-top: 4px; }
.send-row label { min-width: 180px; }
.device-summary { margin: 14px 0 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px; color: var(--muted); background: rgba(148, 163, 184, 0.08); }

.log-panel { min-height: 460px; }
.full-log-panel { min-height: calc(100vh - 190px); }
.log-list { display: grid; gap: 10px; max-height: 330px; padding: 0; margin: 0; list-style: none; overflow: auto; }
.log-list.large { max-height: calc(100vh - 310px); }
.log-list li { display: grid; grid-template-columns: 88px 1fr; gap: 10px; padding: 12px; border-radius: 12px; background: rgba(148, 163, 184, 0.08); }
.log-list time { color: var(--muted); font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
.warn { color: var(--warn); }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .deploy-card { position: static; margin-top: 24px; }
  .metric-grid, .workflow-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .main, .sidebar { padding: 18px; }
  .topbar, .notice { flex-direction: column; align-items: flex-start; }
  .metric-grid, .workflow-grid, .terminal-grid, .form-grid.three, .form-grid.four { grid-template-columns: 1fr; }
  .terminal-box textarea { min-height: 260px; }
}
