:root {
  --page: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #17211c;
  --body: #536159;
  --muted: #7b8881;
  --line: #dde5e0;
  --line-strong: #cbd7cf;
  --green: #176b54;
  --green-strong: #0f5744;
  --green-soft: #eaf4ef;
  --blue: #315f7d;
  --blue-soft: #edf4f8;
  --amber: #8a5a1f;
  --amber-soft: #fbf3e6;
  --red: #a33d45;
  --red-soft: #faecee;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --radius: 8px;
  color: var(--ink);
  background: var(--page);
  font-family: var(--sans);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  background: var(--page);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  text-rendering: optimizeLegibility;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--ink);
  color: #ffffff;
  transform: translateY(-140%);
}

.skip-link:focus {
  transform: translateY(0);
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.sidebar-brand {
  min-height: 82px;
  display: flex;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.brand-link {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark,
.access-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
}

.brand-link > span:last-child {
  min-width: 0;
  display: grid;
  gap: 2px;
}

img.brand-mark,
img.access-mark {
  object-fit: contain;
  background: #ffffff;
}

.brand-link strong {
  overflow: hidden;
  font-size: 15px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-link small {
  color: var(--muted);
  font-size: 11px;
}

.section-nav {
  display: grid;
  gap: 4px;
  padding: 18px 12px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--body);
  text-align: left;
  transition: background 150ms ease, color 150ms ease;
}

.nav-item:hover,
.nav-item:focus-visible {
  background: var(--surface-soft);
  color: var(--ink);
  outline: none;
}

.nav-item.is-active {
  background: var(--green-soft);
  color: var(--green-strong);
  font-weight: 650;
}

.nav-index {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.nav-item.is-active .nav-index {
  color: var(--green);
}

.sidebar-account {
  min-width: 0;
  display: grid;
  gap: 6px;
  margin-top: auto;
  padding: 18px 20px 22px;
  border-top: 1px solid var(--line);
}

.account-label {
  color: var(--muted);
  font-size: 11px;
}

.sidebar-account strong {
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-account a,
.mobile-header a {
  color: var(--green-strong);
  font-size: 12px;
  text-decoration: none;
}

.main-content {
  width: 100%;
  min-width: 0;
  max-width: 1540px;
  padding: 40px clamp(24px, 4vw, 64px) 72px;
  outline: none;
}

.mobile-header {
  display: none;
}

.view {
  min-width: 0;
}

.page-heading {
  min-height: 92px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.panel-kicker {
  margin: 0 0 7px;
  color: var(--green);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  line-height: 1.4;
  text-transform: uppercase;
}

.page-heading h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 720;
  letter-spacing: 0;
  line-height: 1.2;
}

.page-heading p:last-child {
  max-width: 650px;
  margin: 8px 0 0;
  color: var(--body);
  font-size: 14px;
  line-height: 1.7;
}

.button,
.icon-button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 620;
  line-height: 1;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  font-size: 13px;
  white-space: nowrap;
}

.button:hover,
.button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--green);
  color: var(--green-strong);
  outline: none;
}

.button:active,
.icon-button:active {
  transform: translateY(1px);
}

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

.button-primary {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.button-primary:hover,
.button-primary:focus-visible {
  border-color: var(--green-strong);
  background: var(--green-strong);
  color: #ffffff;
}

.button-danger {
  border-color: var(--red);
  background: var(--red);
  color: #ffffff;
}

.button-danger:hover,
.button-danger:focus-visible {
  border-color: #873039;
  background: #873039;
  color: #ffffff;
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--body);
}

.button-small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-top: 28px;
  overflow: hidden;
  background: var(--surface);
}

.metric {
  min-width: 0;
  min-height: 132px;
  padding: 22px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric:nth-child(3n) {
  border-right: 0;
}

.metric:nth-last-child(-n + 3) {
  border-bottom: 0;
}

.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  display: block;
  margin-top: 16px;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 700;
  line-height: 1.1;
}

