:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f3f5f6;
  color: #202428;
  font-size: 15px;
  --border: #d8dde0;
  --muted: #667078;
  --panel: #ffffff;
  --ink: #202428;
  --accent: #1264a3;
  --accent-dark: #0c4e82;
  --success: #147d4d;
  --warning: #a05a00;
  --danger: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f3f5f6;
}

button,
input { font: inherit; }

button { letter-spacing: 0; }

button:focus-visible,
input:focus-visible,
tr:focus-visible {
  outline: 3px solid rgba(18, 100, 163, 0.25);
  outline-offset: 1px;
}

.app-header {
  height: 64px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #f8fafb;
  background: #202428;
  border-bottom: 1px solid #111416;
}

.brand,
.header-actions,
.session-actions,
.dialog-heading,
.pane-heading,
.search-field {
  display: flex;
  align-items: center;
}

.brand { gap: 10px; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid #69737a;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  color: #b9d9ee;
}

h1,
h2,
p { margin: 0; }

.brand h1 { font-size: 17px; font-weight: 700; }
.brand p { color: #adb6bc; font-size: 12px; margin-top: 2px; }
.header-actions { gap: 10px; }

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #c5ccd0;
  font-size: 12px;
}

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #889197;
}

.status-dot.online::before { background: #35b87f; }
.status-dot.connecting::before { background: #e9a23b; }

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
}

.icon-button:hover:not(:disabled) { background: rgba(127, 139, 147, 0.16); border-color: rgba(127, 139, 147, 0.22); }
.icon-button:disabled { opacity: 0.36; cursor: default; }
.icon-button svg { width: 19px; height: 19px; }
.primary-icon { color: white; background: var(--accent); }
.primary-icon:hover:not(:disabled) { background: var(--accent-dark); }
.danger-button { color: var(--danger); }

.auth-shell {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: start center;
  padding: 72px 20px;
}

.auth-panel {
  width: min(420px, 100%);
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(23, 30, 34, 0.08);
}

.auth-panel h2 { font-size: 20px; margin-bottom: 22px; }
.form-stack { display: grid; gap: 16px; }

.auth-divider {
  display: grid;
  margin: 20px 0;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.auth-divider::before, .auth-divider::after { height: 1px; background: var(--border); content: ""; }
.google-sign-in { width: 100%; min-height: 44px; }
.google-button-host { display: flex; min-height: 44px; justify-content: center; }
.google-sign-in[data-state="busy"] { opacity: .65; pointer-events: none; }
.google-status { margin: 8px 0 0; color: var(--muted); font-size: 12px; text-align: center; }
.google-status:empty { display: none; }
.google-sign-in[data-state="error"] .google-status { color: var(--danger); }

label {
  display: grid;
  gap: 6px;
  color: #3f484e;
  font-size: 13px;
  font-weight: 600;
}

input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bfc6ca;
  border-radius: 4px;
}

input:hover { border-color: #8e999f; }

.primary-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  color: white;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 5px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.primary-button:disabled { opacity: 0.5; cursor: wait; }
.primary-button svg { width: 18px; height: 18px; }

.secondary-button {
  min-height: 40px;
  padding: 8px 14px;
  color: var(--accent);
  background: transparent;
  border: 1px solid #aeb9bf;
  border-radius: 5px;
  font-weight: 700;
  cursor: pointer;
}

.secondary-button:hover { background: #eef3f6; border-color: #82919a; }

.error-text { min-height: 18px; color: var(--danger); font-size: 13px; }
#auth-error { margin-top: 12px; text-align: center; }

.qr-frame {
  width: 256px;
  max-width: 100%;
  padding: 8px;
  margin: 0 auto;
  background: white;
  border: 1px solid var(--border);
}
.qr-frame img { display: block; width: 100%; }

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

.device-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.pane-heading {
  min-height: 72px;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.pane-heading h2 { font-size: 17px; }
.pane-heading span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }

.search-field {
  position: relative;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.search-field svg { position: absolute; left: 22px; width: 17px; color: var(--muted); }
.search-field input { min-height: 36px; padding-left: 34px; background: #f8f9fa; }

.device-table-wrap { position: relative; min-height: 180px; flex: 1; overflow: auto; }
.device-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.device-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 10px;
  color: var(--muted);
  background: #f7f8f9;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-align: left;
  text-transform: uppercase;
}
.device-table th:nth-child(1) { width: 44%; }
.device-table th:nth-child(2) { width: 26%; }
.device-table th:nth-child(3) { width: 30%; }
.device-table td {
  padding: 10px;
  border-bottom: 1px solid #e8ebed;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.device-table tr { cursor: default; }
.device-table tr:hover { background: #f3f7fa; }
.device-table tr.selected { background: #e7f1f8; box-shadow: inset 3px 0 var(--accent); }
.device-table tr.identity-mismatch { background: #fff0ef; }
.device-name { font-weight: 700; }
.state-label { display: inline-flex; align-items: center; gap: 5px; }
.state-label::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #8c969c; }
.state-label.online::before { background: var(--success); }
.state-label.mismatch { color: var(--danger); }
.state-label.mismatch::before { background: var(--danger); }
.fingerprint-short { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: #4f5960; }

.empty-state {
  position: absolute;
  inset: 50px 0 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}
.empty-state svg { width: 32px; height: 32px; }

.device-details { padding: 14px 16px; border-top: 1px solid var(--border); background: #fafbfb; }
.detail-row { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 12px; }
.detail-row span,
.fingerprint-block span { color: var(--muted); }
.fingerprint-block { display: grid; gap: 5px; font-size: 12px; }
.fingerprint-block code { overflow-wrap: anywhere; line-height: 1.5; color: #30383d; }

.session-pane { min-width: 0; display: grid; grid-template-rows: 60px 1fr; background: #cfd4d7; }
.session-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  color: var(--ink);
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.session-summary { min-width: 0; }
.session-summary strong,
.session-summary span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-summary strong { font-size: 14px; }
.session-summary span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.session-actions { gap: 2px; }

.remote-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow: hidden;
  background: #111416;
}
.remote-stage video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: none;
  user-select: none;
}
.remote-placeholder {
  position: absolute;
  display: grid;
  justify-items: center;
  gap: 12px;
  color: #9ca6ac;
  font-size: 13px;
}
.remote-placeholder svg { width: 42px; height: 42px; }
.session-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  color: #eef4f1;
  background: rgba(24, 34, 30, 0.88);
  border: 1px solid rgba(144, 191, 167, 0.35);
  border-radius: 4px;
  font-size: 11px;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #49cf92; }

.dialog-shell {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 18px 60px rgba(19, 25, 29, 0.24);
}
.dialog-shell::backdrop { background: rgba(24, 29, 33, 0.48); }
.dialog-shell form { padding: 20px; }
.dialog-heading { justify-content: space-between; }
.dialog-heading h2 { font-size: 18px; }
.dialog-close { margin-right: -8px; }
.pairing-code-panel {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 16px;
  background: #f6f8f9;
  border: 1px solid var(--border);
}
.pairing-code-panel span,
.pairing-code-panel small { color: var(--muted); font-size: 12px; }
.pairing-code-panel output { font: 800 30px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 11px 13px;
  color: white;
  background: #30373b;
  border: 1px solid #4c565c;
  border-radius: 5px;
  box-shadow: 0 8px 24px rgba(22, 28, 32, 0.24);
  font-size: 13px;
}

[hidden] { display: none !important; }

@media (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(260px, 42%) 1fr; }
  .device-pane { border-right: 0; border-bottom: 1px solid var(--border); }
  .device-details { display: none; }
  .session-pane { grid-template-rows: 54px 1fr; }
  .session-toolbar { padding: 6px 10px; }
  .remote-stage { padding: 8px; }
}
