:root {
  --polo-bg: #f6f7f4;
  --polo-surface: #ffffff;
  --polo-surface-2: #eef2ee;
  --polo-surface-alt: #eef2ee;
  --polo-text: #17201d;
  --polo-muted: #65706a;
  --polo-line: #d9dfda;
  --polo-border: #d9dfda;
  --polo-primary: #126b5a;
  --polo-primary-strong: #0a4d40;
  --polo-accent: #a85f2b;
  --polo-success: #1f7a56;
  --polo-danger: #9b2f34;
  --polo-warning: #946b12;
  --polo-radius-sm: 6px;
  --polo-radius-md: 8px;
  --polo-radius-lg: 8px;
  --polo-space-xs: 6px;
  --polo-space-sm: 10px;
  --polo-space-md: 14px;
  --polo-space-lg: 18px;
  --polo-density: 0.9;
  color-scheme: light;
}

:root[data-polo-density="compact"] {
  --polo-density: 0.82;
  --polo-space-sm: 8px;
  --polo-space-md: 12px;
  --polo-space-lg: 16px;
}

:root[data-polo-density="dense"] {
  --polo-density: 0.74;
  --polo-space-sm: 7px;
  --polo-space-md: 10px;
  --polo-space-lg: 14px;
}

:root[data-polo-theme-mode="dark"] {
  --polo-bg: #101615;
  --polo-surface: #17211f;
  --polo-surface-2: #20302c;
  --polo-surface-alt: #20302c;
  --polo-text: #eef5f0;
  --polo-muted: #a8b6af;
  --polo-line: #30413c;
  --polo-border: #30413c;
  --polo-primary: #51a995;
  --polo-primary-strong: #73c5b2;
  --polo-accent: #d2945d;
  color-scheme: dark;
}

:root[data-polo-theme-mode="high_contrast"] {
  --polo-bg: #000;
  --polo-surface: #fff;
  --polo-surface-2: #f1f1f1;
  --polo-surface-alt: #f1f1f1;
  --polo-text: #000;
  --polo-muted: #202020;
  --polo-line: #000;
  --polo-border: #000;
  --polo-primary: #0047ff;
  --polo-primary-strong: #002a99;
  --polo-accent: #8b2b00;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--polo-border);
  border-radius: var(--polo-radius-sm);
  min-height: 36px;
  padding: 0 var(--polo-space-md);
  color: var(--polo-text);
  background: var(--polo-surface);
  cursor: pointer;
}

button:hover {
  border-color: var(--polo-primary);
}

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

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

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

.icon-button {
  width: 36px;
  padding: 0;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--polo-border);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--polo-surface);
  color: var(--polo-text);
}

input::placeholder {
  color: var(--polo-muted);
}

input[readonly] {
  color: var(--polo-muted);
  background: var(--polo-surface-alt);
}

label {
  display: grid;
  gap: 6px;
  color: var(--polo-muted);
  font-size: 12px;
  font-weight: 600;
}

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

h1 {
  font-size: 18px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

h3 {
  font-size: 14px;
  line-height: 1.2;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--polo-space-lg);
  min-height: 68px;
  padding: 12px var(--polo-space-lg);
  background: color-mix(in srgb, var(--polo-surface) 94%, transparent);
  border-bottom: 1px solid var(--polo-border);
  backdrop-filter: blur(12px);
}

.brand,
.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.locale-switch {
  width: 96px;
  gap: 4px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--polo-primary), #2c465f);
  font-weight: 800;
}

#runtimeLine {
  color: var(--polo-muted);
  font-size: 12px;
  margin-top: 3px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  gap: var(--polo-space-lg);
  padding: var(--polo-space-lg);
}

body.shell-embed .topbar,
body.shell-embed .sidebar {
  display: none;
}

body.shell-embed .workspace {
  grid-template-columns: 1fr;
  padding: var(--polo-space-sm);
}

body.shell-embed .content {
  gap: var(--polo-space-sm);
}

.sidebar,
.content {
  display: grid;
  align-content: start;
  gap: var(--polo-space-md);
}

.panel,
.data-section {
  background: var(--polo-surface);
  border: 1px solid var(--polo-border);
  border-radius: var(--polo-radius-md);
}

.panel {
  display: grid;
  gap: 12px;
  padding: var(--polo-space-md);
}

