:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #65758b;
  --line: #d9e0e8;
  --green: #137c3a;
  --green-bg: #e9f8ee;
  --blue: #1665b8;
  --blue-bg: #eaf3ff;
  --orange: #a15c00;
  --orange-bg: #fff4df;
  --red: #b42318;
  --red-bg: #ffebe8;
  --gray: #5c6674;
  --gray-bg: #eef1f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.page {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.1;
}

.refresh {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  border-color: #b7c3d1;
}

.summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  min-height: 82px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.metric.danger strong {
  color: var(--red);
}

.metric.neutral strong {
  color: var(--gray);
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
  margin-bottom: 16px;
}

.meta-panel {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

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

.meta-panel div {
  min-width: 0;
}

.meta-panel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.meta-panel strong,
.meta-panel p {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
}

.meta-ticket {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfe;
}

.meta-ticket button {
  margin-top: 8px;
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.ticket-queue {
  display: none;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  box-shadow: var(--shadow);
}

.ticket-queue.visible {
  display: block;
}

.ticket-queue-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.ticket-queue-head h2 {
  font-size: 18px;
}

.ticket-queue-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.ticket-table {
  display: grid;
  gap: 6px;
  overflow-x: auto;
}

.ticket-row {
  display: grid;
  grid-template-columns: 110px 150px 70px 130px minmax(220px, 1fr) 120px 90px;
  gap: 10px;
  min-width: 940px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
}

.ticket-row.header {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  background: #fbfcfe;
}

.ticket-row a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.strip-item {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--muted);
}

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

.card {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.card.archived {
  background: #fafbfc;
}

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

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.type {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 130px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge.ok,
.badge.ready,
.badge.active {
  color: var(--green);
  background: var(--green-bg);
}

.badge.shadow,
.badge.paper,
.badge.watching {
  color: var(--blue);
  background: var(--blue-bg);
}

.badge.warning,
.badge.not_ready {
  color: var(--orange);
  background: var(--orange-bg);
}

.badge.critical,
.badge.blocked {
  color: var(--red);
  background: var(--red-bg);
}

.badge.needs-attention,
.badge.active-optimization,
.badge.ready-for-next-stage,
.badge.progressing {
  color: var(--blue);
  background: var(--blue-bg);
}

.badge.stalled {
  color: var(--orange);
  background: var(--orange-bg);
}

.badge.unknown,
.badge.n-a,
.badge.paused,
.badge.archived,
.badge.discarded {
  color: var(--gray);
  background: var(--gray-bg);
}

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

.fields div,
.pnl-item {
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfe;
}

.fields span,
.pnl-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.fields strong,
.pnl-item strong {
  display: block;
  margin-top: 7px;
  font-size: 14px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

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

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

.progress-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5eaf0;
}

.bar span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  background: var(--blue);
}

.message {
  margin: 0;
  min-height: 44px;
  color: var(--text);
  line-height: 1.45;
  font-size: 14px;
}

.agent {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.agent-note {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  padding: 10px;
  font-size: 13px;
  line-height: 1.4;
}

.agent-note span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.warnings {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 30px;
}

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

.ticketables-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.ticketable {
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: #fbfcfe;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.ticketable.warning,
.ticketable.blocker,
.ticketable.p1,
.ticketable.p0 {
  border-left-color: var(--orange);
}

.ticketable.p0,
.ticketable.blocker {
  border-left-color: var(--red);
}

.ticketable-text strong {
  display: block;
  font-size: 13px;
  line-height: 1.3;
}

.ticketable-text p {
  margin: 4px 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.ticketable-text span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ticketable-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ticketable-actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.warning {
  border-left: 3px solid var(--orange);
  background: var(--orange-bg);
  color: #593500;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.35;
}

.blocker {
  border-left-color: var(--red);
  background: var(--red-bg);
  color: var(--red);
}

.meta {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.detail {
  display: none;
  width: fit-content;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.detail.visible {
  display: inline-block;
}

.ticket-dialog {
  width: min(1100px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 18px 60px rgba(16, 24, 40, 0.24);
}

.ticket-dialog::backdrop {
  background: rgba(23, 32, 42, 0.42);
}

.ticket-modal {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: #fff;
}

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

.ticket-form {
  display: grid;
  grid-template-columns: 1.4fr 80px 1fr 140px 120px 110px 110px 1.3fr;
  gap: 10px;
}

.ticket-form label,
.markdown-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.checkbox-label input {
  width: auto;
  min-height: 36px;
  align-self: flex-start;
}

.context-status {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 220px;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
}

.context-status strong {
  color: var(--text);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.ticket-form input,
.ticket-form select,
.markdown-label textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 9px 10px;
  text-transform: none;
}

.markdown-label textarea {
  min-height: 430px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  line-height: 1.45;
  white-space: pre;
}

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

.modal-actions span {
  color: var(--muted);
  font-size: 13px;
}

#ticketStatusText {
  margin-right: auto;
}

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

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

@media (max-width: 760px) {
  .page {
    width: min(100% - 20px, 720px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 26px;
  }

  .summary,
  .meta-panel.visible,
  .ticket-form,
  .context-status,
  .grid,
  .fields,
  .pnl {
    grid-template-columns: 1fr;
  }

  .ticket-dialog {
    width: calc(100% - 16px);
  }

  .modal-head,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-actions span {
    margin-right: 0;
  }

  .card-head {
    flex-direction: column;
  }

  .badges {
    justify-content: flex-start;
  }
}
