:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #eef2f5;
  --border: #d8dee6;
  --text: #1e2933;
  --muted: #667482;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --warning: #a15c07;
  --shadow: 0 10px 28px rgba(30, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary,
.panel-heading button,
#clearMaterialForm,
#clearAvatarForm,
#clearVoiceForm {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

button.secondary:hover,
.panel-heading button:hover,
#clearMaterialForm:hover,
#clearAvatarForm:hover,
#clearVoiceForm:hover {
  background: var(--surface-strong);
}

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

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

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

main {
  width: min(1440px, calc(100% - 32px));
  margin: 18px auto 40px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.captcha-button {
  min-height: 42px;
  border-color: var(--border);
  background: var(--surface-strong);
  padding: 0;
}

.captcha-button:hover {
  background: #e2e8f0;
}

.captcha-button img {
  display: block;
  width: 120px;
  height: 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.settings {
  display: grid;
  grid-template-columns: minmax(220px, 320px) auto auto auto;
  align-items: end;
  gap: 12px;
}

.admin-account {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  min-height: 84px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.material-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 16px;
  padding: 16px;
}

#digitalHumansPanel .material-layout {
  grid-template-columns: 1fr;
}

.tool-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

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

.checkbox-line {
  display: flex;
  width: auto;
  align-items: center;
  gap: 8px;
  align-self: end;
  min-height: 38px;
  color: var(--text);
}

.checkbox-line input {
  width: auto;
}

.inline-options,
.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.inline-options label {
  display: flex;
  width: auto;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.inline-options input {
  width: auto;
}

.production-badge {
  display: inline-flex;
  width: fit-content;
  margin: 0;
  border-radius: 4px;
  padding: 5px 9px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 12px;
  font-weight: 700;
}

.switch-label {
  display: flex;
  width: auto;
  align-items: center;
  gap: 8px;
}

.switch-label input {
  width: auto;
}

.access-control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  padding: 16px;
}

.whitelist-toolbar {
  grid-template-columns: minmax(220px, 1fr) 160px auto;
  padding-top: 16px;
}

.user-heading {
  margin-top: 24px;
  border-top: 1px solid var(--border);
}

@media (max-width: 760px) {
  .access-control-grid {
    grid-template-columns: 1fr;
  }

  .whitelist-toolbar {
    grid-template-columns: 1fr;
  }

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }
}

.list-toolbar {
  display: grid;
  grid-template-columns: 160px 160px minmax(220px, 1fr) auto;
  align-items: end;
  gap: 12px;
  padding: 0 16px 16px;
}

.sub-heading {
  margin-top: 24px;
  border-top: 1px solid var(--border);
}

.tag-admin-layout {
  align-items: start;
}

.tag-list-panel {
  padding: 0;
}

.tag-checkbox-list {
  display: flex;
  min-height: 38px;
  max-height: 132px;
  align-items: flex-start;
  gap: 8px;
  overflow-y: auto;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  padding: 8px;
}

.tag-checkbox-item {
  display: inline-flex;
  width: auto;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--text);
  cursor: pointer;
}

.tag-checkbox-item input {
  width: auto;
}

.tag-checkbox-item:has(input:checked) {
  border-color: var(--accent);
  background: #e6fffb;
  color: var(--accent-dark);
}

.inline-toolbar {
  grid-template-columns: minmax(160px, 1fr) minmax(140px, 1fr) auto;
  padding: 16px;
}

.nested-table-wrap {
  border-top: 1px solid var(--border);
}

.prompt-fragment {
  max-width: 420px;
  color: var(--muted);
  white-space: normal;
}

#usersPanel .list-toolbar {
  grid-template-columns: minmax(220px, 1fr) 160px auto;
  padding-top: 16px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--border);
}

.pagination {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

.pagination .muted {
  margin-top: 0;
}

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

.split-table-wrap {
  display: grid;
  grid-template-columns: repeat(2, minmax(420px, 1fr));
  gap: 16px;
  padding: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.split-table-wrap table {
  min-width: 0;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

td .row-actions,
td .quota-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quota-actions input {
  width: 96px;
}

.url-cell {
  max-width: 280px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-thumb {
  display: inline-grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--muted);
  object-fit: cover;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  min-width: 50px;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: #e6f4f1;
  color: var(--accent-dark);
  font-size: 12px;
}

.pill.off {
  background: #f3f4f6;
  color: var(--muted);
}

.status-line {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100% - 40px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #172026;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.toast.error {
  background: var(--danger);
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .settings,
  .material-layout,
  .form-grid,
  .form-grid.compact,
  .list-toolbar,
  .split-table-wrap,
  #usersPanel .list-toolbar,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  main {
    width: min(100% - 20px, 1440px);
  }
}
