:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171b22;
  --panel-2: #1e242d;
  --panel-3: #242b35;
  --line: #303946;
  --line-strong: #4a5666;
  --text: #edf2f7;
  --muted: #9aa8b7;
  --faint: #6f7b89;
  --accent: #4f9ecf;
  --accent-2: #62b789;
  --accent-soft: rgba(79, 158, 207, 0.14);
  --danger: #d76060;
  --warn: #dfb55d;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid #8ac8ff;
  outline-offset: 2px;
}

.agent-shell {
  height: 100vh;
  min-width: 320px;
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 334px;
  background: var(--bg);
}

.agent-sidebar,
.agent-inspector {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.agent-sidebar {
  border-right: 1px solid var(--line);
}

.agent-inspector {
  border-left: 1px solid var(--line);
  overflow: auto;
}

.sidebar-brand {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.sidebar-brand h1,
.sidebar-brand p,
.context-block h2,
.context-block p,
.inspector-panel h3 {
  margin: 0;
}

.sidebar-brand h1,
.context-block h2 {
  font-size: 16px;
  line-height: 1.2;
}

.sidebar-brand p,
.context-block p {
  color: var(--muted);
  font-size: 12px;
}

.new-session-button,
.send-button,
.secondary-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-3);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.new-session-button {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px;
  background: var(--text);
  color: #0f1115;
}

.send-button {
  min-height: 38px;
  padding: 8px 13px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.secondary-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 11px;
  text-decoration: none;
}

.icon-button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.new-session-button:hover,
.secondary-button:hover,
.icon-button:hover,
.send-button:hover {
  border-color: var(--line-strong);
  filter: brightness(1.06);
}

.sidebar-section {
  padding: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.sidebar-section-fill {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

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

.section-label,
.section-note,
.context-kicker {
  color: var(--faint);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.service-list,
.session-list,
.project-list,
.artifact-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.session-list {
  min-height: 0;
  overflow: auto;
}

.service-item,
.session-item,
.project-item,
.artifact-item {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.session-item,
.project-item,
.artifact-item {
  grid-template-columns: minmax(0, 1fr);
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.04);
}

.service-item:hover,
.session-item:hover,
.project-item:hover,
.artifact-item:hover {
  background: var(--panel-2);
  border-color: var(--line);
}

.service-item.active,
.session-item.active,
.project-item.active {
  background: var(--accent-soft);
  border-color: rgba(79, 158, 207, 0.56);
}

.service-item.active .service-glyph {
  background: var(--accent);
  color: #fff;
}

.service-glyph {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--panel-3);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
}

.item-title,
.item-meta {
  min-width: 0;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-title {
  font-weight: 700;
}

.item-meta {
  margin-top: 2px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
}

.service-item .item-meta {
  font-family: var(--font);
  white-space: normal;
  line-height: 1.25;
}

.sidebar-user {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.user-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.credit-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  color: var(--faint);
  font-size: 12px;
}

.credit-line strong {
  color: var(--warn);
}

.sidebar-signin-button {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  padding: 7px 11px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}

.sidebar-signin-button:hover {
  background: rgba(79, 158, 207, 0.22);
  border-color: var(--accent);
  filter: brightness(1.08);
}

.agent-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.agent-topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 22, 29, 0.96);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-surface {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

.message-list {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  overflow: auto;
}

.message-list.has-onboarding {
  justify-content: center;
}

.onboarding-hero {
  width: min(760px, 100%);
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 4px;
  animation: onboarding-fade 360ms ease both;
}

.onboarding-kicker {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.onboarding-hero h2 {
  max-width: 720px;
  margin: 0;
  font-size: 34px;
  line-height: 1.18;
  letter-spacing: 0;
}

.onboarding-lead {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.sample-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.sample-prompt-button {
  max-width: 100%;
  min-height: 36px;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  overflow-wrap: anywhere;
  animation: onboarding-fade 320ms ease both;
  animation-delay: var(--sample-delay, 120ms);
}

.sample-prompt-button:hover {
  border-color: rgba(79, 158, 207, 0.55);
  background: rgba(79, 158, 207, 0.12);
}

.onboarding-budgetcode .onboarding-kicker {
  color: var(--warn);
}

.onboarding-novelforge .onboarding-kicker {
  color: #bca7ff;
}

.onboarding-articleforge .onboarding-kicker,
.onboarding-memforge .onboarding-kicker {
  color: var(--accent-2);
}

@keyframes onboarding-fade {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message {
  width: min(780px, 88%);
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.message.user {
  align-self: flex-end;
  border-color: rgba(79, 158, 207, 0.48);
  background: rgba(79, 158, 207, 0.13);
}

.message.assistant {
  align-self: flex-start;
  border-color: rgba(98, 183, 137, 0.42);
  background: rgba(98, 183, 137, 0.11);
}

.message.system {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
}

.message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-meta {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #12161d;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1117;
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  min-height: 74px;
  resize: vertical;
}

.composer-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inspector-panel {
  margin: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.panel-header {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.inspector-panel h3 {
  font-size: 13px;
}

.inspector-copy {
  margin: 0;
  padding: 10px 10px 0;
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.status-pill.ok {
  color: var(--accent-2);
  border-color: rgba(98, 183, 137, 0.4);
}

.status-pill.error {
  color: var(--danger);
  border-color: rgba(215, 96, 96, 0.4);
}

.status-pill.signin {
  color: var(--warn);
  border-color: rgba(223, 181, 93, 0.45);
}

.status-pill.conflict {
  color: var(--danger);
  border-color: rgba(215, 96, 96, 0.5);
  animation: pulse-conflict 1.8s ease infinite;
}

@keyframes pulse-conflict {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* offline draft: session list item */
.session-item.draft-item {
  opacity: 0.72;
  border-color: rgba(223, 181, 93, 0.3);
}

.draft-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border: 1px solid rgba(223, 181, 93, 0.5);
  border-radius: 4px;
  color: var(--warn);
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
}

/* offline draft: notice in message area */
.draft-notice {
  align-self: center;
  padding: 6px 12px;
  border: 1px solid rgba(223, 181, 93, 0.35);
  border-radius: 6px;
  background: rgba(223, 181, 93, 0.08);
  color: var(--warn);
  font-size: 12px;
}

/* conflict banner */
.conflict-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(215, 96, 96, 0.15);
  border-bottom: 1px solid rgba(215, 96, 96, 0.5);
  color: var(--danger);
  font-size: 13px;
}

.conflict-reload-button {
  padding: 4px 10px;
  border: 1px solid var(--danger);
  border-radius: 5px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.conflict-reload-button:hover {
  background: rgba(215, 96, 96, 0.18);
}

.route-list {
  margin: 0;
  padding: 10px;
}

.route-list div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  padding: 5px 0;
}

.route-list dt {
  color: var(--faint);
  font-size: 12px;
}

.route-list dd {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
}

.artifact-list {
  padding: 10px;
}

.artifact-item {
  color: var(--text);
}

.empty-note,
.error-note {
  padding: 10px;
  color: var(--faint);
}

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

.dialog-backdrop,
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(6, 8, 11, 0.72);
}

.hidden {
  display: none !important;
}

.dialog-card,
.auth-card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.dialog-card h2,
.auth-card h2,
.auth-card p {
  margin: 0;
}

.auth-kicker {
  margin-bottom: 5px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.auth-card h2 {
  font-size: 20px;
  line-height: 1.25;
}

.auth-card p {
  color: var(--muted);
}

.auth-pending {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  border: 1px solid rgba(79, 158, 207, 0.34);
  border-radius: 6px;
  background: rgba(79, 158, 207, 0.1);
}

.auth-pending span {
  color: var(--faint);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.auth-pending strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.dialog-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.toast-region {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  max-width: min(420px, calc(100vw - 28px));
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #202833;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3);
}

.toast.error {
  border-color: rgba(215, 96, 96, 0.6);
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .agent-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .agent-inspector {
    grid-column: 1 / -1;
    min-height: 300px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

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

  .agent-sidebar,
  .agent-inspector {
    max-height: none;
    border-right: 0;
  }

  .agent-topbar,
  .composer {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .agent-topbar,
  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .message {
    width: 100%;
  }

  .message-list.has-onboarding {
    justify-content: flex-start;
  }

  .onboarding-hero h2 {
    font-size: 24px;
  }

  .sample-prompts {
    flex-direction: column;
  }

  .sample-prompt-button {
    width: 100%;
  }

  .composer {
    display: flex;
    flex-direction: column;
  }

  .composer-actions {
    flex-direction: row;
  }

  .composer-actions button {
    flex: 1 1 0;
  }
}

/* --- Recent cards (T27) --- */

.recent-card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  padding: 4px 0;
}

.recent-card-item {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  transition: border-color 0.12s;
}

.recent-card-item:hover {
  border-color: var(--line-strong);
}

.recent-card-item.revoked {
  opacity: 0.42;
  pointer-events: none;
}

.recent-card-meta {
  font-size: 11px;
  color: var(--faint);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 3px;
}

.recent-card-excerpt {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 6px;
}

.recent-card-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.card-action-btn {
  min-height: 26px;
  padding: 3px 8px;
  font-size: 12px;
}

.revoked-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--danger);
  letter-spacing: 0.02em;
}

/* card edit dialog */

#card-edit-dialog .dialog-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#card-edit-dialog label {
  display: flex;
  flex-direction: column;
}

#card-edit-body {
  resize: vertical;
  min-height: 160px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}

#card-edit-body:focus {
  border-color: var(--accent);
  outline: none;
}

.dialog-meta {
  font-size: 12px;
  color: var(--faint);
  margin: 0;
}
