:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #dce2ea;
  --text: #18212f;
  --muted: #647086;
  --brand: #1767c2;
  --brand-strong: #0b4f9b;
  --good: #13795b;
  --warn: #9a5b00;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.primary:hover {
  background: var(--brand-strong);
}

.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.danger {
  background: var(--danger);
  color: #fff;
}

.wide {
  width: 100%;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: calc(18px + env(safe-area-inset-top)) 24px 18px;
  background: rgba(245, 247, 250, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.header-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 26px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 16px;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 6px;
  font-size: 15px;
  letter-spacing: 0;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.bridge-pill {
  display: none;
  width: fit-content;
  margin: 10px 0 0;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.header-actions,
.card-actions,
.log-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  gap: 18px;
  padding: 18px 24px 28px;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.workspace {
  min-width: 0;
}

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

.panel {
  padding: 16px;
}

.env-list {
  margin: 0;
}

.env-list div {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #eef2f6;
}

.env-list div:last-child {
  border-bottom: 0;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field span,
.param-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  min-height: 110px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.log-view {
  min-height: 240px;
  max-height: 460px;
  overflow: auto;
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 6px;
  background: #101828;
  color: #eef4ff;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tab {
  flex: none;
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.test-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.test-card {
  display: flex;
  flex-direction: column;
  min-height: 360px;
  padding: 14px;
}

.card-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.badge {
  flex: none;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}

.badge.safe {
  color: var(--good);
  background: #e8f6f1;
}

.badge.confirm {
  color: var(--warn);
  background: #fff4dc;
}

.badge.danger {
  color: var(--danger);
  background: #ffe7e4;
}

.meta {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.expected {
  margin: 0 0 12px;
  padding: 10px;
  border-left: 3px solid var(--brand);
  background: #f2f7ff;
  color: #24344d;
  font-size: 13px;
  line-height: 1.5;
}

.card-spacer {
  flex: 1;
}

.result-box {
  min-height: 64px;
  max-height: 150px;
  overflow: auto;
  margin-top: 10px;
  padding: 10px;
  border-radius: 6px;
  background: #f7f9fc;
  color: #314158;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.24);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-body {
  width: min(420px, calc(100vw - 32px));
  padding: 18px;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 18px 0 0;
  padding: 0;
}

@media (max-width: 880px) {
  body {
    background: #fff;
  }

  .app-header {
    position: static;
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: calc(12px + env(safe-area-inset-top)) 12px 12px;
  }

  h1 {
    font-size: 20px;
    line-height: 1.2;
  }

  h2 {
    font-size: 15px;
  }

  .subtitle {
    display: none;
  }

  .bridge-pill {
    display: block;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .header-actions button {
    width: 100%;
    min-height: 44px;
    padding: 8px 6px;
    font-size: 14px;
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 12px calc(18px + env(safe-area-inset-bottom));
  }

  .workspace {
    order: 1;
  }

  .side-panel {
    order: 2;
    gap: 10px;
  }

  .panel,
  .test-card {
    border-radius: 7px;
    box-shadow: none;
  }

  .panel {
    padding: 12px;
  }

  .env-list div {
    grid-template-columns: 56px 1fr;
    gap: 6px;
    padding: 7px 0;
    font-size: 12px;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 8;
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -12px 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    min-height: 38px;
    padding: 7px 11px;
    font-size: 13px;
    white-space: nowrap;
  }

  .test-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .test-card {
    min-height: auto;
    padding: 12px;
  }

  .card-title {
    align-items: center;
  }

  h3 {
    font-size: 15px;
  }

  .meta,
  .expected {
    font-size: 12px;
  }

  .expected {
    margin-bottom: 10px;
    padding: 8px;
  }

  textarea {
    min-height: 92px;
    font-size: 11px;
  }

  input,
  textarea {
    padding: 8px;
  }

  .card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 7px;
  }

  .card-actions button {
    min-height: 42px;
    padding: 7px 5px;
    font-size: 13px;
  }

  .result-box {
    max-height: 120px;
    min-height: 52px;
    font-size: 11px;
  }

  .log-view {
    min-height: 130px;
    max-height: 220px;
    font-size: 11px;
  }

  .dialog-body {
    padding: 16px;
  }

  menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  menu button {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .header-actions,
  .card-actions {
    grid-template-columns: 1fr;
  }

  .badge {
    padding: 3px 6px;
    font-size: 11px;
  }
}
