:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-muted: #edf0ec;
  --border: #d8ded6;
  --text: #17211b;
  --muted: #627168;
  --primary: #23644d;
  --primary-dark: #143d30;
  --primary-soft: #dcebe4;
  --warning: #8a4c1d;
  --danger: #9d2b2b;
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 14px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 10px 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
}

.section-label {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.ghost-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

main {
  padding: 20px;
}

.auth-panel {
  max-width: 440px;
  margin: 11vh auto 0;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.auth-panel h1,
.panel-header h1,
.detail-header h2,
.empty-state h2 {
  margin: 0;
  letter-spacing: 0;
}

.token-form {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.token-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.app-layout {
  display: grid;
  grid-template-columns:
    minmax(280px, 380px) minmax(0, 1fr) minmax(260px, 340px);
  gap: 16px;
  min-height: calc(100vh - 104px);
}

.inbox-panel,
.detail-panel,
.audit-panel {
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.inbox-panel {
  display: grid;
  grid-template-rows: auto auto auto auto auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
}

.audit-panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
}

.panel-header,
.detail-header,
.reply-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.field-label,
.token-form label,
.update-row label,
.internal-note-form label,
.reply-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.ticket-list {
  overflow: auto;
  padding-right: 2px;
}

.audit-list {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.ticket-card {
  width: 100%;
  margin: 0 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.ticket-card:hover,
.ticket-card.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.ticket-title {
  font-weight: 800;
}

.ticket-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.audit-event {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface);
}

.audit-event-type {
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 900;
}

.audit-event-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.audit-event-metadata {
  max-height: 160px;
  overflow: auto;
  margin: 8px 0 0;
  border-radius: 6px;
  padding: 8px;
  background: var(--surface-muted);
  color: var(--text);
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.detail-panel {
  padding: 18px;
  overflow: auto;
}

.empty-state {
  display: grid;
  align-content: center;
  min-height: 360px;
  color: var(--muted);
  text-align: center;
}

.detail-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

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

.badge-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.badge {
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.is-urgent,
.badge.is-high {
  background: #ffe9d6;
  color: var(--warning);
}

.badge.is-open {
  background: #e5ecff;
  color: #244880;
}

.badge.is-resolved,
.badge.is-closed {
  background: #e4eadf;
  color: #315538;
}

.badge.is-sla-waiting-first-response,
.badge.is-sla-in-progress {
  background: #e1f0ec;
  color: #1f5f4a;
}

.badge.is-sla-first-response-breached,
.badge.is-sla-resolution-breached,
.badge.is-sla-breached {
  background: #ffe3e1;
  color: var(--danger);
}

.update-row {
  display: grid;
  grid-template-columns:
    minmax(140px, 190px) minmax(140px, 190px) minmax(180px, 260px) auto;
  align-items: end;
  gap: 12px;
  margin: 16px 0;
}

.update-row .reason-field {
  grid-column: 1 / -1;
}

.update-row > button[type="submit"] {
  grid-column: 4;
  grid-row: 1;
}

.messages-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

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

.section-heading h3 {
  margin: 0;
  font-size: 16px;
}

.message {
  max-width: min(720px, 88%);
  border-radius: 18px;
  padding: 10px 14px;
  background: var(--surface-muted);
}

.message.is-support {
  margin-left: auto;
  background: var(--primary-soft);
}

.message-author {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.message-time {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.internal-notes {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.internal-notes-list {
  display: grid;
  gap: 8px;
}

.internal-note {
  border-left: 3px solid var(--primary);
  padding: 8px 0 8px 12px;
  background: transparent;
}

.internal-note-form {
  display: grid;
  gap: 8px;
}

.reply-form {
  display: grid;
  gap: 8px;
  position: sticky;
  bottom: 0;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.macro-row {
  display: grid;
  grid-template-columns: minmax(180px, 320px) auto;
  align-items: end;
  gap: 10px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .app-layout {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  }

  .audit-panel {
    grid-column: 1 / -1;
    min-height: 360px;
  }
}

@media (max-width: 860px) {
  main {
    padding: 12px;
  }

  .app-layout {
    grid-template-columns: 1fr;
  }

  .inbox-panel,
  .detail-panel {
    min-height: auto;
  }

  .update-row {
    grid-template-columns: 1fr;
  }

  .update-row .reason-field,
  .update-row > button[type="submit"] {
    grid-column: auto;
    grid-row: auto;
  }

  .token-row {
    grid-template-columns: 1fr;
  }

  .macro-row {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }
}
