:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f0f4f8;
  --text: #17202a;
  --muted: #667085;
  --line: #d9e0e8;
  --blue: #2563eb;
  --green: #168a5b;
  --amber: #b7791f;
  --rose: #c2415b;
  --shadow: 0 12px 35px rgba(31, 42, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: #aeb9c7;
}

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

button.ghost {
  background: transparent;
}

button.danger {
  border-color: #f0b8c4;
  color: var(--rose);
}

button.wide {
  width: 100%;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 11px;
}

textarea {
  min-height: 74px;
  padding-block: 9px;
  resize: vertical;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #eef3f7;
  padding: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #14213d;
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.panel-title small,
.eyebrow {
  color: var(--muted);
}

.workspace {
  padding: 24px;
}

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

.topbar h1 {
  margin: 2px 0 0;
  font-size: 28px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  font-size: 13px;
}

.topbar-actions,
.token-row,
.form-actions,
.preview-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sidebar .panel {
  box-shadow: none;
  margin-bottom: 14px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
}

.panel-title span {
  font-weight: 700;
}

.auth-panel {
  padding-bottom: 12px;
}

.auth-panel .token-row {
  padding: 14px 12px 10px;
}

.auth-panel .wide {
  margin: 0 12px;
  width: calc(100% - 24px);
}

.grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.form-panel,
.details-panel,
.preview-panel {
  overflow: hidden;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}

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

.wide-field {
  grid-column: 1 / -1;
}

.protocol-section {
  border-top: 1px solid var(--line);
  padding: 16px;
}

.protocol-section > span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.checks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.port-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface-strong);
}

.check input {
  width: 16px;
  min-height: 16px;
}

.form-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding: 14px 16px;
}

.profile-list,
.subscription-list {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.profile-item,
.subscription-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.profile-item.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.profile-head,
.subscription-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.profile-head strong,
.subscription-head strong {
  overflow-wrap: anywhere;
}

.profile-meta,
.subscription-url {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.profile-actions,
.subscription-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.empty-state {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border: 1px dashed #aeb9c7;
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  margin-bottom: 18px;
}

.empty-state strong {
  display: block;
  margin-bottom: 4px;
  font-size: 18px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.notice {
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: #e9f7ef;
  color: var(--green);
}

.notice.error {
  background: #fff1f2;
  color: var(--rose);
}

.hidden {
  display: none;
}

.preview-panel {
  margin-top: 18px;
}

.preview-controls {
  min-width: min(430px, 100%);
}

#clientSelect {
  min-width: 170px;
}

pre {
  min-height: 280px;
  max-height: 520px;
  margin: 0;
  overflow: auto;
  background: #111827;
  color: #e6edf5;
  padding: 16px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .app-shell,
  .grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar,
  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-title {
    justify-content: center;
    padding: 12px 16px;
  }
}

@media (max-width: 640px) {
  .workspace,
  .sidebar {
    padding: 14px;
  }

  .field-grid,
  .checks,
  .port-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .token-row,
  .form-actions,
  .preview-controls {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }
}
