:root {
  --bg: #f5f6f8;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-strong: #ffffff;
  --line: rgba(17, 24, 39, 0.1);
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --safe: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.1);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 0;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(245, 246, 248, 0.94)),
    #edf0f5;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
}

.phone-shell {
  position: relative;
  width: min(100%, 430px);
  height: 100dvh;
  min-height: 640px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(245, 246, 248, 0.95);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 10px;
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.app-header h1,
.view-heading h2,
.chat-title-row h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.18;
  font-weight: 760;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

.status-ribbon {
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}

.status-ribbon span,
.pill,
.status-chip,
.risk {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  color: #334155;
}

.offline-banner {
  flex: 0 0 auto;
  margin: 0 14px 10px;
  padding: 9px 11px;
  border-radius: var(--radius-md);
  color: #365314;
  background: rgba(236, 252, 203, 0.84);
  border: 1px solid rgba(132, 204, 22, 0.32);
  font-size: 12px;
  font-weight: 720;
  line-height: 1.4;
}

.offline-banner[hidden] {
  display: none;
}

.app-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.view {
  height: 100%;
  display: none;
  overflow: hidden;
}

.view-active {
  display: flex;
  flex-direction: column;
}

.view-heading,
.chat-title-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
}

.section-note {
  flex: 0 0 auto;
  margin: -4px 16px 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.workflow-strip {
  flex: 0 0 auto;
  margin: 0 14px 8px;
  padding: 10px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(18px);
}

.workflow-strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.workflow-strip-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.workflow-steps {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.workflow-step {
  flex: 0 0 118px;
  display: grid;
  gap: 5px;
  min-height: 58px;
  padding: 9px 10px;
  text-align: left;
  border-radius: 14px;
  color: var(--text);
  background: rgba(248, 250, 252, 0.92);
  border: 1px solid var(--line);
}

.workflow-step strong {
  font-size: 13px;
  line-height: 1.2;
}

.workflow-step span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
}

.message-list,
.stack-list,
.console-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 14px 118px;
}

.message-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 9px;
  align-items: end;
  margin: 10px 0;
}

.message-row.from-controller .message-bubble {
  background: rgba(37, 99, 235, 0.1);
  border-color: rgba(37, 99, 235, 0.18);
}

.message-bubble,
.department-section,
.employee-item,
.console-card,
.wide-panel,
.approval-card,
.loading-block,
.error-block {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.07);
  backdrop-filter: blur(18px);
  border-radius: var(--radius-lg);
}

.message-bubble {
  min-width: 0;
  padding: 10px 12px;
}

.message-meta,
.message-foot,
.employee-top,
.approval-head,
.task-row,
.audit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.message-meta strong,
.employee-top strong,
.task-row span,
.approval-card h3 {
  min-width: 0;
}

.message-meta span,
.message-foot,
.employee-body small,
.audit-row small,
.approval-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.message-bubble p,
.employee-body p,
.approval-card p {
  margin: 7px 0;
  color: #1f2937;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.composer {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.composer input {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0 12px;
  background: #f8fafc;
  color: var(--text);
}

.composer button,
.secondary-button {
  border-radius: 13px;
  padding: 0 13px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.department-section,
.approval-card,
.wide-panel {
  margin: 10px 0;
  padding: 12px;
}

.department-header h3,
.wide-panel h3,
.approval-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.department-header p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.employee-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  margin: 8px 0;
  box-shadow: none;
}

.employee-body {
  min-width: 0;
}

.employee-body p,
.employee-body small {
  display: block;
  overflow-wrap: anywhere;
}

.console-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: start;
  gap: 10px;
}

