:root {
  --bg: #120F10;
  --surface: #1C1718;
  --elevated: #251E20;
  --active: #302729;
  --accent: #C85C43;
  --accent-soft: #E38B74;
  --accent-deep: #8D2F18;
  --accent-warm: #F3C2B6;
  --text: #FCF6F4;
  --text-secondary: #E3D4CF;
  --text-muted: #B59F99;
  --border: #3B2F31;
  --success: #5EA976;
  --warning: #D3A43A;
  --danger: #CF6C6C;
  --shadow: 0 22px 46px rgba(0, 0, 0, 0.28);
  font-family: Inter, "Avenir Next", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  position: relative;
  background:
    radial-gradient(circle at 18% 8%, rgba(227, 139, 116, 0.18), transparent 0 18%, transparent 28%),
    radial-gradient(circle at 82% 12%, rgba(200, 92, 67, 0.18), transparent 0 16%, transparent 26%),
    radial-gradient(circle at 50% -16%, rgba(243, 194, 182, 0.12), transparent 22%),
    linear-gradient(180deg, #181314 0%, var(--bg) 24%, #130F10 100%);
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  pointer-events: none;
  z-index: 0;
  filter: blur(48px);
  opacity: 0.52;
}

body::before {
  width: 220px;
  height: 220px;
  top: -28px;
  left: -40px;
  border-radius: 45% 55% 62% 38% / 42% 44% 56% 58%;
  background: rgba(200, 92, 67, 0.18);
}

body::after {
  width: 260px;
  height: 260px;
  right: -60px;
  bottom: 8%;
  border-radius: 39% 61% 35% 65% / 49% 35% 65% 51%;
  background: rgba(227, 139, 116, 0.11);
}

body > * {
  position: relative;
  z-index: 1;
}

.terminal-output {
  margin: 0;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(59, 47, 49, 0.92);
  background: rgba(12, 10, 11, 0.92);
  color: var(--accent-warm);
  font-family: "SFMono-Regular", "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 420px;
  overflow: auto;
}

.app-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(25, 20, 21, 0.94), rgba(18, 17, 17, 0.88));
  backdrop-filter: blur(18px) saturate(130%);
  border-bottom: 1px solid rgba(59, 47, 49, 0.9);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.app-nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(36, 30, 32, 0.96), rgba(28, 23, 24, 0.96));
  border: 1px solid rgba(59, 47, 49, 0.92);
  color: var(--text-secondary);
  font-size: 0.84rem;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.app-nav a:hover {
  transform: translateY(-1px);
  border-color: rgba(227, 139, 116, 0.42);
  color: var(--text);
}

.nav-link-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  min-height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 0.72rem;
  line-height: 1;
}

.nav-link-badge[hidden] {
  display: none;
}

.toast-region {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  right: 12px;
  z-index: 90;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(59, 47, 49, 0.95);
  background: rgba(27, 23, 24, 0.96);
  color: var(--text-secondary);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-8px) scale(0.99);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast.toast-success {
  border-color: rgba(79, 157, 105, 0.5);
  background: rgba(79, 157, 105, 0.14);
}

.toast.toast-warning {
  border-color: rgba(198, 147, 45, 0.5);
  background: rgba(198, 147, 45, 0.14);
}

.toast.toast-danger {
  border-color: rgba(198, 90, 90, 0.5);
  background: rgba(198, 90, 90, 0.14);
}

.activity-rail {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 70;
  width: min(360px, calc(100vw - 24px));
  border: 1px solid rgba(59, 47, 49, 0.94);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(31, 25, 27, 0.96), rgba(24, 20, 21, 0.96));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(130%);
  overflow: hidden;
}

.activity-toggle,
.activity-clear {
  border: 0;
  background: transparent;
  color: var(--text);
}

.activity-toggle {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.activity-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 30px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 0.8rem;
}

.activity-body {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

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

.activity-header h2 {
  font-size: 0.94rem;
}

.activity-clear {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.activity-list {
  display: grid;
  gap: 8px;
  max-height: min(40vh, 360px);
  overflow-y: auto;
}

.session-activity-card {
  padding: 12px;
}

.session-activity-list {
  max-height: 220px;
}

.activity-item {
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(36, 30, 29, 0.72);
}

.activity-item strong {
  display: block;
  font-size: 0.84rem;
}

.activity-item p {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.45;
}

.activity-item time {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.74rem;
}

.activity-item.activity-item-danger {
  border-color: rgba(198, 90, 90, 0.44);
}

.activity-item.activity-item-warning {
  border-color: rgba(198, 147, 45, 0.44);
}

.report-filter-grid {
  display: grid;
  gap: 12px;
}

.report-preset-row {
  flex-wrap: wrap;
}

.report-filter-grid label {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 0.86rem;
}

.report-filter-grid input[type="text"],
.report-filter-grid input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.workflow-packets {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.detail-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(36, 30, 29, 0.72);
}

.detail-card h3 {
  margin: 0 0 4px;
  font-size: 0.9rem;
}

.compact-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--text-secondary);
}

