:root {
  --bg: #0c141f;
  --card: rgba(13, 25, 38, 0.72);
  --card-border: rgba(142, 181, 221, 0.22);
  --text: #e7f1fd;
  --muted: #a8bfd8;
  --brand: #2cc7aa;
  --brand-hover: #1db397;
  --danger: #e16068;
  --danger-hover: #c94c53;
  --border: rgba(165, 197, 230, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  background: radial-gradient(circle at 15% 20%, #163252 0%, #0c141f 45%, #070c14 100%);
  color: var(--text);
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(50px);
  opacity: 0.25;
  pointer-events: none;
  z-index: -1;
}
.bg-orb-a {
  width: 400px;
  height: 400px;
  background: #2cc7aa;
  top: -150px;
  right: -100px;
}
.bg-orb-b {
  width: 500px;
  height: 500px;
  background: #1d79d1;
  left: -200px;
  bottom: -200px;
}

.shell {
  width: min(1480px, calc(100% - 32px));
  max-width: none;
  margin: 40px auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  padding: 24px;
}

.header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kicker {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
}
h1 {
  margin: 0;
  font-size: 28px;
}
h2 {
  margin: 0 0 16px;
  font-size: 18px;
}
.muted {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: rgba(44, 199, 170, 0.15);
  color: var(--brand);
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 24px;
}

.tab-pane.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Forms */
.add-form, .config-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.config-category-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.config-cat-btn {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.08);
  color: #cce0f5;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.config-cat-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.config-cat-btn.active {
  background: rgba(44, 199, 170, 0.16);
  color: #6ff2d7;
  border-color: rgba(77, 226, 196, 0.4);
}

.config-cat-pane {
  display: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.02);
  gap: 12px;
  flex-direction: column;
}

.config-cat-pane.active {
  display: flex;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.config-inline-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
}

.config-inline-row .inline-item {
  min-width: 0;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: #cce0f5;
}

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

.input-text {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
}

.input-text:focus {
  outline: none;
  border-color: var(--brand);
}

textarea#tokenInput {
  width: 100%;
  height: 80px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  resize: vertical;
}

textarea#refreshBundleInput {
  width: 100%;
  min-height: 140px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  resize: vertical;
}

#refreshBundleFile {
  color: var(--muted);
}

.refresh-status {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: #a8bfd8;
  font-size: 12px;
  line-height: 1.5;
}

.refresh-status .table-wrapper {
  margin-top: 6px;
}

.refresh-profiles-table {
  font-size: 12px;
}

.refresh-profiles-table th,
.refresh-profiles-table td {
  padding: 8px;
}

.dialog-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 16, 0.82);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 950;
  padding: 20px;
}

.dialog-modal.open {
  display: flex;
}

.dialog-card {
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: #0d1926;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
}

.personal-video-entry {
  border: 1px solid rgba(99, 212, 255, 0.36);
  color: #a7e8ff;
}

.personal-video-dialog {
  width: min(900px, 100%);
  border-color: rgba(99, 212, 255, 0.28);
  background:
    linear-gradient(145deg, rgba(17, 37, 56, 0.98), rgba(9, 22, 35, 0.99));
}

.dialog-eyebrow {
  margin: 0 0 4px;
  color: #63d4ff;
  font: 600 10px/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.16em;
}

.personal-video-notice {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  margin: 4px 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(99, 212, 255, 0.22);
  border-left: 3px solid #63d4ff;
  border-radius: 8px;
  background: rgba(48, 170, 255, 0.07);
  color: #9eb7cf;
  font-size: 12px;
  line-height: 1.55;
}

.personal-video-notice strong {
  color: #cfefff;
  white-space: nowrap;
}

#personalVideoAccountInput {
  width: 100%;
  min-height: 116px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  resize: vertical;
}

#personalVideoAccountInput:focus {
  outline: none;
  border-color: #63d4ff;
}

.format-guide {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
  font-size: 12px;
}

