:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-muted: #f0f3ee;
  --border: #d8dfd1;
  --border-strong: #aeb9a4;
  --text: #1f2933;
  --muted: #667085;
  --primary: #136f63;
  --primary-hover: #0f5d53;
  --danger: #b42318;
  --danger-hover: #8f1d14;
  --warning-bg: #fff7df;
  --warning-border: #e1bb5d;
  --warning-text: #674600;
  --success-bg: #e4f4ec;
  --success-text: #155b36;
  --idle-bg: #eef1f4;
  --idle-text: #475467;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.42;
}

button,
input,
select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-page {
  width: min(420px, 100%);
}

.login-card {
  display: grid;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form .button {
  width: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(92px, 1fr) auto minmax(92px, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px clamp(12px, 2vw, 20px);
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--border);
}

.topbar-center {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.topbar-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.account-label {
  max-width: 120px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0;
}

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

.control-row,
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.monitor-actions {
  flex-wrap: nowrap;
}

.monitor-actions .button {
  min-width: 84px;
}

.warning-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: min(1180px, calc(100% - 20px));
  margin: 10px auto 0;
  border: 1px solid var(--warning-border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--warning-text);
  background: var(--warning-bg);
  font-weight: 700;
}

.workspace {
  width: min(1180px, calc(100% - 20px));
  margin: 10px auto 20px;
}

.app-shell {
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.side-tabs {
  position: sticky;
  top: 62px;
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tab-button {
  width: 100%;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 9px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}

.tab-button:hover {
  background: var(--surface-muted);
}

.tab-button.is-active {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
}

.tab-content,
.tab-panel,
.page-section {
  min-width: 0;
}

.tab-panel,
.stacked-layout {
  display: grid;
  gap: 10px;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.compact-heading {
  margin-bottom: 8px;
}

.panel h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
}

.muted {
  display: block;
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status-message {
  max-width: 560px;
}

.message-success,
.message-error,
.message-info {
  margin-top: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  font-weight: 700;
}

.message-success {
  color: var(--success-text);
  background: var(--success-bg);
  border-color: #b7dec8;
}

.message-error {
  color: var(--danger);
  background: #fff1f0;
  border-color: #fecdca;
}

.message-info {
  color: var(--primary);
  background: #e7f2ef;
  border-color: #b9d9d2;
}

.button {
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  white-space: nowrap;
}

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

.button:focus-visible,
.tab-button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(19, 111, 99, 0.22);
  outline-offset: 1px;
}

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

.button-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.button-secondary {
  color: var(--text);
  background: var(--surface-muted);
  border-color: var(--border);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--border-strong);
}

.button-danger {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.button-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-running {
  color: var(--success-text);
  background: var(--success-bg);
}

.status-idle {
  color: var(--idle-text);
  background: var(--idle-bg);
}

.metrics {
  display: grid;
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--border);
}

.dashboard-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.login-metrics {
  grid-template-columns: minmax(130px, 180px) minmax(0, 1fr);
  margin-top: 10px;
}

.metric {
  min-width: 0;
  padding: 8px 9px;
  background: var(--surface);
}

.metric dt {
  min-height: 16px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.metric dd {
  margin: 3px 0 0;
  min-height: 21px;
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 750;
}

.metric-wide {
  grid-column: auto;
}

.token-value {
  max-height: 112px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

.form {
  display: grid;
  gap: 10px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.form-grid > .field-wide,
.form-grid > .field-hint,
.form-grid > .field-grid,
.form-grid > fieldset,
.form-grid > .form-actions {
  grid-column: 1 / -1;
}

.login-form-compact {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: end;
}

.aligned-actions {
  align-self: end;
  justify-content: flex-start;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 8px;
}

legend {
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 700;
}

.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

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

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 5px 9px;
}

input::placeholder {
  color: #98a2b3;
}

.secret-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.secret-toggle {
  min-width: 58px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}

.field-hint {
  margin: -3px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.field .field-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.rule-example {
  margin-top: -5px;
}

.filters-bar {
  display: grid;
  grid-template-columns: minmax(104px, 138px) minmax(118px, 150px) minmax(180px, 1fr) auto auto;
  align-items: end;
  gap: 7px;
  margin: 0 0 8px;
}

.logs-filters {
  grid-template-columns: minmax(104px, 138px) minmax(118px, 150px) minmax(118px, 150px) minmax(220px, 1fr) auto auto;
}

.filter-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

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

.filter-count {
  align-self: center;
  white-space: nowrap;
}

.events-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.events-preview {
  max-height: 360px;
}

.events-full {
  max-height: calc(100dvh - 142px);
}

.event-item {
  display: grid;
  gap: 5px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.event-main {
  display: grid;
  grid-template-columns: 136px 64px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
}

.event-time,
.event-level {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.event-level {
  justify-self: start;
  min-width: 52px;
  border-radius: 999px;
  padding: 2px 7px;
  text-align: center;
}

.event-level-success {
  color: var(--success-text);
  background: var(--success-bg);
}

.event-level-error {
  color: var(--danger);
  background: #fff1f0;
}

.event-level-info,
.event-level-pending {
  color: var(--primary);
  background: #e7f2ef;
}

.event-level-muted {
  color: var(--idle-text);
  background: var(--idle-bg);
}

.event-message {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.event-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 700;
}

.event-summary {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.event-details {
  min-width: 0;
}

.event-details summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.event-details pre {
  margin: 6px 0 0;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
  padding: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.38;
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.test-result-panel {
  padding: 12px;
}

.test-result {
  margin: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.test-result-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.test-result-heading > span:first-child {
  font-size: 12px;
  font-weight: 800;
}

.test-summary {
  margin: 7px 0 0;
  color: var(--text);
  font-size: 13px;
}

.test-result-subheading {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.test-result pre {
  margin: 7px 0 0;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  padding: 9px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.4;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.rule-list {
  display: grid;
  gap: 7px;
}

.queue-rule-row {
  display: grid;
  grid-template-columns: 62px auto minmax(150px, 1.15fr) auto minmax(132px, 1fr) auto minmax(92px, 0.7fr) minmax(120px, 0.9fr) auto;
  align-items: center;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.rule-enabled {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  font-size: 12px;
  font-weight: 700;
}

.rule-enabled input {
  width: 15px;
  min-height: 15px;
}

.rule-copy {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.rule-delete {
  min-width: 58px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(31, 41, 51, 0.36);
}

.modal-panel {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(16, 24, 40, 0.18);
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-heading h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

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

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

  .side-tabs {
    position: static;
    display: flex;
    overflow-x: auto;
  }

  .tab-button {
    flex: 0 0 auto;
    width: auto;
    min-width: 76px;
    text-align: center;
  }

  .queue-rule-row {
    grid-template-columns: 62px auto minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .events-full {
    max-height: 620px;
  }
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-center,
  .topbar-actions {
    grid-column: 1;
    justify-self: stretch;
  }

  .topbar-center {
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
  }

  .topbar h1 {
    text-align: center;
  }

  .topbar-actions {
    justify-content: center;
    flex-wrap: wrap;
  }

  .warning-banner {
    align-items: stretch;
    flex-direction: column;
    text-align: center;
  }

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

  .control-row,
  .form-actions {
    width: 100%;
  }

  .monitor-actions {
    flex-wrap: wrap;
  }

  .button,
  .monitor-actions .button {
    flex: 1 1 120px;
  }

  .workspace {
    width: min(100% - 16px, 1180px);
    margin-top: 8px;
  }

  .app-shell,
  .tab-panel,
  .stacked-layout {
    gap: 8px;
  }

  .side-tabs,
  .panel {
    padding: 10px;
  }

  .dashboard-metrics,
  .login-metrics,
  .form-grid,
  .field-grid,
  .password-form,
  .login-form-compact,
  .event-main,
  .filters-bar,
  .logs-filters,
  .secret-input,
  .queue-rule-row {
    grid-template-columns: 1fr;
  }

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

  .events-preview,
  .events-full {
    max-height: 360px;
  }

  .rule-copy {
    white-space: normal;
  }

  .rule-delete {
    width: 100%;
  }
}

