:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-muted: #eef1ee;
  --ink: #202522;
  --muted: #647067;
  --line: #dbe0dc;
  --body: #2f6f73;
  --task: #806026;
  --chat: #394f8a;
  --safety: #9b3030;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

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

body,
.page-shell,
.module-card,
.chat-rail,
.input-shell {
  overflow-wrap: anywhere;
}

a {
  color: inherit;
}

.app-frame {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.app-header p,
.page-shell__header span,
.module-card span,
.chat-rail span {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.app-header h1,
.page-shell h1,
.module-card h2,
.chat-rail h2 {
  margin: 0;
  line-height: 1.1;
}

.route-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.route-tab,
.module-card a,
.safety-actions a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 12px;
  color: var(--ink);
  text-decoration: none;
}

.route-tab[data-active="true"] {
  border-color: var(--chat);
  color: var(--chat);
  font-weight: 800;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 16px;
  align-items: start;
}

.app-layout > * {
  min-width: 0;
}

.page-shell,
.chat-rail {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
}

.page-shell--safety {
  border-left: 6px solid var(--safety);
}

.page-shell__header {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  min-width: 0;
}

.page-shell__header p,
.module-card p,
.runtime-notice small {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  white-space: normal;
}

.page-shell__header > *,
.module-card > * {
  min-width: 0;
}

.runtime-notice {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  padding: 10px;
}

.contract-strip {
  display: grid;
  grid-template-columns: minmax(190px, 0.32fr) minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.contract-strip div {
  display: grid;
  gap: 5px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  padding: 10px;
}

.contract-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.contract-strip strong,
.contract-strip code {
  min-width: 0;
  overflow-wrap: break-word;
}

.contract-strip strong[data-status="missing_context"] {
  color: var(--task);
}

.contract-strip strong[data-status="safety_interruption"],
.contract-strip strong[data-status="error"] {
  color: var(--safety);
}

.safety-reminder {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  border: 1px solid #d9b8aa;
  border-left: 5px solid var(--safety);
  border-radius: var(--radius);
  background: #fff8f5;
  padding: 10px;
}

.safety-reminder span {
  color: var(--safety);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.safety-reminder p {
  margin: 0;
  color: var(--muted);
}

.safety-reminder button,
.module-card button {
  width: fit-content;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

.runtime-notice span,
.runtime-notice strong {
  display: inline-flex;
  width: fit-content;
}

.runtime-notice span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.runtime-notice strong {
  border-radius: var(--radius);
  background: var(--surface);
  padding: 4px 8px;
}

.runtime-notice[data-status="missing_context"] strong {
  color: var(--task);
}

.runtime-notice[data-status="safety_interruption"] strong,
.runtime-notice[data-status="error"] strong {
  color: var(--safety);
}

.module-card--missing,
.module-card--error,
.module-card--warning,
.module-card--safety-guidance {
  background: var(--surface);
}

.home-grid,
.system-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.module-card {
  display: grid;
  min-height: 180px;
  gap: 10px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  padding: 14px;
}

.module-card--body {
  border-top: 5px solid var(--body);
}

.module-card--task,
.module-card--primary {
  border-top: 5px solid var(--task);
}

.module-card--missing {
  margin-top: 12px;
  border-top: 5px solid var(--task);
}

.module-card--error {
  margin-bottom: 12px;
  border-top: 5px solid var(--safety);
}

.module-card--warning {
  margin-bottom: 12px;
  border-top: 5px solid var(--task);
}

.module-card--safety-guidance {
  margin-bottom: 12px;
  border-top: 5px solid var(--safety);
  background: #fff8f5;
}

.compact-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
}

.module-card--error + .system-layout .module-card {
  min-height: auto;
  border-style: dashed;
  background: #f6f7f4;
}

.module-card--safety-ack {
  margin-bottom: 12px;
  border-top: 5px solid var(--safety);
}

.module-card code {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.92em;
}

.chat-rail {
  position: sticky;
  top: 18px;
  border-top: 5px solid var(--chat);
}

.chat-rail dl {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
}

.chat-rail div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px;
  border-radius: var(--radius);
  background: var(--surface-muted);
  padding: 8px;
}

.chat-rail dt {
  color: var(--muted);
  font-weight: 700;
}

.chat-rail dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.safety-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.input-shell {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  padding: 14px;
}

.input-shell__intro {
  display: grid;
  gap: 6px;
}

.input-shell__intro span,
.input-form label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.input-shell__intro h2,
.input-shell__intro p {
  margin: 0;
}

.input-shell__intro p {
  color: var(--muted);
  line-height: 1.45;
}

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

.input-form label {
  display: grid;
  gap: 6px;
}

.input-form label:nth-child(3),
.input-form button {
  grid-column: 1 / -1;
}

.input-form input,
.input-form select,
.input-form textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  padding: 9px 10px;
}

.input-form textarea {
  resize: vertical;
}

.input-form button {
  min-height: 44px;
  border: 1px solid var(--chat);
  border-radius: var(--radius);
  background: var(--chat);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

@media (max-width: 840px) {
  .app-frame {
    width: 100%;
    max-width: 100%;
    padding: 12px 12px 96px;
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
  }

  .route-nav {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .route-tab {
    justify-content: center;
    min-width: 0;
    padding: 0 8px;
    text-align: center;
  }

  .app-layout,
  .home-grid,
  .system-layout,
  .input-form,
  .contract-strip {
    grid-template-columns: 1fr;
  }

  .app-layout,
  .home-grid,
  .system-layout,
  .page-shell__header {
    gap: 10px;
  }

  .page-shell,
  .chat-rail {
    width: 100%;
    max-width: calc(100vw - 24px);
    padding: 14px;
  }

  .module-card,
  .input-shell,
  .contract-strip,
  .runtime-notice {
    max-width: 100%;
  }

  .page-shell__header {
    margin-bottom: 12px;
  }

  .page-shell h1 {
    font-size: 28px;
  }

  .input-shell {
    gap: 12px;
    padding: 12px;
  }

  .module-card {
    min-height: auto;
    gap: 8px;
    padding: 12px;
  }

  .module-card h2 {
    font-size: 20px;
  }

  .module-card--primary {
    background: var(--surface);
  }

  .module-card--missing,
  .module-card--error {
    margin-top: 0;
    margin-bottom: 10px;
    border-left: 5px solid var(--task);
    border-top-width: 1px;
  }

  .module-card--error {
    border-left-color: var(--safety);
  }

  .module-card--error + .system-layout .module-card {
    min-height: auto;
    border-style: dashed;
    background: #f6f7f4;
  }

  .system-layout .module-card:nth-child(4) {
    min-height: auto;
    border-style: dashed;
    background: #f6f7f4;
    color: var(--muted);
  }

  .runtime-notice {
    gap: 4px;
    margin-bottom: 10px;
    border-style: dashed;
    background: transparent;
    padding: 8px;
  }

  .runtime-notice small,
  .module-card p code {
    color: var(--muted);
    font-size: 12px;
  }

  .page-shell__header p,
  .module-card p,
  .runtime-notice small {
    max-width: 32ch;
  }

  .page-shell--safety .page-shell__header {
    border-radius: var(--radius);
    background: #fff8f5;
    padding: 12px;
  }

  .safety-actions {
    gap: 8px;
  }

  .safety-actions a {
    width: 100%;
    justify-content: center;
  }

  .chat-rail {
    position: static;
    max-height: none;
    overflow: auto;
    box-shadow: none;
  }
}
