:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #182230;
  --muted: #667085;
  --line: #d9e3ee;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --blue: #2563eb;
  --amber: #b54708;
  --green: #067647;
  --red: #b42318;
  --shadow: 0 18px 50px rgba(16, 24, 40, .10);
  --mono: Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(180deg, #ffffff 0, var(--bg) 280px);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 7px;
  padding: 0 15px;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}

button:hover {
  border-color: #98a2b3;
  transform: translateY(-1px);
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

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

.primary:hover {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}

.shell {
  min-height: 100vh;
  padding: 22px;
}

.login-view {
  min-height: calc(100vh - 44px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(430px, 100%);
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  display: grid;
  gap: 18px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e6fffb;
  color: var(--teal-dark);
  font-weight: 800;
  border: 1px solid #99f6e4;
}

.brand-mark.small {
  width: 46px;
  height: 46px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

input:focus {
  outline: 3px solid rgba(15, 118, 110, .16);
  border-color: var(--teal);
}

.error-text {
  color: var(--red);
  min-height: 18px;
  font-size: 13px;
}

.app-view {
  width: min(1220px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.topbar,
.panel,
.status-card {
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(16, 24, 40, .06);
}

.topbar {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.title-block {
  display: flex;
  align-items: center;
  gap: 13px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.history-control {
  display: grid;
  grid-template-columns: auto 72px;
  align-items: center;
  gap: 7px;
  height: 40px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.history-control input {
  width: 72px;
  height: 40px;
  padding: 0 9px;
}

.sync-result {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.hero-status {
  display: grid;
  grid-template-columns: 1.45fr .75fr .9fr;
  gap: 16px;
}

.status-card {
  padding: 16px;
  display: grid;
  gap: 10px;
  min-height: 132px;
}

.status-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status-card strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.status-card-head,
.panel-head,
.logs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.signal-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.signal-dot {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: #eef4ff;
  border: 1px solid #c7d7fe;
  position: relative;
}

.signal-dot::after {
  content: "";
  position: absolute;
  inset: 17px;
  border-radius: 999px;
  background: var(--blue);
  box-shadow: 0 0 0 7px rgba(37, 99, 235, .12);
}

.main-status.open .signal-dot {
  background: #ecfdf3;
  border-color: #abefc6;
}

.main-status.open .signal-dot::after {
  background: var(--green);
  box-shadow: 0 0 0 7px rgba(6, 118, 71, .14);
}

.main-status.qr .signal-dot,
.main-status.connecting .signal-dot,
.main-status.starting .signal-dot {
  background: #fffaeb;
  border-color: #fedf89;
}

.main-status.qr .signal-dot::after,
.main-status.connecting .signal-dot::after,
.main-status.starting .signal-dot::after {
  background: var(--amber);
  box-shadow: 0 0 0 7px rgba(181, 71, 8, .12);
}

.main-status.closed .signal-dot,
.main-status.error .signal-dot {
  background: #fef3f2;
  border-color: #fecdca;
}

.main-status.closed .signal-dot::after,
.main-status.error .signal-dot::after {
  background: var(--red);
  box-shadow: 0 0 0 7px rgba(180, 35, 24, .12);
}

.pill {
  width: fit-content;
  min-width: 92px;
  border-radius: 999px;
  padding: 6px 11px;
  background: #f2f4f7;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.pill.open { background: #dcfae6; color: var(--green); }
.pill.qr,
.pill.connecting,
.pill.starting { background: #fef0c7; color: var(--amber); }
.pill.closed,
.pill.error { background: #fee4e2; color: var(--red); }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(320px, 420px);
  gap: 16px;
}

.panel {
  padding: 16px;
}

.targets-list {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.target-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 13px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.target-card strong {
  display: block;
  font-size: 15px;
}

.target-card span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.target-badge {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  background: #fee4e2;
  color: var(--red);
}

.target-card.connected .target-badge {
  background: #dcfae6;
  color: var(--green);
}

.qr-panel {
  min-height: 360px;
}

.qr-box {
  margin-top: 14px;
  min-height: 292px;
  border: 1px dashed #b8c4cf;
  border-radius: 8px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 18px;
  background: #fbfdff;
}

.qr-box img {
  width: min(264px, 100%);
  height: auto;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(16, 24, 40, .08);
}

.logs-section {
  padding: 0;
  overflow: hidden;
}

.logs-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.logs {
  height: 380px;
  overflow: auto;
  background: #111827;
  color: #e5e7eb;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
}

.log-line {
  display: grid;
  grid-template-columns: 92px 72px 1fr;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
}

.log-time { color: #9ca3af; }
.log-level { color: #bfdbfe; font-weight: 700; }
.log-line.success .log-level { color: #86efac; }
.log-line.warn .log-level { color: #fcd34d; }
.log-line.error .log-level { color: #fca5a5; }

.sr-value {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@media (max-width: 920px) {
  .hero-status,
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .shell { padding: 12px; }
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }
  .top-actions button { flex: 1 1 100px; }
  .log-line {
    grid-template-columns: 1fr;
    gap: 1px;
    padding: 7px 0;
  }
}
