:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #15171a;
  --muted: #6a7078;
  --line: #dde1e6;
  --line-strong: #c8cdd3;
  --accent: #176b4d;
  --accent-hover: #12563e;
  --accent-soft: #e8f4ef;
  --blue: #2764b8;
  --blue-soft: #eaf1fb;
  --danger: #b42318;
  --danger-soft: #fdf0ee;
  --warning: #8a5a0a;
  --warning-soft: #fff6dc;
  --shadow: 0 12px 28px rgba(17, 24, 39, 0.07);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.topbar-inner {
  width: min(1440px, calc(100% - 40px));
  min-height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand,
.topbar-actions,
.worker-state,
.section-heading,
.heading-actions,
.form-row,
.button,
.key-item,
.job-status,
.key-group-header,
.key-group-title {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--text);
  color: #ffffff;
  font-size: 13px;
  font-weight: 750;
}

.brand h1,
.section-heading h2,
.login-panel h1 {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.25;
}

.brand p,
.section-heading p,
.login-panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  gap: 12px;
}

.worker-state {
  min-height: 34px;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.workspace {
  width: min(1440px, calc(100% - 40px));
  margin: 24px auto 48px;
}

.primary-grid,
.operations-grid {
  display: grid;
  gap: 20px;
}

.primary-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
}

.operations-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  margin-top: 20px;
}

