:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --text: #111114;
  --muted: #767680;
  --soft: #f4f4f6;
  --soft-2: #e8e8ed;
  --line: #e7e7ec;
  --blue: #0a84ff;
  --green: #2fbf71;
  --red: #ff4d4f;
  --orange: #f59f00;
  --ink: #18181b;
  --shadow: 0 12px 30px rgba(20, 23, 31, 0.07);
  --hairline-shadow: inset 0 0 0 1px rgba(17, 17, 20, 0.06);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

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

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  padding-bottom: calc(82px + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 92px 1fr 52px;
  align-items: center;
  gap: 8px;
  padding: calc(16px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(251, 251, 253, 0.88);
  backdrop-filter: blur(22px) saturate(1.25);
  border-bottom: 1px solid rgba(231, 231, 236, 0.72);
}

.title-block {
  text-align: center;
  min-width: 0;
}

.app-title {
  font-size: 19px;
  line-height: 24px;
  font-weight: 760;
  white-space: nowrap;
}

.app-subtitle {
  margin-top: 1px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: lowercase;
}

.verified {
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: linear-gradient(180deg, #2f9bff, var(--blue));
  color: #fff;
  font-size: 13px;
  vertical-align: 2px;
}

.link-button {
  background: transparent;
  color: var(--blue);
  font-size: 17px;
  text-align: left;
  padding: 8px 0;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--hairline-shadow);
  font-size: 22px;
  line-height: 1;
}

main {
  width: min(100%, 760px);
  margin: 0 auto;
}

.view {
  display: none;
  padding: 8px 16px 22px;
}

.view.active {
  display: block;
}

.hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 18px;
}

.avatar-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 50px;
  padding: 4px 12px 4px 5px;
  border-radius: 25px;
  background: var(--soft);
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-weight: 800;
}

.gear-avatar {
  background: var(--ink);
}

.gear-avatar .ui-icon {
  width: 24px;
  height: 24px;
}

.primary-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-weight: 760;
  letter-spacing: 0;
  box-shadow: 0 12px 24px rgba(17, 17, 20, 0.16);
}

.search-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 18px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--hairline-shadow);
  color: var(--muted);
}

.search-icon {
  flex: 0 0 auto;
  width: 27px;
  height: 27px;
  color: #8e8e93;
}

.search-line input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0 26px;
  padding: 8px;
  border-radius: 16px;
  background: #ededf1;
}

.tab-chip {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 56px;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 720;
  font-size: 13px;
  box-shadow: 0 1px 0 rgba(255,255,255,.9), 0 2px 8px rgba(18, 24, 31, 0.04);
}

.ui-icon {
  width: 24px;
  height: 24px;
  display: block;
}

.section-title {
  margin: 26px 0 12px;
  font-size: 25px;
  line-height: 30px;
  font-weight: 780;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

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

.card,
.task-item,
.metric-card,
.form-card {
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow), var(--hairline-shadow);
}

.card {
  padding: 16px;
}

.stat-card {
  min-height: 96px;
}

.stat-value {
  font-size: 30px;
  line-height: 34px;
  font-weight: 820;
}

.stat-label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.agent-list,
.task-list {
  display: grid;
  gap: 10px;
}

.agent-card {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.agent-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  color: var(--agent-accent, var(--blue));
  font-weight: 800;
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(255,255,255,.74)),
    color-mix(in srgb, var(--agent-accent, var(--blue)) 18%, white);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--agent-accent, var(--blue)) 22%, transparent);
}

.agent-mark svg {
  width: 38px;
  height: 38px;
  display: block;
}

.agent-letter {
  color: var(--agent-accent, var(--blue));
  font-size: 22px;
}

.agent-name,
.task-title {
  font-weight: 760;
}