.format-guide summary {
  cursor: pointer;
  color: #a8bfd8;
  font-weight: 700;
}

.format-guide code {
  display: block;
  margin-top: 9px;
  padding: 8px 10px;
  overflow-x: auto;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: #76e8d1;
  white-space: nowrap;
}

.personal-video-submit-row {
  min-height: 40px;
}

.personal-video-progress {
  margin-top: 6px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
}

.personal-video-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.personal-video-progress-head strong {
  display: block;
  margin-top: 3px;
  color: #e3f3ff;
}

.progress-track {
  height: 7px;
  margin: 12px 0 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2cc7aa, #63d4ff);
  transition: width 0.3s ease;
}

.personal-video-results-wrap {
  max-height: 310px;
  overflow: auto;
}

.personal-video-results-table {
  min-width: 700px;
  font-size: 12px;
}

.personal-video-results-table th,
.personal-video-results-table td {
  padding: 9px 10px;
}

.personal-video-results-table td:last-child {
  max-width: 310px;
  color: #9eb7cf;
  overflow-wrap: anywhere;
}

@media (max-width: 680px) {
  .personal-video-notice {
    grid-template-columns: 1fr;
  }
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* Actions */
.actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

button {
  background: var(--brand);
  color: #051410;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
button:hover {
  background: var(--brand-hover);
}

button.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}
button.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 6px 12px;
  font-size: 12px;
}
button.danger:hover {
  background: var(--danger);
  color: #fff;
}

button.small {
  padding: 6px 12px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}
button.small:hover {
  background: rgba(255, 255, 255, 0.2);
}

.msg {
  font-size: 14px;
}

/* Table */
.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.list-head h2 {
  margin: 0;
}

.token-list-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.token-list-actions .actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.token-credits-summary {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.token-credits-summary strong {
  color: #e7f1fd;
  font-size: 15px;
}

.input-select {
  min-width: 120px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.input-select:focus {
  outline: none;
  border-color: var(--brand);
}

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

.stat-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.stat-value {
  color: #e7f1fd;
  font-size: 24px;
  line-height: 1.1;
  font-weight: 700;
}

.table-wrapper {
  overflow-x: auto;
}

.token-table-wrapper {
  overflow-x: visible;
}

.token-summary {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: -6px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.token-summary strong {
  color: #e7f1fd;
  font-size: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

#logsTable,
#runningLogsTable {
  table-layout: fixed;
}

#logsTable {
  min-width: 1430px;
}

.log-col-time { width: 98px; }
.log-col-request { width: 150px; }
.log-col-status { width: 106px; }
.log-col-duration { width: 74px; }
.log-col-progress { width: 70px; }
.log-col-account { width: 190px; }
.log-col-retry { width: 108px; }
.log-col-model { width: 150px; }
.log-col-spec { width: 142px; }
.log-col-prompt { width: auto; }
.log-col-preview { width: 76px; }

#logsTable td,
#runningLogsTable td {
  padding: 10px 10px;
  vertical-align: middle;
}

#logsTable tbody tr:not(.log-attempt-detail-row) {
  height: 88px;
}

#logsTable tbody tr:not(.log-attempt-detail-row) > td {
  height: 88px;
  overflow: hidden;
}

#logsTable th {
  white-space: nowrap;
  padding: 12px 10px;
}

.log-account-cell {
  display: block;
  width: 100%;
  overflow: hidden;
  color: #a8bfd8;
  line-height: 1.35;
}

.log-time-cell {
  color: #a8bfd8;
  line-height: 1.2;
  white-space: nowrap;
}

.log-time-cell .date {
  display: block;
}

.log-time-cell .time {
  display: block;
  color: #7f96ad;
}

.log-request-cell {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
}

.log-request-cell button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: #8fb5d8;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.log-request-cell button:hover {
  color: #5eead4;
}

.log-account-email {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #7f96ad;
}

.log-retry-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  color: #7f96ad;
  font-size: 11px;
}

