:root {
  --bg: #eef4ef;
  --panel: #ffffff;
  --panel-alt: #f5faf6;
  --ink: #1d3428;
  --muted: #62786c;
  --line: #d9e6dc;
  --brand: #2f6b4f;
  --brand-strong: #1f4e38;
  --danger: #b54040;
  --warning: #b8741a;
  --shadow: 0 18px 40px rgba(18, 41, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, #e7f1ea 0%, #f7faf8 100%);
  color: var(--ink);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

body {
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: #edf5ef;
}

.admin-shell {
  min-height: 100vh;
}

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  backdrop-filter: blur(16px);
  background: rgba(247, 250, 248, 0.88);
  border-bottom: 1px solid rgba(217, 230, 220, 0.9);
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.admin-brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--brand), #5e9474);
}

.admin-brand-eyebrow,
.section-eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.admin-brand-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-nav-link,
.admin-user-chip {
  padding: 0.72rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  font-size: 0.95rem;
}

.admin-nav-link.is-active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.admin-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem;
}

.admin-alert {
  margin-bottom: 1rem;
  padding: 0.95rem 1.1rem;
  border-radius: 18px;
  border: 1px solid transparent;
}

.admin-alert.is-success {
  background: #edf7f0;
  color: var(--brand-strong);
  border-color: #c9e1d0;
}

.admin-alert.is-error {
  background: #fff1f1;
  color: #842b2b;
  border-color: #f0caca;
}

