:root {
  --navy: #102743;
  --blue: #1459a6;
  --blue-soft: #eaf2fb;
  --ink: #172033;
  --muted: #667085;
  --line: #dfe4ea;
  --surface: #ffffff;
  --page: #f5f7fa;
  --danger: #b42318;
  --success: #067647;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--page); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 92px;
  padding: 18px clamp(20px, 4vw, 64px);
  background: var(--navy);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: -0.02em; }
h2 { margin-bottom: 0; font-size: 20px; }
h3 { margin-bottom: 8px; font-size: 16px; }
.eyebrow, .section-label { margin-bottom: 4px; font-size: 11px; font-weight: 750; letter-spacing: 0.12em; }
.eyebrow { color: #9dc3f0; }
.section-label { color: var(--blue); }

.health { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #d7e6f7; }
.health span:first-child { width: 9px; height: 9px; border-radius: 50%; background: #f79009; }
.health.ready span:first-child { background: #32d583; }
.health.error span:first-child { background: #f04438; }

main { width: min(1440px, calc(100% - 40px)); margin: 24px auto 60px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.metrics article { padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.metrics span { display: block; color: var(--muted); font-size: 12px; }
.metrics strong { display: block; margin-top: 5px; font-size: 25px; }

.layout { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 1px 2px rgba(16, 39, 67, 0.04); }
.compose-panel, .integration-panel { padding: 20px; }
.panel-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
.tickets-panel .panel-heading { padding: 20px 20px 12px; }

form, label { display: grid; gap: 7px; }
form { gap: 14px; }
label { color: #344054; font-size: 12px; font-weight: 650; }
input, select, textarea { width: 100%; padding: 10px 11px; border: 1px solid #cfd6df; border-radius: 6px; color: var(--ink); background: white; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20, 89, 166, 0.1); }
textarea { resize: vertical; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.primary, .secondary, .danger, .text-button { border-radius: 6px; font-weight: 700; }
.primary { padding: 10px 14px; border: 1px solid var(--blue); background: var(--blue); color: white; }
.secondary { padding: 8px 11px; border: 1px solid #cfd6df; background: white; color: #344054; }
.danger { padding: 6px 9px; border: 1px solid #fecdca; background: #fff5f4; color: var(--danger); }
.text-button { padding: 5px 2px; border: 0; background: transparent; color: var(--blue); }
.primary:hover { background: #0e4b91; }
.secondary:hover { background: #f8fafc; }

.list-heading { flex-wrap: wrap; }
.filters { display: flex; gap: 8px; }
.filters select { width: auto; min-width: 130px; padding: 8px; }
.table-wrap { overflow: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; font-size: 13px; }
th { padding: 10px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f9fafb; color: var(--muted); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
td { padding: 13px 14px; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.ticket-title { max-width: 320px; font-weight: 650; }
.ticket-title small { display: block; margin-top: 4px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; padding: 4px 7px; border-radius: 999px; background: #f2f4f7; color: #475467; font-size: 10px; font-weight: 800; }
.badge.CRITICAL, .badge.ESCALATED { background: #fee4e2; color: #b42318; }
.badge.HIGH { background: #fff1e7; color: #b54708; }
.badge.NEW { background: #eaf2fb; color: #1459a6; }
.badge.CLAIMED, .badge.IN_PROGRESS { background: #f4ebff; color: #6941c6; }
.badge.RESOLVED, .badge.CLOSED { background: #e7f6ec; color: #067647; }
.ticket-row { cursor: pointer; }
.row-actions { display: flex; gap: 6px; }
.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty { padding: 38px; text-align: center; color: var(--muted); }

.integration-panel { margin-top: 16px; }
.integration-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.integration-grid article { padding: 16px; border: 1px solid var(--line); border-radius: 7px; }
.integration-grid p { color: var(--muted); font-size: 13px; }
.inline-form, .button-row { display: flex; gap: 8px; }
.inline-form input { max-width: 260px; }
pre { min-height: 78px; max-height: 220px; overflow: auto; margin: 12px 0 0; padding: 12px; border-radius: 6px; background: #101828; color: #d0d5dd; font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }
.api-key-note { color: var(--muted); font-size: 12px; }
code { color: #344054; }

#toast { position: fixed; right: 20px; bottom: 20px; max-width: 360px; padding: 12px 15px; border-radius: 7px; background: var(--ink); color: white; font-size: 13px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: 160ms ease; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: var(--danger); }

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

@media (max-width: 600px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  main { width: min(100% - 24px, 1440px); margin-top: 12px; }
  .field-grid, .metrics { grid-template-columns: 1fr; }
  .filters { width: 100%; flex-wrap: wrap; }
  .filters select { flex: 1; min-width: 120px; }
  .panel-heading { align-items: flex-start; }
  .api-key-note { display: none; }
}

body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 39, 67, 0.62);
}
.ticket-modal {
  width: min(780px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(16, 39, 67, 0.3);
}
.modal-heading, .detail-summary, .activity-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.modal-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: white;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}
.detail-summary { margin-top: 18px; align-items: center; }
.detail-summary > strong { color: var(--blue); font-size: 14px; }
.detail-meta { margin: 10px 0 20px; color: var(--muted); font-size: 12px; }
.detail-block { margin-top: 16px; padding: 17px; border: 1px solid var(--line); border-radius: 8px; }
.detail-description { margin-bottom: 0; color: #344054; line-height: 1.55; white-space: pre-wrap; }
.agent-activity-block { border-color: #b8d6f4; background: #f7fbff; }
.activity-status { padding: 4px 8px; border-radius: 999px; background: #e7f6ec; color: var(--success); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.activity-list { display: grid; gap: 12px; margin-top: 14px; }
.activity-entry { padding: 14px; border-left: 4px solid var(--blue); border-radius: 6px; background: white; box-shadow: 0 1px 2px rgba(16, 39, 67, 0.06); }
.activity-entry strong { color: var(--navy); font-size: 12px; }
.activity-entry p { margin: 8px 0 0; color: #344054; font-size: 13px; line-height: 1.55; white-space: pre-wrap; }
.activity-empty { margin: 0; color: var(--muted); font-size: 13px; }
