:root {
  color-scheme: light;
  --page: #f3f5f2;
  --surface: #ffffff;
  --surface-soft: #f7f8f6;
  --line: #dfe3dd;
  --line-strong: #c7cec5;
  --text: #20251f;
  --muted: #697168;
  --accent: #176b5b;
  --accent-dark: #105448;
  --accent-soft: #e7f3ef;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --warning: #8a5a13;
  --warning-soft: #fff5df;
  --shadow: 0 18px 48px rgba(29, 37, 31, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--page);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

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

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.admin-bootstrap,
.access-denied {
  display: grid;
  min-height: 100vh;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.admin-bootstrap {
  color: var(--muted);
}

.access-denied h1 {
  margin: 8px 0 0;
  font-size: 24px;
}

.access-denied p {
  max-width: 480px;
  margin: 0 0 8px;
  color: var(--muted);
}

.admin-brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.admin-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.admin-header-inner,
.admin-tabs-inner,
.admin-content {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
}

.admin-header-inner {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.admin-brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.admin-brand p,
.section-heading p,
.detail-header p {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.admin-brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.admin-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.admin-identity {
  display: grid;
  max-width: 220px;
  margin-right: 8px;
  text-align: right;
}

.admin-identity strong,
.admin-identity span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-identity span {
  color: var(--muted);
  font-size: 11px;
}

.button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.secondary-button {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.secondary-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.danger-text-button {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
}

.danger-text-button:hover:not(:disabled) {
  background: var(--danger-soft);
}

.admin-tabs {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.admin-tabs-inner {
  display: flex;
  gap: 24px;
}

.admin-tab {
  min-height: 46px;
  padding: 0 2px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 750;
}

.admin-tab.active {
  border-bottom-color: var(--accent);
  color: var(--accent-dark);
}

.overview-band {
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

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

.section-heading h2,
.detail-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.section-heading > span {
  color: var(--muted);
  font-size: 12px;
}

.compact-heading {
  margin-bottom: 12px;
}

.compact-heading h2 {
  font-size: 16px;
}

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

.metric-item {
  min-width: 0;
  min-height: 82px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.metric-item span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
}

.metric-item strong {
  display: block;
  overflow: hidden;
  font-size: 23px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-item.success {
  border-top: 3px solid var(--accent);
}

.metric-item.error {
  border-top: 3px solid var(--danger);
}

.admin-main {
  padding-top: 28px;
  padding-bottom: 48px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(210px, 1.7fr) 100px 120px minmax(150px, 1fr) 142px 142px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.user-filter-bar {
  grid-template-columns: minmax(240px, 520px) auto;
  justify-content: start;
}

.filter-field {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.filter-field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.filter-field input,
.filter-field select,
.pagination-bar select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
  background: #fff;
  color: var(--text);
}

.filter-field input:focus,
.filter-field select:focus,
.pagination-bar select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.12);
}

.filter-actions {
  display: flex;
  gap: 7px;
}

.table-shell {
  position: relative;
  min-height: 260px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

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

.admin-table th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.admin-table tbody tr {
  cursor: pointer;
}

.admin-table tbody tr:hover {
  background: #f9fbf9;
}

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

.jobs-table th:nth-child(1) { width: 76px; }
.jobs-table th:nth-child(2) { width: 190px; }
.jobs-table th:nth-child(3) { width: 94px; }
.jobs-table th:nth-child(4) { width: 160px; }
.jobs-table th:nth-child(6) { width: 72px; }
.jobs-table th:nth-child(7) { width: 160px; }
.jobs-table th:nth-child(8) { width: 72px; }

.users-table th:nth-child(1) { width: 280px; }
.users-table th:nth-child(n+2):nth-child(-n+6) { width: 86px; }
.users-table th:nth-child(7) { width: 170px; }
.users-table th:nth-child(8) { width: 104px; }

.record-thumb,
.record-thumb-placeholder {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 10px;
}

.record-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.table-primary,
.table-secondary,
.table-code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-primary {
  font-weight: 750;
}

.inline-primary {
  display: inline;
}

.mobile-label {
  display: none;
}

.table-secondary {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.table-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.prompt-preview {
  display: -webkit-box;
  overflow: hidden;
  color: #353b35;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.status-badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.done {
  border-color: #b9d8cd;
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.status-badge.error {
  border-color: #efc2bd;
  background: var(--danger-soft);
  color: var(--danger);
}

.status-badge.running {
  border-color: #e8cf98;
  background: var(--warning-soft);
  color: var(--warning);
}

.row-action {
  min-height: 30px;
  padding: 6px 9px;
  font-size: 12px;
}

.table-state {
  position: absolute;
  inset: 42px 0 0;
  display: grid;
  place-items: center;
  min-height: 216px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 56px;
  color: var(--muted);
  font-size: 12px;
}

.pagination-bar label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: auto;
}

.pagination-bar select {
  width: 70px;
  height: 34px;
}

.detail-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(24, 30, 25, 0.52);
  cursor: default;
}

.detail-panel {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
  width: min(680px, 100%);
  flex-direction: column;
  border-left: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.detail-header h2 {
  max-width: 540px;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.close-button {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.detail-content {
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
}

.detail-loading {
  display: grid;
  min-height: 240px;
  place-items: center;
  color: var(--muted);
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}

.detail-meta-item {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
}

.detail-meta-item span,
.detail-section > h3 {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.detail-meta-item strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.detail-section {
  margin-top: 20px;
}

.detail-copy,
.detail-json,
.detail-error {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.detail-json {
  max-height: 280px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.detail-error {
  border-color: #efc2bd;
  background: var(--danger-soft);
  color: var(--danger);
}

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

.detail-image-link {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
  aspect-ratio: 1;
}

.detail-image-link img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-preview {
  display: block;
  width: min(260px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
}

.reference-preview img {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: contain;
}

.admin-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 150;
  max-width: min(420px, calc(100% - 40px));
  padding: 11px 14px;
  border: 1px solid #efc2bd;
  border-radius: 6px;
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: var(--shadow);
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .filter-bar {
    grid-template-columns: minmax(230px, 2fr) 100px 120px minmax(150px, 1fr);
  }

  .filter-actions {
    align-self: end;
  }
}

@media (max-width: 820px) {
  .admin-header-inner,
  .admin-tabs-inner,
  .admin-content {
    width: min(100% - 24px, 1480px);
  }

  .admin-header-inner {
    align-items: flex-start;
    flex-direction: column;
    padding: 13px 0;
  }

  .admin-header-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .admin-identity {
    width: 100%;
    max-width: none;
    margin: 0 0 2px;
    text-align: left;
  }

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

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

  .search-field,
  .filter-actions {
    grid-column: 1 / -1;
  }

  .table-shell {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .admin-table,
  .admin-table tbody,
  .admin-table tr,
  .admin-table td {
    display: block;
    width: 100%;
  }

  .admin-table thead {
    display: none;
  }

  .admin-table tbody {
    display: grid;
    gap: 8px;
  }

  .admin-table tbody tr {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    gap: 6px 10px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
  }

  .admin-table td {
    padding: 0;
    border: 0;
  }

  .jobs-table td:nth-child(1) {
    grid-row: 1 / span 3;
  }

  .jobs-table td:nth-child(2),
  .jobs-table td:nth-child(5),
  .users-table td:nth-child(1) {
    grid-column: 2;
  }

  .jobs-table td:nth-child(3),
  .jobs-table td:nth-child(8),
  .users-table td:nth-child(8) {
    grid-column: 3;
  }

  .jobs-table td:nth-child(4),
  .jobs-table td:nth-child(6),
  .jobs-table td:nth-child(7) {
    grid-column: 2 / -1;
    color: var(--muted);
    font-size: 12px;
  }

  .users-table tbody tr {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .users-table td:nth-child(n+2):nth-child(-n+7) {
    grid-column: 1;
    color: var(--muted);
    font-size: 12px;
  }

  .mobile-label {
    display: inline;
    margin-right: 3px;
    color: var(--muted);
    font-weight: 650;
  }

  .record-thumb,
  .record-thumb-placeholder {
    width: 60px;
    height: 60px;
  }

  .table-state {
    inset: 0;
    min-height: 220px;
    border: 1px solid var(--line);
    border-radius: 6px;
  }

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

@media (max-width: 480px) {
  .admin-brand p,
  .admin-identity,
  .danger-text-button {
    display: none;
  }

  .admin-header-actions .button {
    flex: 1 1 auto;
  }

  .overview-band {
    padding: 18px 0;
  }

  .metric-item {
    min-height: 74px;
  }

  .filter-bar,
  .user-filter-bar {
    grid-template-columns: 1fr;
  }

  .search-field,
  .filter-actions {
    grid-column: auto;
  }

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

  .pagination-bar {
    flex-wrap: wrap;
  }

  .pagination-bar label {
    width: 100%;
  }

  .detail-meta-grid,
  .detail-image-grid {
    grid-template-columns: 1fr;
  }
}

.operations-panel { padding: 20px; border: 1px solid var(--line, #e5e6ee); border-radius: 12px; background: white; margin-bottom: 20px; }
.operations-panel .section-heading h2 { font-size: 16px; }
#operationsUpdated { font-size: 11px; color: #696a7d; }
.operations-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.operations-grid > div { display: grid; gap: 5px; }
.operations-grid span { color: #696a7d; font-size: 11px; }
.operations-grid strong { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
#operationsAlerts { padding: 10px 14px 10px 28px; border-radius: 8px; background: #fff8eb; color: #855917; font-size: 12px; margin-bottom: 0; }
.status-badge.partial { color: #855917; background: #fff8eb; }
@media(max-width: 600px) { .operations-panel { padding: 15px; } .operations-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; } }
