:root {
  color-scheme: light;
  --bg: #f4f5f1;
  --ink: #1e2724;
  --muted: #65706c;
  --line: #d9ded7;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --warn: #a16207;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(31, 41, 35, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.09), rgba(244, 245, 241, 0) 34%),
    repeating-linear-gradient(90deg, rgba(30, 39, 36, 0.035) 0 1px, transparent 1px 72px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.docs-link,
button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.15s ease;
}

button:hover,
.docs-link:hover {
  background: var(--accent-dark);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: #e4ebe7;
  color: var(--ink);
}

button.secondary:hover {
  background: #d6e0db;
}

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

.grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(520px, 1.3fr);
  gap: 18px;
  align-items: start;
}

.single-page {
  width: 100%;
  margin: 0;
}

.single-page.wide,
.admin-stack {
  width: 100%;
}

.admin-stack {
  display: grid;
  gap: 18px;
}

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

.secondary-link {
  background: #e4ebe7;
  color: var(--ink);
}

.secondary-link:hover {
  background: #d6e0db;
}

.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.user-panel textarea {
  min-height: 360px;
}

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

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 9px;
  white-space: nowrap;
}

.status-pill.ok {
  color: var(--accent-dark);
  border-color: rgba(15, 118, 110, 0.3);
  background: rgba(15, 118, 110, 0.08);
}

.status-pill.warn {
  color: var(--warn);
  border-color: rgba(161, 98, 7, 0.35);
  background: rgba(161, 98, 7, 0.08);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  outline: none;
  padding: 10px 11px;
}

textarea {
  min-height: 210px;
  resize: vertical;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(15, 118, 110, 0.55);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.admin-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 90px 110px;
  gap: 10px;
}

.config-controls {
  display: grid;
  grid-template-columns: 150px minmax(320px, 1fr) minmax(180px, 0.7fr);
  gap: 10px;
}

.short-textarea {
  min-height: 82px;
}

.button-row,
.table-tools,
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.button-row {
  margin: 8px 0 14px;
}

.progress-wrap {
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 8px;
  background: #f7fbf9;
  margin: 14px 0;
  padding: 14px;
}

.progress-head,
.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
}

.progress-head {
  color: var(--ink);
  font-size: 14px;
  margin-bottom: 7px;
}

.progress-hint {
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 10px;
  padding: 8px 10px;
}

.progress-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.progress-track {
  position: relative;
  width: 100%;
  height: 22px;
  overflow: hidden;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 999px;
  background: #e4ebe7;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #14b8a6);
  transition: width 0.25s ease;
}

.progress-wrap.is-loading .progress-bar {
  background:
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.24) 0 8px,
      rgba(255, 255, 255, 0) 8px 16px
    ),
    linear-gradient(90deg, var(--accent), #14b8a6);
  background-size: 24px 24px, 100% 100%;
  animation: progress-stripes 0.8s linear infinite;
}

.progress-wrap.is-loading .progress-track::after {
  animation: progress-sweep 1.2s ease-in-out infinite;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  content: "";
  inset: 0;
  position: absolute;
  transform: translateX(-100%);
}

@keyframes progress-stripes {
  from {
    background-position: 0 0, 0 0;
  }
  to {
    background-position: 24px 0, 0 0;
  }
}

@keyframes progress-sweep {
  0% {
    transform: translateX(-100%);
  }
  60%,
  100% {
    transform: translateX(100%);
  }
}

.task-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.task-summary span {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: 6px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-events {
  display: grid;
  gap: 6px;
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.task-events li {
  border-left: 3px solid rgba(15, 118, 110, 0.35);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  padding-left: 8px;
}

.task-events span {
  color: var(--muted);
  display: inline-block;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  margin-right: 8px;
}

.table-tools {
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 6px;
}

.table-tools label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-tools select {
  width: auto;
  min-width: 92px;
}

.table-tools .search-field {
  flex: 1 1 260px;
}

.table-tools .search-field input {
  min-width: 220px;
}

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

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
}

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

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

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

td {
  font-size: 13px;
}

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

.code-cell {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.copy-btn {
  min-height: 30px;
  padding: 0 10px;
}

.output {
  min-height: 58px;
  max-height: 210px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111714;
  color: #dce7df;
  padding: 12px;
  white-space: pre-wrap;
}

.output[hidden] {
  display: none;
}

.app-modal[hidden] {
  display: none;
}

.app-modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 23, 20, 0.42);
  backdrop-filter: blur(4px);
}

.app-modal-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  width: min(560px, 100%);
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 70px rgba(17, 23, 20, 0.28);
  padding: 18px;
}

.app-modal-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent-dark);
  font-size: 22px;
  font-weight: 800;
  font-family: Georgia, serif;
}

.app-modal-content {
  min-width: 0;
}

.app-modal-content h2 {
  margin-bottom: 6px;
}

.app-modal-content p:last-child {
  color: var(--muted);
  line-height: 1.5;
}

.app-modal-card.warn {
  border-color: rgba(161, 98, 7, 0.35);
}

.app-modal-card.warn .app-modal-icon {
  background: rgba(161, 98, 7, 0.1);
  color: var(--warn);
}

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

  .admin-controls {
    grid-template-columns: 1fr 1fr;
  }

  .admin-controls .field:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100vw - 20px, 1280px);
    padding: 16px 0;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  h1 {
    font-size: 26px;
  }

  .admin-controls {
    grid-template-columns: 1fr;
  }

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

  .task-summary {
    grid-template-columns: 1fr;
  }

  .app-modal-card {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .app-modal-card button {
    grid-column: 1 / -1;
    width: 100%;
  }
}