.metric-note {
  display: block;
  margin-top: 8px;
  color: var(--body);
  font-size: 11px;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.data-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel-heading {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border-radius: 5px;
  background: var(--green-soft);
  color: var(--green-strong);
  font-size: 10px;
  font-weight: 650;
}

.status-dot::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.status-dot-blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.summary-list {
  margin: 0;
}

.summary-list > div {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.summary-list > div:last-child {
  border-bottom: 0;
}

.summary-list dt {
  color: var(--body);
  font-size: 12px;
}

.summary-list dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 650;
  text-align: right;
}

.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 22px 0 14px;
}

.field {
  min-width: 180px;
  display: grid;
  gap: 7px;
  color: var(--body);
  font-size: 12px;
}

.field-search {
  width: min(420px, 100%);
}

.field span {
  font-weight: 620;
}

.field b {
  color: var(--red);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.field input,
.field select {
  min-height: 42px;
  padding: 0 11px;
}

.field textarea {
  min-height: 92px;
  padding: 10px 11px;
  line-height: 1.6;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 84, 0.12);
}

.field small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.table-region {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overscroll-behavior-inline: contain;
}

.data-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

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

.cell-primary {
  display: grid;
  gap: 4px;
}

.cell-primary strong {
  max-width: 280px;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-primary small,
.cell-muted {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.cell-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--body);
  font-size: 10px;
  font-weight: 650;
  white-space: nowrap;
}

.status-pill.is-success,
.status-pill.is-active,
.status-pill.is-sent,
.status-pill.is-completed {
  background: var(--green-soft);
  color: var(--green-strong);
}

.status-pill.is-running,
.status-pill.is-sending,
.status-pill.is-queued {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-pill.is-warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-pill.is-failed,
.status-pill.is-disabled,
.status-pill.is-error {
  background: var(--red-soft);
  color: var(--red);
}

.empty-state,
.loading-state,
.error-state {
  min-height: 240px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong,
.error-state strong {
  color: var(--ink);
  font-size: 14px;
}

.empty-state p,
.error-state p,
.loading-state p {
  max-width: 460px;
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
}

.loading-line {
  width: 120px;
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--line);
}

.loading-line::after {
  width: 45%;
  height: 100%;
  display: block;
  background: var(--green);
  animation: loading 1s ease-in-out infinite alternate;
  content: "";
}

@keyframes loading {
  from {
    transform: translateX(-30%);
  }
  to {
    transform: translateX(150%);
  }
}

.pagination {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.pagination-status {
  min-width: 112px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-align: center;
}

.access-state {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--page);
}

.access-panel {
  width: min(520px, 100%);
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.access-panel .access-mark {
  margin-bottom: 28px;
}

.access-panel h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.3;
}

.access-panel > p:last-of-type {
  margin: 12px 0 0;
  color: var(--body);
  font-size: 14px;
  line-height: 1.75;
}

.access-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 26px;
}

.access-actions a {
  text-decoration: none;
}

.action-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 32px));
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(23, 33, 28, 0.18);
}

.action-dialog::backdrop {
  background: rgba(23, 33, 28, 0.34);
  backdrop-filter: blur(3px);
}

.conversation-dialog {
  width: min(860px, calc(100vw - 32px));
  max-height: min(860px, calc(100vh - 32px));
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(23, 33, 28, 0.18);
}

.conversation-dialog::backdrop {
  background: rgba(23, 33, 28, 0.34);
  backdrop-filter: blur(3px);
}

.conversation-dialog-shell {
  display: grid;
  gap: 20px;
  padding: 24px;
}

