:root {
  color-scheme: light;
  --background: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --text: #17191c;
  --muted: #626871;
  --border: #d9dde3;
  --primary: #225ee6;
  --primary-hover: #174bbd;
  --success: #198754;
  --warning: #b86800;
  --danger: #c53b35;
  --focus: #8fb3ff;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--background);
  color: var(--text);
  font-size: 14px;
}

button, input, select, textarea { font: inherit; }
button, select { min-height: 36px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
}

.brand, .header-status, .section-heading, .video-heading {
  display: flex;
  align-items: center;
}

.brand { gap: 12px; }
.brand h1 { margin: 0; font-size: 20px; line-height: 1.2; letter-spacing: 0; }

.environment {
  padding: 3px 7px;
  border: 1px solid #e1b767;
  border-radius: 4px;
  background: #fff7e7;
  color: #704400;
  font-size: 12px;
  font-weight: 650;
}

.header-status { gap: 16px; color: var(--muted); }
.header-status span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a6abb3;
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }

main { max-width: 1440px; margin: 0 auto; }
section { padding: 24px 28px; border-bottom: 1px solid var(--border); }

.section-heading { justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h2 { margin: 0 0 4px; font-size: 17px; letter-spacing: 0; }
.muted { margin: 0; color: var(--muted); font-size: 12px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.metrics article {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.metrics span { display: block; color: var(--muted); font-size: 12px; }
.metrics strong { display: block; margin-top: 8px; font-size: 25px; line-height: 1; }

.create-section { background: var(--surface); }
.create-form { display: grid; gap: 12px; }
label span { display: block; margin-bottom: 6px; color: #444a52; font-size: 12px; font-weight: 650; }
textarea, input, select {
  width: 100%;
  border: 1px solid #bcc2cb;
  border-radius: 4px;
  background: #fff;
  color: var(--text);
}
textarea, input { padding: 9px 10px; }
textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
select { padding: 6px 30px 6px 9px; }
textarea:focus, input:focus, select:focus, button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 170px)) minmax(120px, 1fr);
  gap: 12px;
  align-items: end;
}
.form-grid .button { justify-self: end; min-width: 130px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 7px 13px;
  cursor: pointer;
  font-weight: 650;
  text-decoration: none;
}
.button:disabled { cursor: not-allowed; opacity: 0.55; }
.button.primary { background: var(--primary); color: #fff; }
.button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.button.secondary { border-color: var(--border); background: var(--surface); color: var(--text); }
.button.secondary:hover:not(:disabled) { background: var(--surface-alt); }
.button.danger { border-color: #efc0bd; background: #fff5f4; color: #a92f29; }
.button.small { min-height: 30px; padding: 4px 8px; font-size: 12px; }
.button.full-width { width: 100%; }

.tasks-section { min-height: 340px; }
.accounts-section { background: #f8f9fa; }
.filter-label { min-width: 150px; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
table { width: 100%; min-width: 980px; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 10px 12px; border-bottom: 1px solid #e8eaee; text-align: left; vertical-align: middle; }
th { background: #f4f5f7; color: #50565f; font-size: 12px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
th:nth-child(1) { width: 210px; }
th:nth-child(2) { width: 250px; }
th:nth-child(3) { width: 150px; }
th:nth-child(4) { width: 110px; }
th:nth-child(5) { width: 80px; }
th:nth-child(6) { width: 170px; }
.actions-column { width: 190px; }
.accounts-table th:nth-child(1) { width: 180px; }
.accounts-table th:nth-child(2) { width: 90px; }
.accounts-table th:nth-child(3) { width: 120px; }
.accounts-table th:nth-child(4) { width: 90px; }
.accounts-table th:nth-child(5) { width: 110px; }
.accounts-table th:nth-child(6) { width: 100px; }
.accounts-table th:nth-child(7) { width: 170px; }
.accounts-table th:nth-child(8) { width: 170px; }
.accounts-table .actions-column { width: 280px; }
.task-id {
  overflow: hidden;
  color: #343941;
  font-family: Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.prompt-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-error { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-email {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-actions { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; }

.status-badge {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 4px;
  background: #e9edf3;
  color: #414750;
  font-size: 12px;
  font-weight: 650;
}
.status-badge.completed { background: #e6f5ed; color: #116a40; }
.status-badge.processing { background: #e7efff; color: #1c53b5; }
.status-badge.failed { background: #fdebea; color: #a62c27; }
.status-badge.manual_action { background: #fff2dc; color: #885000; }
.status-badge.cancelled { color: #686d75; }

.empty-state { padding: 50px 20px; color: var(--muted); text-align: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

dialog {
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.2);
}
dialog::backdrop { background: rgba(16, 20, 26, 0.58); }
.login-dialog { width: min(400px, calc(100vw - 32px)); padding: 0; }
.login-dialog form { padding: 28px; }
.login-dialog h2 { margin: 8px 0 24px; font-size: 21px; }
.login-brand { color: var(--primary); font-size: 13px; font-weight: 750; }
.form-error { min-height: 20px; margin: 8px 0; color: var(--danger); font-size: 12px; }

.video-dialog { width: min(920px, calc(100vw - 28px)); padding: 14px; }
.video-heading { justify-content: space-between; margin-bottom: 12px; }
.video-dialog video { display: block; width: 100%; max-height: 70vh; background: #000; }

.form-dialog { width: min(480px, calc(100vw - 32px)); padding: 0; }
.form-dialog > form, .login-progress-dialog { padding: 22px; }
.remote-login-dialog {
  width: min(1280px, calc(100vw - 28px));
  max-width: none;
  padding: 18px;
}
.remote-frame-wrap {
  height: min(68vh, 780px);
  min-height: 420px;
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #16191d;
}
.remote-frame-wrap iframe { display: block; width: 100%; height: 100%; border: 0; }
.remote-login-dialog.login-blocked { width: min(520px, calc(100vw - 28px)); }
.remote-login-dialog.login-blocked .remote-frame-wrap,
.remote-login-dialog.login-blocked .login-actions { display: none; }
.remote-login-dialog.login-blocked #account-login-error {
  margin: 0;
  padding: 14px;
  border: 1px solid #efc0bd;
  border-radius: 4px;
  background: #fff5f4;
  font-size: 14px;
  line-height: 1.5;
}
.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.dialog-heading h2 { margin: 0; font-size: 19px; }
.dialog-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.login-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(380px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid #a9c5b5;
  border-radius: 5px;
  background: #edf8f2;
  color: #155c39;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.13);
}
.toast.error { border-color: #edb9b5; background: #fff0ef; color: #972d28; }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
  .form-grid { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
  .form-grid .button { grid-column: 1 / -1; width: 100%; }
}

@media (max-width: 620px) {
  .app-header { align-items: flex-start; padding: 12px 16px; }
  .brand { align-items: flex-start; flex-direction: column; gap: 5px; }
  .brand h1 { font-size: 18px; }
  .header-status span { display: none; }
  section { padding: 20px 16px; }
  .metrics { grid-template-columns: repeat(2, minmax(100px, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .button { grid-column: auto; }
  .section-heading { align-items: flex-end; }
  .remote-login-dialog { width: calc(100vw - 12px); padding: 10px; }
  .remote-frame-wrap { height: 64vh; min-height: 360px; }
  .login-actions { grid-template-columns: 1fr; }
}
