:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #697586;
  --line: #d9dee7;
  --active: #176b54;
  --active-soft: #dff3ec;
  --paused: #8a4b11;
  --paused-soft: #fff0dc;
  --focus: #315ea8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto;
}

.topbar,
.toolbar,
.instances,
.prompt-editor,
.settings-panel,
.table-wrap,
.tabs {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

h1 {
  margin: 0 0 4px;
  font-size: 22px;
  line-height: 1.2;
}

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

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 20px;
}

.icon-button:hover {
  border-color: var(--focus);
}

.tabs {
  display: flex;
  gap: 4px;
  margin-top: 14px;
  padding: 4px;
  width: fit-content;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  height: 34px;
}

.tab.active {
  background: #edf2f7;
  color: var(--text);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  margin-top: 14px;
}

.instances {
  margin-top: 14px;
  padding: 14px;
}

.prompt-editor {
  margin-top: 14px;
  padding: 14px;
}

.settings-panel {
  margin-top: 14px;
  padding: 14px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 12px;
}

h2 {
  margin: 0;
  font-size: 15px;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.instance-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(220px, 2fr) minmax(140px, 1fr) auto auto auto;
  gap: 10px;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
}

.settings-form label:not(.checkbox-line) {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.instance-form input[type="text"],
.instance-form input[type="url"],
.instance-form input[type="password"],
.settings-form input,
.settings-form select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

.prompts-form {
  display: grid;
  gap: 14px;
}

.prompts-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.prompts-form textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.prompts-form textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--focus), transparent 75%);
  border-color: var(--focus);
}

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

.settings-form .form-actions {
  grid-column: 1 / -1;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

.status-item {
  display: grid;
  gap: 4px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfd;
}

.status-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-item strong {
  overflow-wrap: anywhere;
}

.prompts-form button,
.settings-form button {
  border: 1px solid var(--focus);
  background: var(--focus);
  color: #fff;
}

button {
  height: 36px;
  border-radius: 8px;
  padding: 0 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.instance-form button,
.inline-edit button {
  border: 1px solid var(--focus);
  background: var(--focus);
  color: #fff;
}

.secondary {
  border: 1px solid var(--line) !important;
  background: #fff !important;
  color: var(--text) !important;
}

.danger {
  border: 1px solid #a23a3a;
  background: #a23a3a;
  color: #fff;
}

.checkbox-line {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.instance-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.instance-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.instance-item > div:first-child {
  display: grid;
  gap: 3px;
}

.instance-item code {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.pill {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.instance-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.active-pill {
  background: var(--active-soft);
  color: var(--active);
}

.paused-pill {
  background: var(--paused-soft);
  color: var(--paused);
}

.search {
  display: grid;
  gap: 6px;
  min-width: 280px;
  flex: 1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.search input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  font: inherit;
}

.search input:focus {
  outline: 2px solid color-mix(in srgb, var(--focus), transparent 75%);
  border-color: var(--focus);
}

.segments {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  height: 38px;
}

.segment {
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 600;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: #edf2f7;
  color: var(--text);
}

.table-wrap {
  margin-top: 14px;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #fbfcfd;
}

tr:last-child td {
  border-bottom: 0;
}

.group-name {
  display: grid;
  gap: 4px;
  min-width: 220px;
}

.name-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-name strong {
  font-size: 14px;
}

.text-action {
  height: 28px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--focus);
  padding: 0 4px;
  font-size: 12px;
}

.text-action:disabled {
  color: var(--muted);
  cursor: not-allowed;
  text-decoration: none;
}

.danger-link {
  height: 28px;
  border: 1px solid transparent;
  background: transparent;
  color: #a23a3a;
  padding: 0 4px;
  font-size: 12px;
}

.danger-link:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.text-action:hover {
  text-decoration: underline;
}

.inline-edit {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.inline-edit input {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font: inherit;
}

.group-name code {
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.preview {
  max-width: 380px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.count,
.participants,
.instance-cell,
.date-cell {
  color: var(--muted);
  white-space: nowrap;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--paused-soft);
  border: 1px solid #e3c391;
  border-radius: 999px;
  transition: 0.15s ease;
}

.slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--paused);
  transition: 0.15s ease;
}

.switch input:checked + .slider {
  background: var(--active-soft);
  border-color: #86c5b1;
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
  background: var(--active);
}

.empty {
  padding: 34px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 760px) {
  .app {
    width: calc(100vw - 20px);
    margin: 10px auto;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .instance-form {
    grid-template-columns: 1fr;
  }

  .settings-form {
    grid-template-columns: 1fr;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segments {
    width: 100%;
  }

  .segment {
    flex: 1;
  }

  .table-wrap {
    overflow-x: auto;
  }

  table {
    min-width: 980px;
  }
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
}

.confirm-dialog::backdrop {
  background: rgb(23 32 42 / 45%);
}

.confirm-dialog form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.confirm-dialog h2 {
  font-size: 18px;
}

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