:root {
  --ink: #1c2430;
  --ink-soft: #4a5568;
  --muted: #6b7280;
  --accent: #0d9488;
  --accent-dark: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-border: #99f6e4;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #b91c1c;
  --red-soft: #fef2f2;
  --border: #e5e7eb;
  --sidebar: #134e4a;
  --sidebar-text: #e5e7eb;
  --sidebar-muted: #9ca3af;
  --surface: #ffffff;
  --bg: #f0fdfa;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body.app-body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1.45;
  transition: background-color 0.12s ease;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
}

/* —— Sidebar —— */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  height: 100vh;
  max-height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  transition: background-color 0.12s ease;
}

.sidebar-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 1rem;
}

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.12s ease;
}

.brand-name {
  margin: 0;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.25;
}

.brand-tagline {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  color: var(--sidebar-muted);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  text-align: left;
  border: none;
  background: transparent;
  color: var(--sidebar-muted);
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: color-mix(in srgb, var(--accent) 38%, transparent);
  color: #fff;
}

.sidebar-section {
  margin-top: 1.5rem;
  flex: 1;
}

.sidebar-label {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
}

.team-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.82rem;
}

.team-list li {
  padding: 0.35rem 0;
  color: var(--sidebar-muted);
}

.team-list strong {
  display: block;
  color: var(--sidebar-text);
  font-weight: 500;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer select {
  width: 100%;
  margin-bottom: 0.65rem;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
}

.simulated-note {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  color: var(--sidebar-muted);
  line-height: 1.35;
}

.btn-text {
  background: none;
  border: none;
  color: var(--sidebar-muted);
  font: inherit;
  font-size: 0.78rem;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.btn-text:hover { color: #fff; }

/* —— Main —— */
.main-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem 1.5rem 0.75rem;
  background: var(--bg);
  transition: background-color 0.12s ease;
}

.page-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.page-date {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.badge-simulated {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid var(--accent-border);
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.main-content {
  padding: 0 1.5rem 1.5rem;
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.view { display: none; }
.view.active { display: block; }

/* —— Metrics —— */
.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

@media (max-width: 900px) {
  .metrics { grid-template-columns: 1fr; }
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.metric-label {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-value {
  margin: 0.35rem 0 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent-dark);
  transition: color 0.12s ease;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 1rem;
}

@media (max-width: 1100px) {
  .content-grid { grid-template-columns: minmax(0, 1fr); }
}

.content-grid > * {
  min-width: 0;
  max-width: 100%;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}

.card-narrow { max-width: 640px; }

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-head h2 { margin: 0; }

.card-lead {
  margin: -0.35rem 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

/* —— Tables —— */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table tbody tr:hover {
  background: #f9fafb;
}

.data-table .empty {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 1.5rem;
}

/* —— Status pills —— */
.pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
}

.pill-emergency { background: var(--red-soft); color: var(--red); }
.pill-urgent { background: var(--amber-soft); color: var(--amber); }
.pill-routine { background: #f3f4f6; color: var(--ink-soft); }
.pill-assigned { background: var(--accent-soft); color: var(--accent-dark); }
.pill-open { background: #eff6ff; color: #1d4ed8; }
.pill-completed { background: #f0fdf4; color: #15803d; }

/* —— Timeline —— */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  position: relative;
  padding: 0 0 0.85rem 1rem;
  border-left: 2px solid var(--border);
  margin-left: 0.35rem;
  font-size: 0.84rem;
}

.timeline li:last-child {
  border-left-color: transparent;
  padding-bottom: 0;
}

.timeline-time {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.timeline-kind {
  font-weight: 600;
  color: var(--accent-dark);
  text-transform: capitalize;
  margin-right: 0.35rem;
}

/* —— Forms —— */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.form-grid .full { grid-column: 1 / -1; }

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-soft);
}

input, select, textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.btn {
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0.55rem 1rem;
  font-weight: 600;
  font-size: 0.88rem;
  font-family: inherit;
}

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  transition: background-color 0.12s ease;
}

.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--ink-soft);
}

.btn-secondary:hover { background: #f9fafb; }

.toast {
  margin-top: 1rem;
  padding: 0.75rem 0.85rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  font-size: 0.88rem;
}

.toast.hidden { display: none; }

/* —— Integrations —— */
.stack-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.5rem;
}

.stack-badge {
  display: inline-block;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid var(--accent-border);
}

.integration-flows {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
  min-width: 0;
  max-width: 100%;
}

.integration-diagrams {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
  min-width: 0;
  max-width: 100%;
}

.integration-diagram h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
}

.diagram-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.35rem;
}

.diagram-open-link {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-dark);
  text-decoration: none;
  white-space: nowrap;
}

.diagram-open-link:hover {
  text-decoration: underline;
}

.diagram-link {
  display: block;
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.diagram-link:hover {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

.diagram-link:hover .diagram-open-hint {
  opacity: 1;
}

.diagram-open-hint {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-dark);
  padding: 0.35rem 0 0.15rem;
  opacity: 0.65;
}

.diagram-desc {
  margin: 0 0 0.75rem;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.5;
}

.mermaid-wrap {
  overflow-x: auto;
  padding: 0.5rem 0.25rem 0.25rem;
  border-top: 1px solid var(--border);
  cursor: pointer;
}

.mermaid-wrap template {
  display: none;
}

.mermaid-diagram svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.mermaid-diagram .nodeLabel foreignObject div,
.mermaid-diagram .nodeLabel foreignObject span,
.mermaid-diagram .nodeLabel foreignObject p {
  font-size: 14px !important;
  line-height: 1.35 !important;
}

.mermaid-diagram .edgeLabel foreignObject div {
  font-size: 12px !important;
}

.mermaid-diagram .messageText tspan,
.mermaid-diagram .actor tspan {
  font-size: 13px !important;
}

.mermaid-fallback {
  margin: 0;
  font-size: 0.72rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: var(--muted);
  max-width: 100%;
  overflow: auto;
}

.integration-flow h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
}

.flow-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
  min-width: 0;
}