.console-card {
  min-height: 88px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.console-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.console-card strong {
  font-size: 16px;
  line-height: 1.25;
}

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

.task-row,
.audit-row {
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.task-highlight {
  margin: 4px -8px;
  padding: 9px 8px;
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.08);
  border-top-color: transparent;
}

.task-row:first-of-type,
.audit-row:first-of-type {
  border-top: 0;
}

.task-row strong {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 12px;
}

.approval-card {
  display: grid;
  gap: 9px;
}

.approval-card p,
.approval-card small {
  margin: 0;
}

.approval-detail {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
}

.approval-detail h4 {
  margin: 0;
  font-size: 14px;
}

.detail-row {
  display: grid;
  gap: 3px;
}

.detail-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.detail-row p {
  font-size: 13px;
  line-height: 1.45;
}

.risk-low {
  color: var(--safe);
  background: rgba(21, 128, 61, 0.08);
}

.risk-medium {
  color: var(--warn);
  background: rgba(180, 83, 9, 0.08);
}

.risk-high {
  color: var(--danger);
  background: rgba(185, 28, 28, 0.08);
}

.dryrun-preview {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: rgba(248, 250, 252, 0.88);
  border: 1px solid var(--line);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.dryrun-preview span,
.dryrun-preview em {
  color: var(--muted);
  font-style: normal;
}

.approval-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ghost-button {
  border-radius: 13px;
  padding: 0 13px;
  color: #334155;
  background: #ffffff;
  border: 1px solid var(--line);
}

.tab-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.88);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.tab-bar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  height: 54px;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.tab-bar .tab-active {
  color: var(--accent);
  background: rgba(37, 99, 235, 0.09);
}

.avatar-character {
  --avatar-main: #1f2937;
  --avatar-accent: #2563eb;
  --avatar-soft: #f8fafc;
  position: relative;
  width: 54px;
  height: 62px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.95) 0 24%, transparent 25%),
    linear-gradient(145deg, var(--avatar-soft), rgba(255, 255, 255, 0.68));
  border: 1px solid rgba(17, 24, 39, 0.12);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
}

.avatar-compact {
  width: 42px;
  height: 48px;
  border-radius: 15px;
}

.avatar-head {
  position: absolute;
  top: 7px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fed7aa;
  border: 1px solid rgba(17, 24, 39, 0.12);
  z-index: 2;
}

.avatar-hair {
  position: absolute;
  top: -2px;
  left: 3px;
  right: 3px;
  height: 10px;
  border-radius: 10px 10px 5px 5px;
  background: var(--avatar-main);
}

.avatar-face {
  position: absolute;
  inset: 9px 6px 5px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.avatar-eye {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #111827;
  justify-self: center;
}

.avatar-mouth {
  grid-column: 1 / -1;
  width: 10px;
  height: 3px;
  border-bottom: 2px solid rgba(17, 24, 39, 0.6);
  border-radius: 50%;
  justify-self: center;
}

.avatar-body {
  position: absolute;
  top: 31px;
  width: 36px;
  height: 26px;
  border-radius: 14px 14px 8px 8px;
  background: linear-gradient(160deg, var(--avatar-main), var(--avatar-accent));
  z-index: 1;
}

.avatar-badge {
  position: absolute;
  right: 5px;
  top: 5px;
  min-width: 12px;
  height: 12px;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 8px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 4px;
}

.avatar-tools {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 3px;
  display: flex;
  justify-content: center;
  gap: 2px;
  z-index: 3;
}

.avatar-tool {
  max-width: 18px;
  min-width: 13px;
  height: 13px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--avatar-main);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(17, 24, 39, 0.08);
  font-size: 7px;
  font-weight: 800;
}

.seed-security_reviewer .avatar-head {
  background: #fecaca;
}

.seed-qa_tester .avatar-head,
.seed-mobile_ui_designer .avatar-head {
  background: #f5d0fe;
}

.seed-ops_planner .avatar-hair {
  height: 12px;
  background: #eab308;
  border-radius: 4px 4px 10px 10px;
}

.seed-pwa_engineer .avatar-hair {
  height: 11px;
  background: #0f766e;
  border-radius: 10px 10px 4px 4px;
}

.loading-block,
.error-block {
  padding: 14px;
  color: var(--muted);
  font-size: 14px;
}

.error-block {
  color: var(--danger);
}

.toast {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  padding: 12px 14px;
  border-radius: 16px;
  color: #ffffff;
  background: rgba(17, 24, 39, 0.92);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.4;
  z-index: 10;
}

noscript {
  display: block;
  padding: 10px 14px;
  color: var(--danger);
  background: #fff1f2;
}

@media (max-width: 380px) {
  .app-header,
  .view-heading,
  .chat-title-row {
    padding-left: 12px;
    padding-right: 12px;
  }

  .message-list,
  .stack-list,
  .console-grid {
    padding-left: 10px;
    padding-right: 10px;
  }

  .composer {
    left: 9px;
    right: 9px;
    grid-template-columns: 1fr;
  }

  .composer button {
    width: 100%;
  }
}

@media (min-width: 431px) {
  body {
    align-items: center;
  }

  .phone-shell {
    height: min(100dvh, 932px);
    border-radius: 28px;
    border: 1px solid var(--line);
  }
}
