:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef4ff;
  --border: #d9e0ec;
  --text: #19202a;
  --muted: #657080;
  --primary: #2558d6;
  --primary-dark: #1d46ab;
  --success: #0a7a4a;
  --warning: #a86300;
  --danger: #b3261e;
  --shadow: 0 10px 30px rgba(25, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(140deg, rgba(37, 88, 214, 0.09), rgba(10, 122, 74, 0.07)),
    var(--bg);
}

.login-card {
  width: min(100%, 420px);
  display: grid;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 26px;
}

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

button,
a.secondary {
  min-height: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover,
a.secondary:hover {
  border-color: #b8c4d8;
  background: #f9fbff;
}

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

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

button.icon-button {
  min-height: 32px;
  padding: 6px 10px;
}

.sidebar {
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 22px;
}

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

.brand > div {
  min-width: 0;
  flex: 1;
}

.logout-button {
  flex: 0 0 auto;
}

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

/* Scope to the text block: .brand-mark is also a span in .brand, and these rules
   are more specific than .brand-mark, so unscoped they knocked the logo's
   display/color/font-size out and pushed "CS" outside its tile. */
.brand > div strong,
.brand > div span {
  display: block;
}

.brand > div span {
  color: var(--muted);
  font-size: 13px;
}

.new-run {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcff;
  margin-bottom: 22px;
}

.form-intro {
  display: grid;
  gap: 3px;
  color: var(--muted);
  padding-bottom: 4px;
}

.form-intro strong {
  color: var(--text);
  font-size: 16px;
}

.credential-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.credential-panel summary {
  cursor: pointer;
  font-weight: 750;
  color: #2e3642;
}

.credential-panel p {
  color: var(--muted);
  margin: 8px 0 12px;
  font-size: 13px;
}

.credential-panel label + label {
  margin-top: 10px;
}

.server-credentials-note {
  border: 1px solid #c7d7ff;
  background: #f2f6ff;
  color: #29406f;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 700;
}

.form-error {
  border: 1px solid #efb0ac;
  background: #fff1f0;
  color: var(--danger);
  border-radius: 8px;
  padding: 9px 11px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  color: #2e3642;
  font-weight: 650;
}

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

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

input:focus,
textarea:focus {
  outline: 2px solid rgba(37, 88, 214, 0.18);
  border-color: var(--primary);
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.run-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

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

h1 {
  font-size: 30px;
  line-height: 1.15;
  margin-bottom: 8px;
}

h2 {
  font-size: 18px;
  margin-bottom: 0;
}

h3 {
  font-size: 15px;
  margin-bottom: 4px;
}

.run-list {
  display: grid;
  gap: 8px;
}

.run-item {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 4px;
  padding: 12px;
}

.run-item.active {
  border-color: var(--primary);
  background: var(--surface-2);
}

.run-item strong,
.run-item span {
  display: block;
}

.run-item span {
  color: var(--muted);
  font-size: 13px;
}

.main {
  height: 100vh;
  overflow: auto;
  padding: 30px;
}

.empty-state {
  max-width: 680px;
  margin: 20vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 34px;
}

.run-detail {
  max-width: 820px;
  margin: 12vh auto 0;
}

.run-console {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.run-console-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
}

.run-console-head h1 {
  margin-bottom: 6px;
}

.current-step-card {
  margin-top: 24px;
  padding: 20px;
  border: 1px solid #cdd9f2;
  border-radius: 8px;
  background: #f8fbff;
}

.current-step-card h2 {
  font-size: 24px;
  line-height: 1.2;
  margin: 6px 0 8px;
}

.current-step-card p {
  color: var(--muted);
  margin-bottom: 0;
  max-width: 640px;
}

.step-count {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  background: #eaf0ff;
  color: var(--primary);
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 750;
}

.compact-progress {
  box-shadow: none;
  margin: 18px 0 0;
}

.operator-intervention {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  margin-top: 18px;
  border: 1px solid #efb0ac;
  background: #fff7f6;
  border-radius: 8px;
  padding: 14px;
}

.operator-intervention strong {
  display: block;
  color: var(--danger);
}

.operator-intervention p {
  margin: 4px 0 0;
  color: #73322d;
}

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

.advanced-panel {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 12px 14px 14px;
}

.advanced-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 750;
}

.advanced-panel[open] summary {
  margin-bottom: 14px;
}

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

.hidden {
  display: none !important;
}

.detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: start;
  margin-bottom: 18px;
}

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid #f0c56a;
  background: #fff8e8;
  color: #4b3800;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 18px;
}

.notice strong {
  white-space: nowrap;
}

.eyebrow {
  color: var(--primary);
  font-weight: 750;
  letter-spacing: 0;
  margin-bottom: 6px;
}

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

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  max-width: 600px;
}

.automation-status {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.status-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  margin-bottom: 6px;
}

.status-card strong {
  display: block;
  font-size: 18px;
}

.status-card p {
  margin: 6px 0 0;
  color: var(--muted);
}

.progress-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 18px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: #e4e9f2;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--primary);
  transition: width 180ms ease;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}

.tab {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 12px 14px;
  min-height: 42px;
  border-bottom: 3px solid transparent;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.workflow-list,
.form-grid,
.snippet-grid,
.yamix-grid {
  display: grid;
  gap: 14px;
}

.workflow-card,
.form-grid,
.snippet-grid article,
.yamix-field,
#summary-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workflow-card {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.status-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 38px;
  padding: 8px;
  background: #fff;
}

.step-copy {
  color: var(--muted);
  margin-bottom: 0;
}

.step-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

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

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

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

.credential-summary {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcff;
}

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

.credential-grid div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.credential-grid span,
.credential-grid strong,
.credential-grid em {
  display: block;
}

.credential-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.credential-grid strong {
  margin-top: 4px;
}

.credential-grid em {
  color: var(--muted);
  font-style: normal;
  margin-top: 4px;
  font-size: 12px;
}

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

.snippet-grid article {
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  color: #10151d;
  background: #fbfcff;
  min-height: 160px;
  white-space: pre-wrap;
  word-break: break-word;
}

.yamix-field {
  padding: 14px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.yamix-field span:first-child {
  color: var(--muted);
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 750;
  background: #e9eef8;
  color: #3c4858;
}

.pill.done {
  background: #e3f5ed;
  color: var(--success);
}

.pill.blocked {
  background: #fdeceb;
  color: var(--danger);
}

.pill.in-progress {
  background: #fff2d9;
  color: var(--warning);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #10151d;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

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

  .sidebar,
  .main {
    height: auto;
  }

  .detail-header,
  .run-console-head,
  .operator-intervention,
  .workflow-card,
  .snippet-grid,
  .form-grid,
  .automation-status,
  .credential-grid {
    grid-template-columns: 1fr;
  }

  .header-actions,
  .operator-actions,
  .step-actions {
    justify-content: flex-start;
  }
}

/* SE Ranking session (paste cookies to refresh the browser session) */
.se-session {
  margin: 12px 0 4px;
  padding: 12px;
  border: 1px solid var(--border, #2a2f3a);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}
.se-session summary {
  cursor: pointer;
  font-weight: 600;
}
.se-session textarea {
  width: 100%;
  margin: 8px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  resize: vertical;
}
.se-session .muted {
  font-size: 12px;
}

/* Motion cue for a run in flight — without it a multi-minute run reads as frozen. */
.spinner {
  display: inline-block;
  width: 0.72em;
  height: 0.72em;
  margin-right: 0.5em;
  border: 2px solid rgba(37, 88, 214, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: baseline;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.step-elapsed {
  margin-top: 6px;
  font-size: 0.85rem;
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}
