:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-strong: #f9fbfd;
  --ink: #17202a;
  --muted: #687384;
  --line: #d8dee7;
  --blue: #274060;
  --blue-2: #386fa4;
  --green: #2f7d55;
  --red: #b33a3a;
  --amber: #a66a00;
  --teal: #24726b;
  --shadow: 0 10px 30px rgba(24, 35, 49, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  overflow-x: hidden;
}

body {
  width: 100%;
  min-width: 0;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  min-width: 0;
}

button {
  max-width: 100%;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  min-height: 36px;
  padding: 0 12px;
  white-space: normal;
}

button.secondary {
  background: white;
  color: var(--blue);
}

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

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  min-height: 36px;
  padding: 7px 9px;
}

textarea {
  min-height: 130px;
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.check-label {
  align-items: center;
  display: flex;
  gap: 8px;
  min-height: 36px;
  min-width: 0;
}

.check-label input {
  width: auto;
  min-height: auto;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  padding: 12px clamp(14px, 3vw, 28px);
  backdrop-filter: blur(10px);
  width: 100%;
  max-width: 100vw;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  color: var(--blue);
  font-size: 1.24rem;
  line-height: 1.15;
}

.brand p {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.top-button {
  min-height: 34px;
  padding: 0 10px;
  background: white;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 800;
}

.top-button.active,
.top-button:hover {
  border-color: var(--blue);
  background: #eaf1f8;
}

main {
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  padding: 18px clamp(14px, 3vw, 28px) 28px;
}

.auth-panel {
  display: grid;
  min-height: 60vh;
  place-items: center;
}

.auth-form {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
}

.dashboard {
  display: grid;
  gap: 14px;
  min-width: 0;
}

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

.metric {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue-2);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  min-height: 50px;
  padding: 8px 10px;
  text-align: left;
}

.metric strong {
  display: block;
  color: var(--ink);
  font-size: 1.18rem;
  line-height: 1.1;
}

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric.active,
.metric:hover {
  border-color: var(--blue);
  border-left-color: var(--blue);
  background: #eaf1f8;
}

.metric.tone-danger {
  border-left-color: var(--red);
}

.metric.tone-warn {
  border-left-color: var(--amber);
}

.metric.tone-good {
  border-left-color: var(--green);
}

.filter-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.filter-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 0 12px;
  color: var(--blue);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
  list-style: none;
}

.filter-panel summary::-webkit-details-marker {
  display: none;
}

.filter-panel summary::after {
  content: "+";
  font-size: 1.1rem;
  line-height: 1;
}

.filter-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.filter-panel[open] summary::after {
  content: "-";
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(140px, 220px) minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  min-width: 0;
  background: var(--panel);
  padding: 12px;
}

.job-list {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.job-row {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(220px, 1fr) minmax(150px, 220px) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
  min-width: 0;
}

.job-row.hidden-history {
  border-style: dashed;
}

.job-title,
.job-main,
.job-meta {
  min-width: 0;
}

.job-title strong,
.job-main strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.96rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-title span,
.job-main span,
.job-meta span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.job-actions button {
  flex: 0 1 auto;
  min-height: 32px;
  padding: 0 9px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  background: #e8edf3;
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1;
  padding: 6px 8px;
  text-transform: uppercase;
}

.status-pill.failure,
.status-pill.failed,
.status-pill.aborted {
  background: #f8e8e8;
  color: var(--red);
}

.status-pill.review,
.status-pill.manual,
.status-pill.rejected,
.status-pill.retrying,
.status-pill.aborting {
  background: #fff1d7;
  color: var(--amber);
}

.status-pill.success {
  background: #e2f3ea;
  color: var(--green);
}

.status-pill.running {
  background: #e2f1f4;
  color: var(--teal);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
  min-width: 0;
}

.settings-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  min-width: 0;
}

.settings-panel h2 {
  margin: 0;
  color: var(--blue);
  font-size: 1rem;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.push-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

dialog {
  width: min(740px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

dialog::backdrop {
  background: rgba(23, 32, 42, 0.35);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 16px;
  min-width: 0;
}

.dialog-form header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-form h2 {
  margin: 0;
  color: var(--blue);
  font-size: 1.05rem;
}

.icon-only {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

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

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

.artifact-box {
  min-width: 0;
  max-height: 55vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101820;
  color: #e6edf3;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  padding: 12px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  background: var(--blue);
  color: white;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

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

  .job-actions {
    justify-content: flex-start;
  }

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

@media (max-width: 680px) {
  main {
    padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .brand {
    width: 100%;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
  }

  .top-actions {
    margin-left: 48px;
  }

  .toolbar {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .job-row {
    gap: 10px;
    padding: 10px;
  }

  .job-title strong,
  .job-main strong,
  .job-title span,
  .job-main span,
  .job-meta span {
    white-space: normal;
    overflow-wrap: anywhere;
  }

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

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

  .job-actions button,
  .push-actions button {
    width: 100%;
  }

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

  .settings-panel {
    padding: 12px;
  }

  .dialog-form {
    padding: 12px;
  }
}

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