.compact-list li + li {
  margin-top: 4px;
}

.workflow-artifact-checklist {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.workflow-artifact-checklist form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.checkbox-row {
  display: flex !important;
  align-items: center;
  gap: 10px;
}

.report-metric-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.report-metric-card h2,
.report-row-card h2,
.report-event-card h2 {
  margin: 0;
}

.report-row-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.report-link-block {
  display: grid;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.report-event-card p {
  margin-bottom: 0;
}

.report-spike-card {
  border-color: rgba(198, 147, 45, 0.34);
}

.activity-empty {
  color: var(--text-muted);
  font-size: 0.82rem;
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }
button.is-pending {
  opacity: 0.72;
  cursor: progress;
}
a { color: inherit; text-decoration: none; }

.screen {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

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

.topbar.sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: calc(-14px - env(safe-area-inset-top)) -16px 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(23, 18, 19, 0.94), rgba(18, 17, 17, 0.88));
  backdrop-filter: blur(18px) saturate(130%);
  border-bottom: 1px solid rgba(59, 47, 49, 0.5);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 50px;
  height: 50px;
  border-radius: 18px;
  box-shadow: 0 10px 26px rgba(200, 92, 67, 0.24);
}

h1, h2, p { margin: 0; }
h1 { font-size: 1.22rem; line-height: 1.1; letter-spacing: 0.01em; }
h2 { font-size: 1rem; letter-spacing: 0.01em; }
.muted { color: var(--text-muted); font-size: 0.82rem; margin-top: 4px; }

.icon-button, .button {
  min-width: 48px;
  min-height: 48px;
  border: 1px solid rgba(59, 47, 49, 0.95);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(40, 32, 34, 0.98), rgba(31, 25, 27, 0.98));
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button:hover, .button:hover {
  transform: translateY(-1px);
  border-color: rgba(227, 139, 116, 0.4);
}

.icon-button { width: 48px; padding: 0; font-size: 1.18rem; }
.primary {
  background: linear-gradient(180deg, var(--accent-soft), var(--accent));
  border-color: rgba(227, 139, 116, 0.9);
  color: white;
  box-shadow: 0 16px 34px rgba(200, 92, 67, 0.26);
}

.session-list {
  display: grid;
  gap: 12px;
}

.session-section {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

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

.empty-inline {
  padding: 12px 2px 4px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.system-banner {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(59, 47, 49, 0.92);
  background: linear-gradient(180deg, rgba(36, 29, 31, 0.98), rgba(28, 23, 24, 0.98));
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.system-banner.warning {
  border-color: rgba(198, 147, 45, 0.5);
  background: rgba(198, 147, 45, 0.12);
  color: #f3ddb0;
}

.session-card, .empty-card {
  display: block;
  background: linear-gradient(180deg, rgba(30, 24, 26, 0.98), rgba(27, 22, 23, 0.98));
  border: 1px solid rgba(59, 47, 49, 0.92);
  border-radius: 24px;
  padding: 16px;
  box-shadow: var(--shadow);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.session-card:hover, .empty-card:hover {
  transform: translateY(-1px);
  border-color: rgba(227, 139, 116, 0.35);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3);
}

.empty-card {
  display: grid;
  gap: 12px;
  min-height: 220px;
  align-content: center;
}

.session-card:active { background: var(--active); }
.session-card.is-syncing {
  opacity: 0.78;
  border-color: rgba(179, 64, 32, 0.5);
}
.session-card.is-focused {
  border-color: rgba(208, 106, 79, 0.88);
  box-shadow: 0 0 0 1px rgba(208, 106, 79, 0.42), var(--shadow);
}
.attention-card p:last-child {
  margin-top: 8px;
  color: var(--text-secondary);
}
.session-card-paused {
  opacity: 0.9;
}
.session-card-title { font-weight: 700; margin-bottom: 7px; }
.session-card-preview {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.session-card-meta, .pill-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(59, 47, 49, 0.9);
  background: linear-gradient(180deg, rgba(41, 33, 35, 0.98), rgba(31, 25, 27, 0.98));
  color: var(--text-secondary);
  font-size: 0.74rem;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.status-running { color: #F4D1C5; border-color: rgba(179, 64, 32, 0.55); background: rgba(179, 64, 32, 0.16); }
.status-waiting { color: #F1D89E; border-color: rgba(198, 147, 45, 0.46); background: rgba(198, 147, 45, 0.14); }
.status-needs-approval { color: #F1D89E; border-color: rgba(198, 147, 45, 0.58); background: rgba(198, 147, 45, 0.18); }
.status-complete { color: #BFE6CB; border-color: rgba(79, 157, 105, 0.48); background: rgba(79, 157, 105, 0.14); }
.status-failed { color: #F3C2C2; border-color: rgba(198, 90, 90, 0.5); background: rgba(198, 90, 90, 0.14); }
.status-paused { color: var(--text-muted); }
.status-critical { color: #F3C2C2; border-color: rgba(198, 90, 90, 0.5); background: rgba(198, 90, 90, 0.14); }
.status-high { color: #F1D89E; border-color: rgba(198, 147, 45, 0.5); background: rgba(198, 147, 45, 0.16); }
.status-medium { color: var(--text-secondary); border-color: rgba(117, 103, 98, 0.46); background: rgba(117, 103, 98, 0.16); }

.session-heading {
  flex: 1;
  min-width: 0;
}

.session-heading h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline {
  display: grid;
  gap: 12px;
  padding-bottom: 126px;
}

.message {
  width: fit-content;
  max-width: min(92%, 540px);
  padding: 14px 15px;
  border-radius: 20px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.user-message {
  justify-self: end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 8px;
}

.heartie-message, .summary-card, .image-card, .approval-card {
  justify-self: start;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.heartie-message { border-bottom-left-radius: 8px; }
.summary-card { background: var(--elevated); }
.approval-card {
  background: rgba(198, 147, 45, 0.12);
  border-color: rgba(198, 147, 45, 0.4);
}

.approval-card small {
  display: block;
  color: var(--text-muted);
  margin-top: 6px;
}

.summary-card small {
  display: block;
  color: var(--text-muted);
  margin-top: 8px;
  font-size: 0.78rem;
}

.system-event {
  justify-self: center;
  max-width: 92%;
  padding: 8px 12px;
  border: 1px solid rgba(51, 42, 40, 0.78);
  border-radius: 999px;
  background: rgba(36, 30, 29, 0.68);
  color: var(--text-muted);
  font-size: 0.78rem;
}

.image-card { padding: 10px; }
.image-card img {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 16px;
  background: #0a0909;
}
.image-card p { color: var(--text-secondary); margin: 10px 4px 0; }

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.quick-row button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--elevated);
  color: var(--text-secondary);
  padding: 0 12px;
}

.quick-row input,
.stack-form input,
.stack-form textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  padding: 12px 14px;
}

.stack-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.detail-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.detail-row {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(36, 30, 29, 0.58);
}

.detail-row dt {
  color: var(--text-muted);
  font-size: 0.76rem;
  text-transform: capitalize;
}

.detail-row dd {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 0.86rem;
}

.toggle-row input {
  width: auto;
  min-width: 18px;
  min-height: 18px;
  margin: 0;
}

.briefing-text {
  white-space: pre-wrap;
  font: inherit;
  color: var(--text-secondary);
  margin: 14px 0 0;
}

.composer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: min(100%, 720px);
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(18, 17, 17, 0), rgba(18, 17, 17, 0.96) 24%);
}

.composer-message {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  padding: 8px;
  box-shadow: 0 -16px 34px rgba(0, 0, 0, 0.22);
}

.composer-upload { display: flex; align-items: flex-end; }

.composer textarea {
  flex: 1;
  min-height: 48px;
  max-height: 130px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 13px 4px;
}

.composer textarea::placeholder { color: var(--text-muted); }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
}

.bottom-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 60;
  width: min(100%, 640px);
  transform: translate(-50%, 105%);
  transition: transform 180ms ease;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--elevated);
  box-shadow: 0 -24px 54px rgba(0, 0, 0, 0.36);
}

body.sheet-open .sheet-backdrop { display: block; }
body.sheet-open .bottom-sheet { transform: translate(-50%, 0); }

.sheet-handle {
  width: 44px;
  height: 4px;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: var(--border);
}

.bottom-sheet h2 { margin-bottom: 12px; }

.sheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sheet-grid-single {
  grid-template-columns: 1fr;
  margin-bottom: 10px;
}

.sheet-action {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.office-placeholder-card {
  display: grid;
  gap: 18px;
}

.office-placeholder-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.office-placeholder-panel {
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(36, 30, 29, 0.72);
}

.office-placeholder-panel h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.office-placeholder-panel ul {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
}

@media (min-width: 760px) {
  .screen { padding-inline: 22px; }
}

@media (max-width: 759px) {
  .toast-region {
    top: auto;
    bottom: calc(84px + env(safe-area-inset-bottom));
    right: 12px;
  }

  .activity-rail {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: calc(76px + env(safe-area-inset-bottom));
  }
}