.log-attempts-btn {
  border: 1px solid rgba(99, 212, 255, 0.35);
  background: rgba(48, 170, 255, 0.1);
  color: #8edcff;
  padding: 4px 7px;
  font-size: 11px;
}

.log-attempts-btn:hover {
  background: rgba(48, 170, 255, 0.2);
}

.log-attempt-detail-row {
  height: auto;
  background: rgba(9, 24, 39, 0.72);
}

#logsTable tbody .log-attempt-detail-row > td {
  height: auto;
  padding: 0 10px 14px;
  overflow: visible;
}

.log-attempt-detail {
  padding: 12px 14px;
  border-left: 3px solid rgba(99, 212, 255, 0.45);
  background: rgba(48, 170, 255, 0.05);
}

.log-attempt-detail table {
  min-width: 760px;
  table-layout: fixed;
  font-size: 12px;
}

.log-attempt-detail th,
.log-attempt-detail td {
  height: auto;
  padding: 7px 9px;
  overflow: visible;
  vertical-align: top;
}

.log-attempt-result-ok { color: #4de2c4; }
.log-attempt-result-retry { color: #ffca58; }
.log-attempt-result-failed { color: #ffb4bc; }
.log-attempt-error {
  color: #8fa7bf;
  overflow-wrap: anywhere;
}

.log-model-cell {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.35;
  color: #8fb0d3;
  overflow-wrap: anywhere;
}

.log-spec-cell {
  min-width: 112px;
  line-height: 1.35;
  white-space: nowrap;
  color: #dbe9f7;
}

.log-spec-cell strong {
  color: #65e6cd;
}

.log-spec-cell small {
  display: block;
  margin-top: 3px;
  color: #8fa7bf;
  font-size: 11px;
}

.log-prompt-cell {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: #a8bfd8;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

th {
  text-align: left;
  padding: 12px;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-weight: 600;
}

td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.token-val {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: #a0c3e8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#tokenTable {
  width: 100%;
  table-layout: fixed;
  font-size: 13px;
}

#tokenTable th {
  padding: 11px 8px;
  white-space: nowrap;
}

#tokenTable td {
  padding: 13px 8px;
  min-width: 0;
}

.token-col-select { width: 3.5%; }
.token-col-account { width: 20%; }
.token-col-secret { width: 11%; }
.token-col-status { width: 8%; }
.token-col-refresh { width: 9%; }
.token-col-quota { width: 17%; }
.token-col-video { width: 14%; }
.token-col-actions { width: 17.5%; }

.token-select-head,
.token-select-cell {
  text-align: center;
}

.token-account-cell {
  color: #a8bfd8;
  font-size: 12px;
  min-width: 0;
}

.token-account-name,
.token-account-email {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.token-account-name {
  color: #dbe9f8;
  font-weight: 700;
  margin-bottom: 4px;
}

.token-account-email {
  color: #8fa7bf;
}

.token-status-cell .status-badge {
  display: table;
}

.token-fail-count {
  display: block;
  margin-top: 7px;
  color: #7f96ad;
  font-size: 11px;
  white-space: nowrap;
}

.token-fail-count.has-fails {
  color: #ffb4bc;
  font-weight: 700;
}

.token-credit-block,
.token-expiry-block {
  font-size: 11px;
  line-height: 1.4;
}

.token-expiry-block {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed rgba(165, 197, 230, 0.16);
}

.token-meta-label {
  display: inline-block;
  margin-right: 5px;
  color: #63d4ff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.status-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-active { background: rgba(44, 199, 170, 0.2); color: #4de2c4; }
.status-exhausted { background: rgba(225, 163, 44, 0.2); color: #ffca58; }
.status-invalid { background: rgba(225, 96, 104, 0.2); color: #ffb4bc; }
.status-error { background: rgba(225, 96, 104, 0.2); color: #ffb4bc; }
.status-disabled { background: rgba(255, 255, 255, 0.1); color: #aaa; }

.log-status-2xx { background: rgba(44, 199, 170, 0.2); color: #4de2c4; }
.log-status-4xx { background: rgba(225, 163, 44, 0.2); color: #ffca58; }
.log-status-5xx { background: rgba(225, 96, 104, 0.2); color: #ffb4bc; }

.log-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.log-state.running {
  color: #63d4ff;
  background: rgba(48, 170, 255, 0.16);
}

.log-state.success {
  color: #4de2c4;
  background: rgba(44, 199, 170, 0.16);
}

.log-state.failed {
  color: #ffb4bc;
  background: rgba(225, 96, 104, 0.16);
}

.log-state-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.log-state-btn.failed {
  border: 1px solid rgba(255, 180, 188, 0.55);
  background: rgba(255, 180, 188, 0.12);
}

.log-state-btn.failed:hover {
  background: rgba(255, 180, 188, 0.22);
}

.icon-spinner {
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.icon-check,
.icon-error {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
  font-size: 11px;
  line-height: 1;
}

.log-row-running {
  background: rgba(48, 170, 255, 0.06);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.action-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-width: 0;
}

.video-batch-btn {
  border: 1px solid rgba(99, 212, 255, 0.38);
  color: #a7e8ff;
}

.video-access-cell {
  min-width: 0;
}

.video-access-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

.video-access-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.video-access-actions .action-mini {
  min-width: 64px;
  padding: 5px 7px;
  font-size: 11px;
}

.video-status-ready {
  color: #4de2c4;
  background: rgba(44, 199, 170, 0.18);
}

.video-status-login {
  color: #ffca58;
  background: rgba(225, 163, 44, 0.16);
}

.video-status-off {
  color: #8fa7bf;
  background: rgba(143, 167, 191, 0.12);
}

/* Account-scoped generation console */
.generation-console-card {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(15, 30, 46, 0.94), rgba(8, 20, 32, 0.97)),
    var(--card);
}

.generation-console-card::after {
  position: absolute;
  width: 360px;
  height: 360px;
  right: -170px;
  bottom: -210px;
  border: 1px solid rgba(99, 212, 255, 0.16);
  border-radius: 50%;
  box-shadow:
    0 0 0 42px rgba(99, 212, 255, 0.025),
    0 0 0 84px rgba(44, 199, 170, 0.018);
  content: "";
  pointer-events: none;
}

.generation-console-head {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 22px;
}

.generation-console-head h2 {
  margin: 7px 0 6px;
  font-size: 22px;
}

.generation-console-kicker {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #63d4ff;
  font: 700 10px/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.16em;
}

.generation-console-kicker span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4de2c4;
  box-shadow: 0 0 12px rgba(77, 226, 196, 0.75);
}

.generation-console-state {
  min-width: 88px;
  padding: 8px 12px;
  border: 1px solid rgba(143, 167, 191, 0.25);
  border-radius: 999px;
  color: #8fa7bf;
  background: rgba(0, 0, 0, 0.22);
  text-align: center;
  font: 700 11px/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.1em;
}

.generation-console-state.running {
  border-color: rgba(99, 212, 255, 0.45);
  color: #63d4ff;
  box-shadow: inset 0 0 16px rgba(48, 170, 255, 0.08);
}

.generation-console-state.completed {
  border-color: rgba(77, 226, 196, 0.45);
  color: #4de2c4;
}

.generation-console-state.failed {
  border-color: rgba(255, 180, 188, 0.45);
  color: #ffb4bc;
}

.generation-console-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(380px, 1.05fr);
  gap: 22px;
}

.generation-test-form,
.generation-result-panel {
  border: 1px solid rgba(165, 197, 230, 0.16);
  border-radius: 14px;
  background: rgba(5, 14, 24, 0.48);
}

.generation-test-form {
  padding: 18px;
}

.generation-kind-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
  padding: 5px;
  border: 1px solid rgba(165, 197, 230, 0.13);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
}

.generation-kind-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #8fa7bf;
  text-align: left;
}

.generation-kind-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}

.generation-kind-btn.active {
  border-color: rgba(77, 226, 196, 0.32);
  background: linear-gradient(135deg, rgba(44, 199, 170, 0.18), rgba(48, 170, 255, 0.08));
  color: #e7f1fd;
}

.generation-kind-btn strong,
.generation-kind-btn small {
  display: block;
}

.generation-kind-btn strong {
  margin-bottom: 2px;
  font-size: 13px;
}

.generation-kind-btn small {
  color: #7f96ad;
  font-size: 10px;
}

.generation-kind-index {
  color: #63d4ff;
  font: 600 11px/1 "IBM Plex Mono", monospace;
}

.generation-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 15px;
}

.generation-select {
  width: 100%;
  min-width: 0;
  height: 40px;
}

.generation-field-meta {
  min-height: 30px;
  margin: 0;
  color: #7f96ad;
  font-size: 10px;
  line-height: 1.45;
}

.generation-prompt {
  width: 100%;
  min-height: 126px;
  border: 1px solid rgba(165, 197, 230, 0.18);
  border-radius: 10px;
  padding: 12px 13px;
  resize: vertical;
  background: rgba(0, 0, 0, 0.32);
  color: #dbe9f8;
  font: 500 12px/1.6 "IBM Plex Mono", monospace;
}

.generation-prompt:focus {
  outline: none;
  border-color: rgba(99, 212, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(48, 170, 255, 0.08);
}

.generation-audio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 13px;
  padding: 10px 12px;
  border: 1px solid rgba(165, 197, 230, 0.13);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
}

.generation-reference-panel {
  margin-top: 13px;
  padding: 12px;
  border: 1px solid rgba(99, 212, 255, 0.18);
  border-radius: 10px;
  background: rgba(48, 170, 255, 0.045);
}

.generation-reference-panel[hidden],
.generation-reference-files[hidden] {
  display: none;
}

.generation-reference-files {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.generation-reference-files label {
  display: grid;
  gap: 6px;
  color: #a9bfd4;
  font-size: 10px;
}

.generation-reference-files input[type="file"] {
  min-width: 0;
  padding: 8px;
  border: 1px dashed rgba(165, 197, 230, 0.24);
  border-radius: 8px;
  color: #8fa7bf;
  background: rgba(0, 0, 0, 0.22);
  font-size: 10px;
}

.generation-audio-row[hidden] {
  display: none;
}

.generation-audio-row strong,
.generation-audio-row small {
  display: block;
}

.generation-audio-row strong {
  color: #cfe0f2;
  font-size: 12px;
}

.generation-audio-row small {
  margin-top: 2px;
  color: #7f96ad;
  font-size: 10px;
}

.generation-submit-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(165, 197, 230, 0.13);
}

.generation-cost-badge {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  color: #4de2c4;
  background: rgba(44, 199, 170, 0.13);
  font-size: 10px;
  font-weight: 800;
}

.generation-submit-note {
  margin: 7px 0 0;
  color: #7f96ad;
  font-size: 10px;
}

.generation-run-btn {
  min-width: 136px;
  padding: 11px 18px;
  box-shadow: 0 8px 22px rgba(44, 199, 170, 0.18);
}

.generation-run-btn:disabled {
  cursor: wait;
  opacity: 0.55;
}

.generation-result-panel {
  display: flex;
  flex-direction: column;
  min-height: 470px;
  padding: 14px;
}

.generation-result-toolbar {
  display: flex;
  justify-content: space-between;
  color: #7f96ad;
  font: 600 10px/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.12em;
}

.generation-result-progress {
  height: 3px;
  margin: 11px 0 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.generation-result-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #2cc7aa, #63d4ff);
  transition: width 0.35s ease;
}

.generation-result-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 370px;
  padding: 26px;
  border: 1px dashed rgba(165, 197, 230, 0.16);
  border-radius: 10px;
  color: #7f96ad;
  text-align: center;
}

.generation-result-empty strong {
  margin: 9px 0 5px;
  color: #a8bfd8;
  font-size: 13px;
}

.generation-result-empty span {
  max-width: 330px;
  font-size: 11px;
  line-height: 1.55;
}

.generation-result-mark {
  color: #63d4ff;
  font: 500 34px/1 "IBM Plex Mono", monospace;
}

.generation-result-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
}

.generation-result-media {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 310px;
  overflow: hidden;
  border: 1px solid rgba(165, 197, 230, 0.13);
  border-radius: 10px;
  background:
    linear-gradient(45deg, rgba(255,255,255,.018) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.018) 75%),
    #07111d;
  background-size: 18px 18px;
}

.generation-result-media img,
.generation-result-media video {
  display: block;
  width: 100%;
  max-height: 430px;
  object-fit: contain;
}

.generation-result-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.generation-result-meta div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(165, 197, 230, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.generation-result-meta small,
.generation-result-meta strong {
  display: block;
}

.generation-result-meta small {
  margin-bottom: 4px;
  color: #7f96ad;
  font-size: 9px;
  letter-spacing: 0.06em;
}

.generation-result-meta strong {
  overflow: hidden;
  color: #cfe0f2;
  font: 600 10px/1.45 "IBM Plex Mono", monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.generation-result-error {
  padding: 14px;
  border: 1px solid rgba(255, 180, 188, 0.32);
  border-radius: 9px;
  background: rgba(225, 96, 104, 0.08);
  color: #ffb4bc;
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

th input[type="checkbox"],
td input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.action-btns button {
  width: 100%;
  padding: 3px 5px;
  font-size: 10px;
  border-radius: 4px;
}

.switch-btn {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  background: #2b3948;
  vertical-align: middle;
}

.switch-btn.on {
  background: rgba(44, 199, 170, 0.35);
  border-color: rgba(77, 226, 196, 0.55);
}

.switch-btn.off {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
}

.switch-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.switch-knob {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transform: translateX(0);
  transition: transform 0.15s ease;
}

.switch-btn.on .switch-knob {
  transform: translateX(18px);
}

.switch-text {
  margin-left: 8px;
  font-size: 12px;
  color: #a8bfd8;
}

.empty-state {
  text-align: center;
  padding: 40px !important;
  color: var(--muted);
}

.logs-pagination {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.logs-filter-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 0.72fr)) minmax(240px, 1.5fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid rgba(165, 197, 230, 0.14);
  border-radius: 12px;
  background: rgba(5, 18, 31, 0.42);
}

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

.logs-filter-field > span {
  color: #8fa8c2;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.logs-filter-field .input-select,
.logs-filter-field .input-text {
  width: 100%;
  min-width: 0;
  height: 40px;
}

.logs-filter-search .input-text {
  padding-right: 12px;
}

.logs-filter-reset {
  height: 40px;
  white-space: nowrap;
}

.preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 16, 0.86);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.preview-modal.open {
  display: flex;
}

.preview-modal-dialog {
  width: min(1100px, 100%);
  max-height: calc(100vh - 40px);
  background: #0d1926;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-close {
  align-self: flex-end;
  padding: 6px 12px;
  font-size: 12px;
}

.preview-content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  max-height: calc(100vh - 130px);
}

.preview-content img,
.preview-content video {
  max-width: 100%;
  max-height: calc(100vh - 150px);
  border-radius: 8px;
  background: #08111c;
}

.preview-actions {
  display: flex;
  justify-content: flex-end;
}

.preview-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 80px;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
}

.preview-download:hover {
  background: rgba(255, 255, 255, 0.2);
}

.error-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.error-detail-head h3 {
  margin: 0;
  font-size: 16px;
  color: #e9f4ff;
}

.error-detail-content {
  border: 1px solid rgba(142, 181, 221, 0.25);
  border-radius: 8px;
  background: #091321;
  padding: 12px;
  max-height: calc(100vh - 220px);
  overflow: auto;
}

.error-detail-content pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cfe3f8;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(12, 20, 31, 0.92);
  color: #dbe9f8;
  border: 1px solid rgba(142, 181, 221, 0.28);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35);
  font-size: 13px;
  line-height: 1.4;
  z-index: 1200;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: rgba(77, 226, 196, 0.45);
}