.section {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.input-section,
.key-section {
  padding: 22px;
}

.section-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading.compact {
  min-height: 68px;
  margin: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2 {
  font-size: 16px;
  line-height: 1.3;
}

.section-icon {
  width: 20px;
  height: 20px;
  color: var(--muted);
}

.count-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #f0f2f4;
  color: #4d535b;
  font-size: 12px;
  font-weight: 650;
}

label {
  display: block;
  margin: 0 0 7px;
  color: #34383e;
  font-size: 12px;
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
  background: #ffffff;
  color: var(--text);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input {
  height: 42px;
  padding: 0 12px;
}

textarea {
  display: block;
  min-height: 124px;
  padding: 12px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-row {
  align-items: flex-end;
  gap: 12px;
  margin-top: 16px;
}

.field-grow {
  flex: 1 1 auto;
  min-width: 0;
}

.group-preview {
  display: grid;
  gap: 7px;
}

.group-preview-label {
  color: #34383e;
  font-size: 12px;
  font-weight: 700;
}

.group-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.group-chip {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border: 1px solid #c8d9d1;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 11px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.group-chip.compact {
  min-height: 22px;
  padding: 2px 6px;
  font-size: 9px;
}

.group-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  margin-left: 5px;
  border: none;
  border-radius: 4px;
  background: rgba(180, 35, 24, 0.09);
  color: var(--danger);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.group-chip-remove:hover {
  background: rgba(180, 35, 24, 0.18);
}

.group-manage-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.group-manage-input {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.group-manage-input:focus {
  outline: none;
  border-color: var(--accent);
}

.button,
.icon-button {
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.button {
  min-height: 42px;
  gap: 8px;
  padding: 0 15px;
  font-weight: 700;
}

.button svg,
.icon-button svg {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

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

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

.button.secondary {
  border-color: var(--line-strong);
  background: #ffffff;
  color: #2f3439;
}

.button.secondary:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  background: #f1f3f5;
}

.enqueue-button {
  flex: 0 0 auto;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border-color: var(--line);
  background: #ffffff;
  color: #535a63;
}

.icon-button.danger {
  border-color: #f1c4bf;
  color: var(--danger);
}

.icon-button.danger:hover {
  background: var(--danger-soft);
}

.full {
  width: 100%;
}

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

.compact-button {
  min-height: 34px;
  padding: 0 11px;
}

.danger-outline {
  border: 1px solid #efc5c1;
  background: var(--danger-soft);
  color: var(--danger);
}

.key-groups {
  max-height: 342px;
  overflow: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.key-group + .key-group {
  border-top: 1px solid var(--line-strong);
}

.key-group-header {
  position: sticky;
  top: 0;
  z-index: 1;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 2px 0 10px;
  background: #fafbfc;
}

.key-group-title {
  min-width: 0;
  gap: 9px;
}

.key-group-title strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-group-title span {
  color: var(--muted);
  font-size: 11px;
}

.key-list {
  max-height: 196px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.key-group .key-list {
  max-height: none;
}

.key-empty {
  min-height: 240px;
  display: grid;
  place-items: center;
}

.key-item {
  min-height: 48px;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.key-item.selected {
  background: var(--accent-soft);
}

.key-checkbox {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  margin: 0 4px 0 10px;
  accent-color: var(--accent);
}

.key-details {
  min-width: 0;
  flex: 1 1 auto;
  display: grid;
  gap: 7px;
  padding: 9px 0;
}

.key-group-chips {
  gap: 4px;
}

.key-value {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  color: #30343a;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.key-actions .icon-button {
  width: 32px;
  height: 32px;
}

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

.icloud-pool-section {
  margin-top: 20px;
}

.icloud-pool-badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 12px;
  font-weight: 700;
}

.icloud-pool-badge.ready {
  background: var(--accent-soft);
  color: var(--accent);
}

.icloud-pool-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.icloud-pool-grid > div {
  min-width: 0;
  padding: 14px 20px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}

.icloud-pool-grid > div:last-child {
  border-right: 0;
}

.icloud-pool-grid span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
}

.icloud-pool-grid strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.icloud-pool-aliases {
  display: grid;
  gap: 8px;
  padding: 14px 20px 18px;
  color: var(--muted);
  font-size: 12px;
}

.icloud-pool-aliases > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.icloud-pool-aliases strong {
  color: var(--text);
  overflow-wrap: anywhere;
}

.settings-heading {
  border-bottom: 0;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr)) auto;
  align-items: end;
  gap: 12px;
  padding: 0 20px 20px;
}

.setting-field {
  min-width: 0;
}

.settings-save {
  white-space: nowrap;
}

.cooldown-control {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(300px, auto) auto;
  align-items: end;
  gap: 16px;
  padding: 18px 20px 20px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.cooldown-copy {
  align-self: center;
  display: grid;
  gap: 4px;
}

.cooldown-copy strong {
  font-size: 13px;
}

.cooldown-copy span {
  color: var(--muted);
  font-size: 12px;
}

.cooldown-form,
.cooldown-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.cooldown-field {
  width: 170px;
}

.cooldown-actions {
  align-items: center;
  padding-bottom: 3px;
}

.table-wrap {
  max-height: 410px;
  overflow: auto;
}

.queue-current {
  color: var(--accent) !important;
  font-weight: 700;
}

.current-job-row td {
  background: var(--accent-soft);
}

.mailbox-type {
  display: block;
  width: max-content;
  margin-top: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
}

.mailbox-outlook {
  background: var(--blue-soft);
  color: var(--blue);
}

.mailbox-icloud {
  background: #f0ebff;
  color: #6842b8;
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fafbfc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

th:first-child,
td:first-child {
  width: 64px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 200px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 104px;
}

th:last-child,
td:last-child {
  width: 54px;
}

td {
  color: #33383f;
  font-size: 12px;
}

.email-cell {
  overflow-wrap: anywhere;
}

.account-details {
  display: grid;
  gap: 4px;
}

.account-email {
  color: var(--text);
  font-weight: 650;
}

.account-password-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
}

.account-password {
  min-width: 0;
  color: #4b5159;
  font-size: 10px;
  overflow-wrap: anywhere;
}

.account-copy.icon-button {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
}

.account-copy.icon-button svg {
  width: 13px;
  height: 13px;
}

.job-groups {
  gap: 4px;
}

.job-status {
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
}

.job-status svg {
  width: 14px;
  height: 14px;
}

.status-queued {
  color: var(--blue);
}

.status-waiting_alias {
  color: var(--muted);
}

.status-running {
  color: var(--warning);
}

.status-success {
  color: var(--accent);
}

.status-failed {
  color: var(--danger);
}

.log-view {
  height: 410px;
  overflow: auto;
  padding: 10px 0;
  background: #fbfcfd;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.55;
}

.log-line {
  display: grid;
  grid-template-columns: 72px 50px minmax(0, 1fr);
  gap: 8px;
  padding: 4px 14px;
}

.log-line:hover {
  background: #f1f3f5;
}

.log-time,
.log-job {
  color: #8a9199;
}

.log-message {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #3c4249;
}

.log-error .log-message {
  color: var(--danger);
}

.log-success .log-message {
  color: var(--accent);
}

.empty-state {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(380px, calc(100% - 40px));
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #f5f6f8;
}

.login-shell {
  width: min(390px, 100%);
}

.login-panel {
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-panel .brand-mark {
  margin-bottom: 18px;
}

.login-panel h1 {
  font-size: 22px;
}

.login-form {
  margin-top: 24px;
}

.login-form input {
  margin-bottom: 15px;
}

.form-error {
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid #efc5c0;
  border-radius: 6px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
}

@media (max-width: 980px) {
  .primary-grid,
  .operations-grid {
    grid-template-columns: 1fr;
  }

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

  .icloud-pool-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .settings-save {
    width: 100%;
  }

  .cooldown-control {
    grid-template-columns: 1fr auto;
  }

  .cooldown-form {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (max-width: 640px) {
  .topbar-inner,
  .workspace {
    width: min(1440px, calc(100% - 24px));
  }

  .topbar-inner {
    min-height: 64px;
  }

  .brand p,
  .worker-state .status-dot {
    display: none;
  }

  .worker-state {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .workspace {
    margin-top: 12px;
  }

  .input-section,
  .key-section {
    padding: 16px;
  }

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

  .enqueue-button {
    width: 100%;
  }

  .settings-form {
    grid-template-columns: 1fr;
    padding: 0 16px 16px;
  }

  .icloud-pool-grid {
    grid-template-columns: 1fr;
  }

  .icloud-pool-aliases > div {
    align-items: flex-start;
    flex-direction: column;
  }

  .cooldown-control {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .cooldown-form {
    grid-column: auto;
    grid-row: auto;
    align-items: stretch;
  }

  .cooldown-field {
    width: auto;
    flex: 1 1 auto;
  }

  .cooldown-actions {
    padding: 0;
  }

  .heading-actions .button span {
    display: none;
  }

  .section-heading {
    align-items: flex-start;
  }

  th:nth-child(3),
  td:nth-child(3) {
    display: none;
  }

  .log-line {
    grid-template-columns: 62px minmax(0, 1fr);
  }

  .log-job {
    display: none;
  }
}

.icloud-count-value { font-size: 1.5rem; white-space: nowrap; }
.icloud-count-section .section-heading { border-bottom: 0; }