.agent-role,
.task-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.agent-role {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.agent-side {
  display: grid;
  gap: 6px;
  justify-items: end;
}

.queue-count {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 760;
}

.status-pill,
.priority-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.status-created {
  color: var(--orange);
  background: #fff3d8;
}

.status-accepted,
.status-in_progress {
  color: var(--blue);
  background: #eaf3ff;
}

.status-completed {
  color: var(--green);
  background: #e8f8ef;
}

.status-failed {
  color: var(--red);
  background: #ffefef;
}

.priority-urgent {
  color: #fff;
  background: var(--red);
}

.priority-high {
  color: #8a4d00;
  background: #fff0cc;
}

.priority-low {
  color: #60708a;
  background: #eef2f7;
}

.task-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  width: 100%;
  padding: 15px;
  text-align: left;
}

.task-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.publication-item {
  align-items: start;
  cursor: pointer;
}

.publication-item:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.publication-card-side {
  display: grid;
  gap: 6px;
  justify-items: end;
}

.publication-stages {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

.publication-stage-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--hairline-shadow);
  font-size: 13px;
  font-weight: 740;
}

.publication-stage-chip strong {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border-radius: 12px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
}

.publication-stage-chip.status-review {
  color: #8a4d00;
  background: #fff8e8;
}

.publication-stage-chip.status-ready,
.publication-stage-chip.status-published {
  color: #218653;
  background: #eefbf4;
}

.publication-stage-chip.status-scheduled {
  color: #1f63b5;
  background: #edf6ff;
}

.publication-board {
  display: grid;
  gap: 12px;
}

.publication-column {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  background: #f0f0f4;
  box-shadow: var(--hairline-shadow);
}

.publication-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px;
}

.publication-column-header span:first-child {
  display: grid;
  gap: 2px;
}

.publication-column-header strong {
  font-size: 15px;
  line-height: 19px;
}

.publication-column-header small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.publication-column-count {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 780;
  box-shadow: var(--hairline-shadow);
}

.publication-status-select {
  min-height: 34px;
  max-width: 136px;
  padding: 0 8px;
  border: 0;
  border-radius: 9px;
  background: var(--soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 760;
  box-shadow: var(--hairline-shadow);
}

.publication-canvas .result-editor {
  min-height: 260px;
}

.knowledge-folders {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.knowledge-folders::-webkit-scrollbar {
  display: none;
}

.folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--hairline-shadow);
  font-size: 13px;
  font-weight: 740;
  white-space: nowrap;
}

.folder-chip.active {
  background: var(--ink);
  color: #fff;
}

.folder-chip span {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: rgba(118, 118, 128, 0.14);
  font-size: 11px;
}

.folder-chip.active span {
  background: rgba(255, 255, 255, 0.18);
}

.progress-block {
  margin-top: 10px;
}

.progress-block-detail {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--hairline-shadow);
}

.progress-meter {
  height: 7px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--soft-2);
}

.progress-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 0.25s ease;
}

.progress-caption,
.progress-detail,
.progress-warning {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.progress-detail {
  font-size: 13px;
}

.progress-warning {
  color: var(--orange);
  font-weight: 700;
}

.inline-error {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 10px;
  background: #ffefef;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

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

.filters select,
.filters input,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 0;
  outline: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--hairline-shadow);
  color: var(--text);
}

.filters select {
  min-height: 42px;
  padding: 0 12px;
}

.filter-search {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--hairline-shadow);
  color: var(--muted);
}

.filter-search input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  box-shadow: none;
}

.filter-search .search-icon {
  width: 20px;
  height: 20px;
}

.form-card {
  padding: 14px;
}

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

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

.field-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.handoff-agent-grid {
  display: grid;
  gap: 8px;
}

.handoff-agent-option {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  box-shadow: var(--hairline-shadow);
}

.handoff-agent-option.selected {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 10px 20px rgba(17, 17, 20, 0.12);
}

.handoff-agent-option.selected .agent-role {
  color: rgba(255, 255, 255, 0.72);
}

.handoff-agent-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--agent-accent, var(--blue)) 14%, white);
  color: var(--agent-accent, var(--blue));
}

