:root {
  color-scheme: light;
  --bg: #f6f4ee;
  --panel: #fffdfa;
  --panel-strong: #f0eadf;
  --ink: #17211f;
  --muted: #66716d;
  --line: #ddd5c8;
  --accent: #0f7b6c;
  --accent-strong: #075f54;
  --amber: #d98b12;
  --red: #c74634;
  --blue: #2f5f9f;
  --shadow: 0 18px 50px rgba(27, 31, 29, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 123, 108, 0.28);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 250, 0.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand,
.top-actions,
.builder-head,
.section-title,
.prompt-actions,
.preview-toolbar {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 220px;
}

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

.mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 800;
  letter-spacing: 0;
}

.top-actions {
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(420px, 1fr) minmax(260px, 330px);
  gap: 14px;
  padding: 14px;
  min-height: calc(100vh - 72px);
}

.panel,
.builder {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
  max-height: calc(100vh - 100px);
}

.builder {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  padding: 14px;
  min-width: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 14px;
}

.section-title {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.project-list,
.template-list,
.queue-list,
.toggle-list,
.action-grid {
  display: grid;
  gap: 8px;
}

.project-card,
.template-card,
.queue-item {
  width: 100%;
  text-align: left;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.project-card {
  display: grid;
  gap: 6px;
}

.project-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.project-row,
.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.project-row strong,
.template-card strong {
  font-size: 13px;
}

.meta-row,
.template-card p,
.queue-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.template-card {
  display: grid;
  gap: 4px;
}

.template-card:hover,
.project-card:hover {
  border-color: #9db8b1;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(15, 123, 108, 0.12);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.warn {
  background: rgba(217, 139, 18, 0.16);
  color: #8b5206;
}

.status-pill.danger {
  background: rgba(199, 70, 52, 0.14);
  color: #963424;
}

.status-pill.neutral {
  background: var(--panel-strong);
  color: var(--muted);
}

.meter {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-strong);
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease, background 180ms ease;
}

.compact-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0 0;
}

.compact-stats div {
  padding: 8px;
  background: var(--panel-strong);
  border-radius: 8px;
}

dt {
  color: var(--muted);
  font-size: 11px;
}

dd {
  margin: 3px 0 0;
  font-weight: 800;
  font-size: 13px;
}

.builder-head {
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.title-input {
  width: min(520px, 100%);
  min-width: 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-size: 26px;
  font-weight: 800;
  padding: 2px 0;
}

.title-input:focus {
  border-bottom-color: var(--accent);
}

.segmented {
  padding: 3px;
  border-radius: 8px;
  background: var(--panel-strong);
  flex-shrink: 0;
}

.mode-button,
.tool-button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.mode-button.active,
.tool-button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(27, 31, 29, 0.1);
}

.prompt-row {
  display: grid;
  grid-template-columns: 1fr 170px;
  gap: 10px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 102px;
  padding: 12px;
  line-height: 1.45;
}

input,
select {
  min-height: 38px;
  padding: 0 10px;
}

.select-label,
.class-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.prompt-actions {
  align-items: stretch;
  flex-direction: column;
  gap: 8px;
}

.primary-button,
.ghost-button,
.small-button,
.icon-button {
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: white;
}

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

.ghost-button,
.small-button,
.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 20px;
}

.guardrail {
  min-height: 36px;
  display: none;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(217, 139, 18, 0.12);
  color: #744605;
  font-size: 13px;
  font-weight: 700;
}

.guardrail.visible {
  display: flex;
}

.preview-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.preview-toolbar {
  justify-content: space-between;
  gap: 12px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-strong);
  font-weight: 800;
  font-size: 13px;
}

iframe {
  width: 100%;
  height: 100%;
  min-height: 430px;
  border: 0;
  background: white;
  justify-self: center;
  transition: width 150ms ease;
}

iframe.mobile {
  width: min(390px, 100%);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.class-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle-list label {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--panel-strong);
  font-size: 13px;
}

.toggle-list input {
  width: 18px;
  min-height: 18px;
}

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

.action-grid .ghost-button {
  min-height: 36px;
  font-size: 13px;
}

.budget-card {
  padding-top: 4px;
}

.queue-item {
  border-left: 4px solid var(--amber);
}

.empty {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

  .admin-panel {
    grid-column: 1 / -1;
    max-height: none;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    min-height: 72px;
    align-items: flex-start;
    padding: 12px;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

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

  .panel,
  .admin-panel {
    max-height: none;
  }

  .admin-panel {
    display: flex;
  }

  .builder-head,
  .prompt-row {
    grid-template-columns: 1fr;
  }

  .builder-head {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .prompt-row {
    display: grid;
  }

  .prompt-actions {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .title-input {
    font-size: 22px;
  }

  iframe {
    min-height: 520px;
  }
}
