:root {
  --bg: #f4f4f6;
  --card: #ffffff;
  --line: #e5e5ea;
  --text: #1c1c1f;
  --muted: #6a6a72;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #d6453a;
  --ok: #1f8a4c;
  --warn: #a06800;
  --bg-mine: #4f46e5;
  --bg-pc: #efeff3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 15px;
  min-height: 100vh;
}
body { min-height: 100dvh; }

.hidden { display: none !important; }

/* ---------- Generic ---------- */

button {
  font: inherit;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  padding: 10px 14px;
  background: #e5e5ea;
  color: var(--text);
}
button.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.compact { padding: 6px 12px; font-size: 13px; }
button.flex1 { flex: 1; }
button.danger {
  background: var(--danger);
  color: #fff;
  font-weight: 600;
}
button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
}
button.back {
  background: none;
  font-size: 22px;
  width: 36px; height: 36px;
  border-radius: 18px;
  padding: 0;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
label input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
label input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.spacer { flex: 1; }

/* ---------- App bar (shared header) ---------- */

.appbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.appbar .brand { display: flex; gap: 10px; align-items: center; flex: 1; }
.appbar .brand .logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 18px;
}
.appbar h1 { margin: 0; font-size: 17px; line-height: 1.2; }
.appbar .sub { margin: 0; font-size: 11px; color: var(--muted); }

.appbar .title-row {
  display: flex; align-items: center; gap: 8px;
  flex: 1; min-width: 0;
}
.appbar .title-row #current-pc-name {
  font-weight: 700; font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pc-switcher {
  font: inherit;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  max-width: 180px;
}

/* ---------- List view ---------- */

.view.list {
  padding: 0 0 24px;
}
.pc-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
}
.pc-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.pc-info { flex: 1; min-width: 0; }
.pc-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pc-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pc-actions { display: flex; gap: 6px; }
.empty-hint {
  padding: 24px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Form view ---------- */

.view.form {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
}
.view.form .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.04);
}
.hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.footnote {
  margin-top: 14px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
.footnote code {
  background: #eee;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 11px;
}

/* ---------- Viewer view ---------- */

.view.viewer {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.viewer-bar { padding: 8px 10px; }

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.statusbar .updated { margin-left: auto; font-size: 11px; }
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #999;
}
.dot-idle { background: #aaa; }
.dot-connecting { background: var(--warn); }
.dot-connected { background: var(--ok); }
.dot-disconnected, .dot-pc-offline { background: var(--warn); }
.dot-auth-failed, .dot-error { background: var(--danger); }

.screen {
  position: relative;
  background: #111;
  height: 42vh;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.screen img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.placeholder {
  color: #888;
  font-size: 13px;
  padding: 16px;
  text-align: center;
}

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.controls .primary { padding: 8px 14px; }
.meta { color: var(--muted); font-size: 12px; }

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-height: 0;
}
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}
.msg .bubble {
  padding: 8px 12px;
  border-radius: 14px;
  line-height: 1.3;
  word-break: keep-all;
  white-space: pre-wrap;
}
.msg .meta { font-size: 10px; margin-top: 2px; color: var(--muted); }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.mine .bubble {
  background: var(--bg-mine); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.pc { align-self: flex-start; align-items: flex-start; }
.msg.pc .bubble {
  background: var(--bg-pc); color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--card);
  border-top: 1px solid var(--line);
}
.chat-input-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.chat-input-row input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat-input-row .primary { padding: 8px 14px; }

@media (min-width: 720px) {
  .view.list, .view.form, .view.viewer { max-width: 720px; margin: 0 auto; }
  .view.viewer { box-shadow: 0 0 24px rgba(0,0,0,0.05); }
  .screen { height: 50vh; }
}
