:root {
  color-scheme: light;
  --bg: #f1f4f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #d8e0ea;
  --text: #17202a;
  --muted: #657386;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
  --shadow: 0 10px 28px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button,
.file-button {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 8px 12px;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

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

textarea {
  resize: vertical;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
}

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

.hidden {
  display: none !important;
}

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

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

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 26px;
}

.shell {
  width: min(1360px, calc(100% - 32px));
  margin: 22px auto 40px;
}

.topbar,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 16px;
}

.topbar p,
small,
.error-text,
#submitState,
#configState {
  color: var(--muted);
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(7, minmax(118px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stats article {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

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

.stats strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

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

.tabs button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.tab-panel {
  display: none;
  padding: 18px;
  overflow-x: auto;
}

.tab-panel.active {
  display: block;
}

.panel {
  padding: 18px;
}

.narrow {
  width: min(560px, 100%);
}

.runtime-panel {
  margin-top: 16px;
}

.update-panel {
  margin-top: 16px;
}

#versionState {
  margin: 4px 0 0;
  color: var(--muted);
}

#updateOutput {
  min-height: 92px;
  max-height: 260px;
  overflow: auto;
  margin: 14px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  white-space: pre-wrap;
}

form {
  display: grid;
  gap: 16px;
}

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

.form-grid.two {
  grid-template-columns: repeat(2, minmax(160px, 1fr));
}

.form-grid.four {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.full {
  grid-column: 1 / -1;
}

.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.inline input,
.toggles input,
.file-button input {
  width: auto;
}

.file-button {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 750;
}

.primary:hover {
  background: var(--accent-strong);
}

.task-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

#taskForm .form-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 500;
}

.table {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.table-head,
.table-row {
  display: grid;
  gap: 12px;
  align-items: center;
}

.table-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 12px;
}

.table-row {
  min-height: 58px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px 12px;
}

.accounts-head,
.accounts-row {
  grid-template-columns: minmax(170px, 1.2fr) 78px 72px minmax(110px, 0.8fr) minmax(150px, 1fr) minmax(130px, 0.9fr) minmax(160px, 1fr) 210px;
}

.tasks-head,
.tasks-row {
  grid-template-columns: minmax(190px, 1.2fr) minmax(110px, 0.7fr) 96px 72px minmax(180px, 1fr) 150px;
}

.logs-head,
.logs-row {
  grid-template-columns: 170px minmax(120px, 0.8fr) 130px 100px 84px minmax(220px, 1fr) 70px;
}

.proxies-head,
.proxies-row {
  grid-template-columns: minmax(220px, 1.3fr) 90px 84px 100px 150px minmax(260px, auto);
}

.table-row strong,
.table-row small,
.table-row span,
.table-row a {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-row div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.compact-input input {
  width: 76px;
}

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

.proxy-cell,
.credit-cell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.quota-input {
  gap: 4px;
}

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

.badge {
  display: inline-flex;
  justify-content: center;
  width: fit-content;
  min-width: 76px;
  border-radius: 999px;
  padding: 5px 10px;
  background: #e6edf3;
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
}

.badge.completed {
  background: #dff7ea;
  color: var(--ok);
}

.badge.failed {
  background: #fde7e4;
  color: var(--danger);
}

.badge.generating,
.badge.queuing,
.badge.submitting {
  background: #fff2d9;
  color: var(--warn);
}

.empty {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.error-text {
  min-height: 18px;
  color: var(--danger);
}

dialog {
  width: min(760px, calc(100% - 32px));
  padding: 0;
}

dialog.wide-dialog {
  width: min(980px, calc(100% - 32px));
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.32);
}

.dialog-form {
  padding: 18px;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.detail-summary div {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px 12px;
  min-width: 0;
}

.detail-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-summary strong {
  display: block;
  margin-top: 4px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.log-detail {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  white-space: pre-wrap;
}

@media (max-width: 980px) {
  .topbar,
  .task-layout {
    grid-template-columns: 1fr;
    display: grid;
  }

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

  .table-head {
    display: none;
  }

  .accounts-row,
  .tasks-row,
  .logs-row,
  .proxies-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 20px, 1360px);
  }

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

  .tabs {
    overflow-x: auto;
  }
}