.form-panel {
  align-content: start;
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.status-grid div {
  border: 1px solid var(--polo-border);
  border-radius: 6px;
  padding: 8px;
  background: var(--polo-surface-alt);
}

.status-grid dt {
  color: var(--polo-muted);
  font-size: 11px;
}

.status-grid dd {
  margin: 3px 0 0;
  font-size: 13px;
  font-weight: 700;
  word-break: break-word;
}

#activityCanvas {
  width: 100%;
  height: 108px;
  border: 1px solid var(--polo-border);
  border-radius: 6px;
  background: var(--polo-surface);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--polo-space-xs);
  align-items: center;
  padding: var(--polo-space-xs);
  background: var(--polo-surface);
  border: 1px solid var(--polo-border);
  border-radius: var(--polo-radius-md);
}

.tab {
  min-height: 34px;
  text-align: center;
  justify-content: center;
  background: transparent;
}

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

.content {
  min-width: 0;
}

.readiness-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.readiness-item {
  display: grid;
  gap: 3px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--polo-border);
  border-left: 4px solid var(--polo-muted);
  border-radius: var(--polo-radius-md);
  background: var(--polo-surface);
}

.readiness-item span {
  color: var(--polo-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.readiness-item[data-ready="ok"] {
  border-left-color: var(--polo-primary);
}

.readiness-item[data-ready="warn"] {
  border-left-color: var(--polo-warning);
}

.readiness-item[data-ready="error"] {
  border-left-color: var(--polo-danger);
}

.view {
  display: none;
  gap: 14px;
}

.view.is-active {
  display: grid;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  min-height: 48px;
}

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

.section-header p {
  margin-top: 4px;
  color: var(--polo-muted);
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(280px, 0.8fr);
  gap: 14px;
  align-items: start;
}

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

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

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--polo-border);
  border-radius: 6px;
  background: var(--polo-surface-alt);
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--polo-text);
  font-size: 12px;
  font-weight: 600;
}

.checkbox-grid input {
  width: auto;
  min-height: 0;
}

.data-section {
  overflow: hidden;
}

.data-section h3 {
  padding: 12px 12px 0;
}

.table-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 220px);
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--polo-border);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--polo-border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--polo-muted);
  font-size: 11px;
  text-transform: uppercase;
  background: var(--polo-surface-alt);
}

td {
  font-size: 13px;
}

tr[data-selected="true"] td {
  background: #eef8f5;
}

.sub-row td {
  background: var(--polo-surface-alt);
  color: var(--polo-muted);
  font-size: 12px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--polo-border);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.active,
.pill.queued,
.pill.applied,
.pill.approved {
  color: var(--polo-primary-strong);
  background: #e8f5f0;
}

.pill.stale,
.pill.running,
.pill.pending {
  color: var(--polo-warning);
  background: #fff5dc;
}

.pill.tombstoned,
.pill.failed,
.pill.rejected {
  color: var(--polo-danger);
  background: #fbe8e9;
}

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

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.empty-state {
  min-height: 88px;
  display: grid;
  place-items: center;
  color: var(--polo-muted);
  border: 1px dashed var(--polo-border);
  border-radius: 6px;
  padding: 16px;
  text-align: center;
}

.detail-grid {
  display: grid;
  gap: 8px;
}

.detail-grid > div:not(.detail-actions) {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
}

.detail-grid dt {
  color: var(--polo-muted);
}

.detail-grid dd {
  margin: 0;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 4px;
}

.danger-button {
  color: var(--polo-danger);
  border-color: #e9c6c8;
}

.danger-button:hover {
  color: #fff;
  background: var(--polo-danger);
  border-color: var(--polo-danger);
}

.list-header {
  display: grid;
  grid-template-columns: minmax(80px, auto) minmax(160px, 1fr);
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--polo-border);
}

.list-header h3 {
  padding: 0;
}

.event-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding: 12px;
}

.event-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--polo-border);
  border-radius: 6px;
  background: #fff;
}

.event-row strong {
  font-size: 13px;
}

.toast {
  display: none;
  border-radius: 6px;
  padding: 10px 12px;
  background: #17201d;
  color: #fff;
}

.toast.is-visible {
  display: block;
}

@media (max-width: 1000px) {
  .workspace,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 2;
  }

  .content {
    order: 1;
  }

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

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

@media (max-width: 640px) {
  .topbar,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .locale-switch {
    flex: 1 1 96px;
  }

  .top-actions .primary-button {
    flex: 1;
  }

  .form-grid,
  .form-grid.four,
  .checkbox-grid,
  .readiness-strip,
  .table-toolbar,
  .list-header {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 12px;
  }
}