.cell-clamp {
  display: -webkit-box;
  max-width: 320px;
  overflow: hidden;
  color: var(--body);
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.conversation-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.conversation-summary > div {
  min-width: 0;
  padding: 14px;
  background: var(--surface-soft);
}

.conversation-summary dt {
  color: var(--muted);
  font-size: 11px;
}

.conversation-summary dd {
  margin: 6px 0 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 650;
}

.conversation-contact,
.conversation-transcript {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.conversation-contact h3,
.conversation-transcript h3 {
  margin: 0;
  font-size: 16px;
}

.conversation-contact .summary-list {
  margin-top: 14px;
}

.conversation-transcript {
  display: grid;
  gap: 12px;
}

.transcript-message {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-left: 3px solid var(--line-strong);
  background: var(--surface-soft);
}

.transcript-message.is-assistant {
  border-left-color: var(--green);
  background: var(--green-soft);
}

.transcript-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.transcript-meta strong {
  color: var(--ink);
  font-size: 12px;
}

.transcript-message p {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.transcript-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.transcript-sources a {
  color: var(--green-strong);
  font-size: 11px;
  text-underline-offset: 3px;
}

.action-dialog form {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
}

.icon-button {
  width: 40px;
  flex: 0 0 40px;
  padding: 0;
  font-size: 24px;
  font-weight: 400;
}

.dialog-summary {
  margin: 0;
  padding: 11px 12px;
  border-left: 3px solid var(--green);
  background: var(--green-soft);
  color: var(--body);
  font-size: 12px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

#editUserFields,
#quotaGrantFields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.action-dialog .field {
  min-width: 0;
}

.form-message {
  min-height: 18px;
  margin: -4px 0 0;
  color: var(--red);
  font-size: 12px;
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  max-width: min(390px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--ink);
  color: #ffffff;
  font-size: 12px;
  line-height: 1.55;
  box-shadow: 0 12px 36px rgba(23, 33, 28, 0.2);
}

@media (max-width: 980px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric:nth-child(n) {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .metric:nth-child(2n) {
    border-right: 0;
  }

  .metric:nth-last-child(-n + 2) {
    border-bottom: 0;
  }
}

@media (max-width: 800px) {
  .admin-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 4px 16px rgba(23, 33, 28, 0.04);
  }

  .sidebar-brand,
  .sidebar-account {
    display: none;
  }

  .section-nav {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .section-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
    grid-template-columns: auto auto;
    gap: 7px;
    padding: 0 13px;
    text-align: center;
  }

  .main-content {
    padding: 0 18px 56px;
  }

  .mobile-header {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
  }

  .mobile-header > div {
    min-width: 0;
    display: grid;
    gap: 3px;
  }

  .mobile-brand {
    color: var(--ink);
    font-size: 13px;
    font-weight: 700;
  }

  #mobileAdminEmail {
    max-width: 220px;
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-heading {
    min-height: auto;
    padding: 28px 0 20px;
  }

  .page-heading h1 {
    font-size: 24px;
  }

  .overview-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .main-content {
    padding-inline: 14px;
  }

  .page-heading {
    display: grid;
    gap: 16px;
  }

  .page-heading > .button {
    width: fit-content;
  }

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

  .metric {
    min-height: 116px;
    padding: 17px 14px;
  }

  .metric-value {
    margin-top: 13px;
    font-size: 21px;
  }

  .metric-note {
    line-height: 1.45;
  }

  .filter-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .filter-bar .field {
    width: 100%;
    min-width: 0;
    grid-column: 1 / -1;
  }

  .filter-bar .button {
    min-width: 88px;
  }

  .data-table {
    min-width: 820px;
  }

  .pagination {
    justify-content: center;
  }

  .action-dialog,
  .conversation-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

  .action-dialog form {
    padding: 19px;
  }

  .conversation-dialog-shell {
    padding: 18px;
  }

  .conversation-summary {
    grid-template-columns: 1fr;
  }

  #editUserFields,
  #quotaGrantFields {
    grid-template-columns: 1fr;
  }

  .dialog-actions .button {
    flex: 1;
  }

  .access-state {
    padding: 14px;
  }

  .access-panel {
    padding: 28px 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