.handoff-agent-option.selected .handoff-agent-icon {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.handoff-agent-icon svg {
  width: 30px;
  height: 30px;
}

.handoff-screen {
  display: grid;
  gap: 12px;
  padding-top: 12px;
}

.handoff-screen .field textarea {
  min-height: 156px;
}

.handoff-source-preview {
  padding: 12px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--hairline-shadow);
}

.handoff-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: grid;
  gap: 8px;
  padding: 10px 0 calc(4px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(251,251,253,0), var(--bg) 22%);
}

.field input,
.field select {
  min-height: 48px;
  padding: 0 12px;
}

.field textarea {
  min-height: 132px;
  resize: vertical;
  padding: 12px;
  line-height: 1.35;
}

.template-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 12px;
}

.template-row button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 720;
  box-shadow: var(--hairline-shadow);
}

.submit-button,
.secondary-button,
.danger-button {
  width: 100%;
  min-height: 50px;
  border-radius: 12px;
  font-weight: 780;
}

.submit-button {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 12px 24px rgba(17, 17, 20, 0.14);
}

.secondary-button {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--hairline-shadow);
}

.submit-button:disabled,
.secondary-button:disabled {
  opacity: .45;
  cursor: default;
}

.danger-button {
  background: #ffefef;
  color: var(--red);
}

.metric-grid {
  display: grid;
  gap: 12px;
}

.metric-card {
  padding: 16px;
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.meter {
  height: 8px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--soft-2);
}

.meter span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--blue);
}

.empty-state {
  padding: 28px 18px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--hairline-shadow);
  color: var(--muted);
  text-align: center;
}

.settings-list {
  display: grid;
  gap: 10px;
}

.settings-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow), var(--hairline-shadow);
}

.settings-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
}

.settings-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(251, 251, 253, 0.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(22px) saturate(1.25);
}

.bottom-nav button {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 52px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
}

.bottom-nav span {
  font-size: 22px;
  line-height: 24px;
}

.bottom-nav button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--hairline-shadow);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.24);
}

.modal {
  max-height: 88vh;
  overflow: auto;
  border-radius: 24px 24px 0 0;
  background: var(--bg);
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.modal-header h2 {
  margin: 2px 0 0;
  font-size: 22px;
}

.modal-kicker {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.detail-block {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--hairline-shadow);
}

.detail-block h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.detail-block p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.4;
}

.result-canvas {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow), var(--hairline-shadow);
}

.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.copy-button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 750;
}

.result-editor {
  width: 100%;
  min-height: 280px;
  border: 0;
  outline: 0;
  border-radius: 12px;
  background: #fafafa;
  box-shadow: inset 0 0 0 1px rgba(17, 17, 20, 0.06);
  padding: 12px;
  color: var(--text);
  line-height: 1.45;
  resize: vertical;
  white-space: pre-wrap;
}

.result-editor[readonly] {
  color: var(--text);
}

.copy-sections,
.result-actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 0;
}

.copy-sections button,
.result-actions button {
  flex: 0 0 auto;
  width: auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 10px;
}

.handoff-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.chain-button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
}

.event-list {
  display: grid;
  gap: 8px;
}

.event-item {
  display: grid;
  grid-template-columns: 9px 1fr;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
}

.event-dot {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--blue);
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 60;
  padding: 13px 15px;
  border-radius: 8px;
  background: #111;
  color: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  .view {
    padding-inline: 24px;
  }

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

  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .publication-stages {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .publication-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
}

@media (max-width: 380px) {
  .app-header {
    grid-template-columns: 76px 1fr 44px;
    padding-inline: 12px;
  }

  .app-title {
    font-size: 18px;
  }

  .primary-pill {
    padding: 0 14px;
    font-size: 15px;
  }

  .tabs {
    gap: 6px;
    padding: 6px;
  }

  .tab-chip {
    font-size: 12px;
  }
}