.flow-header h3 {
  flex: 1 1 12rem;
  min-width: 0;
}

.flow-trigger {
  font-size: 0.72rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: #f3f4f6;
  color: var(--ink-soft);
  border: 1px solid var(--border);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.flow-how {
  margin: 0 0 0.85rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.payload-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 900px) {
  .payload-grid { grid-template-columns: minmax(0, 1fr); }
}

.payload-col {
  min-width: 0;
  max-width: 100%;
}

.payload-col h4 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.payload-dir {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.75rem;
}

.payload-card {
  margin-bottom: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #fafafa;
  min-width: 0;
  max-width: 100%;
}

.payload-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  align-items: baseline;
  padding: 0.45rem 0.6rem;
  background: #f3f4f6;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.payload-service {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--accent-dark);
  min-width: 0;
  overflow-wrap: anywhere;
}

.payload-action {
  font-size: 0.72rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.payload-json {
  margin: 0;
  padding: 0.65rem 0.75rem;
  font-size: 0.72rem;
  line-height: 1.45;
  overflow: auto;
  max-width: 100%;
  max-height: 220px;
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

.payload-json code {
  display: block;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.payload-empty {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
}

.card .empty {
  color: var(--muted);
  font-style: italic;
}

/* —— Mobile —— */
@media (max-width: 800px) {
  .app-shell {
    flex-direction: column;
    overflow-x: hidden;
    max-width: 100vw;
  }

  .main-column {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .main-content {
    padding: 0 0.75rem 1rem;
    max-width: 100%;
    overflow-x: hidden;
  }

  .topbar {
    padding: 1rem 0.75rem 0.65rem;
  }

  .page-title {
    font-size: 1.15rem;
  }

  .card {
    max-width: 100%;
    overflow: hidden;
    padding: 0.85rem 0.75rem;
  }

  .payload-grid,
  .payload-col,
  .payload-card,
  .payload-json {
    max-width: 100%;
  }

  .flow-trigger {
    flex: 1 1 100%;
  }

  .integration-diagram .diagram-head h3 {
    font-size: 0.9rem;
    line-height: 1.35;
  }

  .diagram-open-link {
    white-space: normal;
    text-align: right;
    max-width: 45%;
  }

  .mermaid-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    padding: 0.35rem 0;
  }

  .mermaid-diagram svg {
    min-width: 0;
    width: 100% !important;
    max-width: 100%;
  }

  .diagram-controls {
    padding: 0.45rem 0.5rem;
    gap: 0.35rem;
  }

  .diagram-step-label {
    flex-basis: 100%;
    min-width: 0;
    font-size: 0.78rem;
  }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: none;
    position: static;
    overflow-y: visible;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem;
  }

  .sidebar-brand {
    border: none;
    margin: 0;
    padding: 0;
    flex: 1;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    order: 3;
  }

  .sidebar-section { display: none; }

  .sidebar-footer {
    width: 100%;
    order: 4;
    border: none;
    padding-top: 0;
  }
}