.toast.error {
  border-color: rgba(255, 180, 188, 0.45);
}

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

  .list-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .list-head .actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 10px;
  }

  .token-list-actions {
    width: 100%;
    align-items: flex-start;
  }

  .token-credits-summary {
    text-align: left;
  }

  .token-list-actions .actions {
    justify-content: flex-start;
  }
}

@media (max-width: 1100px) and (min-width: 821px) {
  .token-col-secret,
  #tokenTable th:nth-child(3),
  #tokenTable .token-secret-cell {
    display: none;
  }

  .token-col-account { width: 23%; }
  .token-col-status { width: 9%; }
  .token-col-refresh { width: 10%; }
  .token-col-quota { width: 18%; }
  .token-col-video { width: 17%; }
  .token-col-actions { width: 19.5%; }
}

@media (max-width: 1100px) {
  .logs-filter-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .logs-filter-search {
    grid-column: 1 / 3;
  }

  .generation-console-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .generation-result-panel {
    min-height: 420px;
  }
}

@media (max-width: 820px) {
  .logs-filter-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .logs-filter-search {
    grid-column: 1 / -1;
  }

  .shell {
    width: min(100% - 20px, 720px);
    margin: 18px auto;
  }

  .card {
    padding: 16px;
    border-radius: 12px;
  }

  .token-table-wrapper {
    overflow: visible;
  }

  #tokenTable,
  #tokenTable tbody {
    display: block;
    width: 100%;
  }

  #tokenTable colgroup,
  #tokenTable thead {
    display: none;
  }

  #tokenTable tbody {
    display: grid;
    gap: 12px;
  }

  #tokenTable tbody tr {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 16px;
    padding: 16px;
    border: 1px solid rgba(165, 197, 230, 0.16);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.025);
  }

  #tokenTable td {
    display: block;
    padding: 0;
    border: 0;
    min-width: 0;
  }

  #tokenTable td:not(.token-select-cell):not(.empty-state)::before {
    display: block;
    margin-bottom: 6px;
    color: #7f96ad;
    content: attr(data-label);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.04em;
  }

  #tokenTable .token-select-cell {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1;
  }

  #tokenTable .token-account-cell {
    grid-column: 1 / -1;
    padding-right: 34px;
  }

  #tokenTable .token-account-name,
  #tokenTable .token-account-email,
  #tokenTable .token-val {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  #tokenTable .video-access-cell,
  #tokenTable .token-operations-cell {
    align-self: end;
  }

  #tokenTable .empty-state {
    grid-column: 1 / -1;
    padding: 24px 8px;
  }

  .action-btns {
    max-width: 260px;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .generation-console-head {
    align-items: flex-start;
  }

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

@media (max-width: 560px) {
  .logs-filter-bar {
    grid-template-columns: minmax(0, 1fr);
  }

  .logs-filter-search {
    grid-column: 1;
  }

  .logs-filter-reset {
    width: 100%;
  }

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

  .config-category-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

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

  .input-select {
    width: 100%;
  }

  #tokenTable tbody tr {
    grid-template-columns: minmax(0, 1fr);
  }

  #tokenTable .token-account-cell,
  #tokenTable .empty-state {
    grid-column: 1;
  }

  .action-btns {
    max-width: none;
  }

  .generation-console-head,
  .generation-submit-row {
    align-items: stretch;
    flex-direction: column;
  }

  .generation-console-state {
    align-self: flex-start;
  }

  .generation-kind-switch,
  .generation-result-meta {
    grid-template-columns: minmax(0, 1fr);
  }

  .generation-run-btn {
    width: 100%;
  }

  .generation-result-panel {
    min-height: 360px;
  }
}