.auth-card,
.panel,
.ticket-card,
.message-card {
  background: var(--panel);
  border: 1px solid rgba(217, 230, 220, 0.92);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.auth-card {
  max-width: 560px;
  margin: 5vh auto 0;
  padding: 2rem;
}

.auth-copy h1 {
  margin: 0.5rem 0 0.5rem;
  font-size: 2rem;
}

.auth-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.auth-form {
  display: grid;
  gap: 1rem;
  margin-top: 1.6rem;
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field-label {
  font-size: 0.94rem;
  font-weight: 600;
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  padding: 0.9rem 1rem;
  font: inherit;
  color: var(--ink);
}

.field-textarea {
  min-height: 160px;
  resize: vertical;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.95rem 1.2rem;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.button-primary {
  background: var(--brand);
  color: white;
}

.button-secondary {
  background: #eaf3ed;
  color: var(--brand-strong);
  border: 1px solid #d0e2d6;
}

.button-danger {
  background: #fff1f1;
  color: #8f2c2c;
  border: 1px solid #f0caca;
}

.button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.page-head h1,
.ticket-header h1 {
  margin: 0.35rem 0 0;
  font-size: 2rem;
}

.page-head p,
.ticket-header p,
.muted {
  color: var(--muted);
  line-height: 1.6;
}

.panel {
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem;
}

.stat-card {
  padding: 1rem;
  border-radius: 22px;
  background: linear-gradient(180deg, #f8fbf9 0%, #eff6f1 100%);
  border: 1px solid #deebe2;
}

.stat-value {
  margin-top: 0.35rem;
  font-size: 1.7rem;
  font-weight: 800;
}

.filters-form {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) repeat(2, minmax(180px, 1fr)) auto;
  gap: 0.9rem;
  align-items: end;
}

.segment-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem;
  align-items: end;
}

.tickets-grid {
  display: grid;
  gap: 1rem;
}

.ticket-card {
  padding: 1.1rem;
}

.ticket-card-header,
.ticket-meta-row,
.ticket-actions,
.message-meta {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.ticket-actions form {
  margin: 0;
}

.ticket-subject {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.badge-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: #edf5ef;
  color: var(--brand-strong);
}

.badge.status-open {
  background: #eef5ff;
  color: #2b5ea0;
}

.badge.status-answered {
  background: #eef8f0;
  color: #22623d;
}

.badge.status-closed {
  background: #f2f2f2;
  color: #565656;
}

.badge.unread {
  background: #fff1f1;
  color: var(--danger);
}

.ticket-body {
  margin-top: 0.95rem;
  display: grid;
  gap: 0.65rem;
}

.ticket-preview {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 1rem;
}

.sidebar-stack {
  display: grid;
  gap: 1rem;
}

.meta-list {
  display: grid;
  gap: 0.9rem;
}

.meta-item {
  display: grid;
  gap: 0.2rem;
}

.meta-key {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.message-thread {
  display: grid;
  gap: 1rem;
}

.message-card {
  padding: 1rem;
}

.message-card.is-admin {
  border-color: #cfe1d6;
  background: linear-gradient(180deg, #f8fcf9 0%, #edf5ef 100%);
}

.message-meta {
  margin-bottom: 0.7rem;
}

.message-role {
  font-weight: 800;
}

.message-content {
  margin: 0;
  line-height: 1.65;
  white-space: pre-wrap;
}

.message-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #f4f8f5;
  border-radius: 18px;
  border: 1px solid #dbe8de;
}

.message-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.message-image-link {
  display: block;
  aspect-ratio: 1 / 1;
  padding: 0.5rem;
  border-radius: 20px;
  background: #f8fbf9;
  border: 1px solid #dbe8de;
}

.reply-form {
  display: grid;
  gap: 1rem;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
  margin-top: 0.8rem;
}

.mode-option {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.85rem;
  border: 1px solid #deebe2;
  border-radius: 18px;
  background: #f8fbf9;
}

.mode-option input {
  margin-top: 0.2rem;
}

.recipient-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
  margin-top: 0.8rem;
}

.recipient-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid #deebe2;
  border-radius: 18px;
  background: #f8fbf9;
}

.recipient-option input {
  margin-top: 0.2rem;
}

.empty-state {
  padding: 2rem;
  text-align: center;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.admin-table th,
.admin-table td {
  padding: 0.95rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid #e2ece5;
  vertical-align: top;
}

.admin-table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.table-link {
  font-weight: 700;
  color: var(--brand-strong);
}

.table-subtext {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.list-stack {
  display: grid;
  gap: 0.85rem;
}

.mini-card {
  display: grid;
  gap: 0.45rem;
  padding: 1rem;
  border-radius: 20px;
  background: linear-gradient(180deg, #fafdfb 0%, #f1f7f3 100%);
  border: 1px solid #deebe2;
}

.mini-card.is-highlight {
  background: linear-gradient(135deg, var(--brand), #4f8769);
  color: white;
  border-color: transparent;
}

.mini-card.is-highlight .section-eyebrow,
.mini-card.is-highlight .table-subtext {
  color: rgba(255, 255, 255, 0.82);
}

.mini-card-head {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}

.developer-head {
  padding: 1.25rem;
  border: 1px solid #dedbd6;
  border-left: 4px solid #ff5600;
  border-radius: 8px;
  background: #faf9f6;
}

.developer-mode-state {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 0.8rem;
  border: 1px solid #dedbd6;
  border-radius: 4px;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.developer-mode-state.is-on {
  color: #8d3100;
  border-color: #ffb58f;
  background: #fff0e8;
}

.developer-mode-state.is-off {
  color: #626260;
  background: #f2f0ed;
}

.developer-lock-panel,
.developer-toolbar,
.developer-danger-zone {
  border-radius: 8px;
  border-color: #dedbd6;
  box-shadow: none;
  background: #faf9f6;
}

.developer-lock-panel,
.developer-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.developer-inline-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 0.75rem;
  align-items: end;
  margin-top: 1rem;
}

.developer-toolbar .developer-inline-form,
.developer-toolbar form {
  margin: 0;
}

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

.developer-grid > .panel {
  margin: 0;
  border-radius: 8px;
  border-color: #dedbd6;
  box-shadow: none;
}

.developer-grid-wide {
  grid-column: 1 / -1;
}

.developer-action-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.developer-action-stack form {
  margin: 0;
}

.developer-task-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #dedbd6;
}

.developer-task-list > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: #626260;
}

.developer-danger-zone {
  border-color: #e7b9b9 !important;
  background: #fff8f7 !important;
}

.api-status-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
  color: #7b7b78;
}

.api-status-meta code {
  overflow-wrap: anywhere;
}

.api-status-placeholder {
  padding: 2.5rem 1rem;
  text-align: center;
}

.api-status-table {
  min-width: 840px;
}

.api-endpoint-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  color: #111111;
}

.api-health-pill {
  display: inline-flex;
  padding: 0.35rem 0.55rem;
  border: 1px solid;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.api-health-pill.is-healthy {
  color: #145b2d;
  border-color: #a5dab4;
  background: #ecf8ef;
}

.api-health-pill.is-degraded {
  color: #7a4a00;
  border-color: #e6c98f;
  background: #fff7e8;
}

.api-health-pill.is-unhealthy {
  color: #8b2626;
  border-color: #efb0b0;
  background: #fff0f0;
}

.api-health-pill.is-pending {
  color: #626260;
  border-color: #dedbd6;
  background: #faf9f6;
}

.api-health-pill.is-checking {
  color: #0007cb;
  border-color: #aeb2ec;
  background: #f0f1ff;
}

.api-row-checking {
  background: #f7f7ff;
}

.api-stat-healthy {
  border-left: 4px solid #0b9b40;
}

.api-stat-degraded {
  border-left: 4px solid #d28a00;
}

.api-stat-unhealthy {
  border-left: 4px solid #c41c1c;
}

@media (max-width: 960px) {
  .stats-grid,
  .filters-form,
  .split-layout,
  .developer-grid {
    grid-template-columns: 1fr;
  }

  .developer-grid-wide {
    grid-column: auto;
  }
}

@media (max-width: 720px) {
  .admin-topbar,
  .page-head,
  .ticket-card-header,
  .ticket-meta-row,
  .ticket-actions {
    align-items: stretch;
  }

  .admin-topbar,
  .admin-nav {
    flex-direction: column;
    align-items: stretch;
  }

  .developer-lock-panel,
  .developer-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .developer-inline-form {
    grid-template-columns: 1fr;
  }

  .admin-main {
    padding: 1rem;
  }

  .auth-card,
  .panel,
  .ticket-card,
  .message-card {
    border-radius: 22px;
  }
}
