:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --border: #d9e0df;
  --border-strong: #c6d0ce;
  --text: #172321;
  --muted: #687572;
  --primary: #087c65;
  --primary-hover: #056852;
  --primary-soft: #e6f5f0;
  --blue: #2d65a5;
  --blue-soft: #eaf1fa;
  --amber: #a55c08;
  --amber-soft: #fff3df;
  --danger: #b4232f;
  --danger-hover: #941b25;
  --danger-soft: #fdecef;
  --shadow: 0 16px 40px rgba(23, 35, 33, 0.14);
  --font-sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

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

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

svg {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

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

h1,
h2,
h3,
strong {
  font-weight: 650;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.mono {
  font-family: var(--font-mono);
}

.eyebrow {
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.brand h1 {
  overflow: hidden;
  font-size: 16px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid #b9d8ce;
  border-radius: 7px;
  color: var(--primary);
  background: var(--primary-soft);
}

.brand-mark svg {
  width: 21px;
  height: 21px;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 620;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.button:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(8, 124, 101, 0.18);
  outline-offset: 1px;
}

.button {
  min-height: 38px;
  gap: 8px;
  padding: 8px 14px;
}

.button-small {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

.button-wide {
  width: 100%;
}

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

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

.button-secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
}

.button-secondary:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: #a8d2c5;
}

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

.button-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  color: #52615e;
  background: transparent;
  border-color: transparent;
}

.icon-button.is-loading svg,
.button.is-loading svg,
.task-spinner {
  animation: spin 900ms linear infinite;
}

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

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

input {
  height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 150px;
  padding: 10px 11px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
}

input::placeholder,
textarea::placeholder {
  color: #96a19f;
}

label {
  color: #34413f;
  font-size: 13px;
  font-weight: 620;
}

.form-error {
  color: var(--danger);
  font-size: 13px;
}

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

.login-panel {
  width: min(100%, 400px);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-login {
  margin-bottom: 30px;
}

.brand-login .brand-mark {
  width: 46px;
  height: 46px;
  flex-basis: 46px;
}

.brand-login h1 {
  font-size: 20px;
}

.brand-login p {
  margin-top: 2px;
  font-size: 13px;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form .button {
  margin-top: 6px;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 44px;
  font-family: var(--font-mono);
}

.field-action {
  position: absolute;
  top: 1px;
  right: 1px;
  height: 38px;
}

.app-view {
  min-height: 100vh;
}

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

.topbar-inner {
  display: flex;
  width: min(100%, 1240px);
  min-height: 64px;
  margin: 0 auto;
  padding: 0 24px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.topbar-actions,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.service-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.service-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.workspace {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 34px 24px 64px;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.page-heading h2 {
  margin-top: 4px;
  font-size: 26px;
  line-height: 1.25;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 28px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.metric {
  display: flex;
  min-height: 104px;
  padding: 22px 24px;
  align-items: center;
  gap: 14px;
  border-right: 1px solid var(--border);
}

.metric:last-child {
  border-right: 0;
}

.metric-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 7px;
}

.metric-accounts {
  color: var(--blue);
  background: var(--blue-soft);
}

.metric-aliases {
  color: #7b4a9f;
  background: #f2ebf8;
}

.metric-ready {
  color: var(--primary);
  background: var(--primary-soft);
}

.metric-expired {
  color: var(--amber);
  background: var(--amber-soft);
}

.metric div {
  display: grid;
}

.metric strong {
  font-size: 24px;
  line-height: 1.2;
}

.metric span:last-child {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.task-strip {
  display: flex;
  min-height: 54px;
  margin-top: 18px;
  padding: 10px 14px;
  align-items: center;
  gap: 12px;
  border: 1px solid #b8d9cf;
  border-radius: 6px;
  background: var(--primary-soft);
}

.task-strip.is-error {
  border-color: #e8bcc1;
  background: var(--danger-soft);
}

.task-strip > svg {
  color: var(--primary);
}

.task-strip.is-error > svg {
  color: var(--danger);
}

.task-strip div {
  min-width: 0;
  flex: 1;
}

.task-strip strong,
.task-strip span {
  display: block;
}

.task-strip span {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.task-progress {
  width: 120px;
  height: 5px;
  overflow: hidden;
  border-radius: 4px;
  background: #c9ded8;
}

.task-progress span {
  height: 100%;
  background: var(--primary);
}

.account-section {
  margin-top: 34px;
}

.section-toolbar {
  display: flex;
  min-height: 44px;
  margin-bottom: 12px;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.section-toolbar > div {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.section-toolbar h3,
.drawer-section h3 {
  font-size: 16px;
}

.search-field {
  position: relative;
  width: min(100%, 280px);
}

.search-field svg {
  position: absolute;
  top: 11px;
  left: 11px;
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.search-field input {
  padding-left: 36px;
  font-weight: 400;
}

.table-shell {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

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

.account-table th,
.account-table td {
  padding: 13px 16px;
  border-bottom: 1px solid #e5eae9;
  text-align: left;
  vertical-align: middle;
}

.account-table th {
  height: 42px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 650;
}

.account-table th:first-child { width: 29%; }
.account-table th:nth-child(2) { width: 11%; }
.account-table th:nth-child(3) { width: 19%; }
.account-table th:nth-child(4) { width: 11%; }
.account-table th:nth-child(5) { width: 20%; }
.account-table th:last-child { width: 10%; }

.account-table tbody tr:last-child td {
  border-bottom: 0;
}

.account-table tbody tr:hover {
  background: #fbfcfc;
}

.account-identity,
.pool-cell {
  min-width: 0;
}

.account-email {
  display: block;
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-note {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  padding: 2px 8px;
  align-items: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.badge::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.badge-enabled,
.badge-available {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: #c7e2da;
}

.badge-disabled {
  color: var(--muted);
  background: #edf0ef;
  border-color: #dce2e0;
}

.badge-used {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: #efd3a9;
}

.badge-blacklisted {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #f1c8ce;
}

.pool-numbers {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.pool-numbers strong {
  font-size: 14px;
}

.pool-bar {
  height: 5px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 4px;
  background: #e4e9e8;
}

.pool-bar span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.manage-button {
  min-height: 32px;
  padding: 5px 8px 5px 10px;
  white-space: nowrap;
}

.manage-button svg {
  width: 15px;
  height: 15px;
}

.empty-state {
  display: grid;
  min-height: 280px;
  padding: 40px 24px;
  place-items: center;
  align-content: center;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 34px;
  height: 34px;
  margin-bottom: 12px;
  color: #87938f;
}

.empty-state strong {
  color: var(--text);
  font-size: 15px;
}

.empty-state span {
  margin-top: 4px;
  font-size: 13px;
}

dialog {
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
}

dialog::backdrop {
  background: rgba(15, 25, 23, 0.5);
  backdrop-filter: blur(2px);
}

.modal {
  width: min(calc(100% - 32px), 620px);
  max-height: calc(100vh - 40px);
  overflow: visible;
}

.modal-small {
  width: min(calc(100% - 32px), 450px);
}

.modal-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header,
.modal-footer {
  display: flex;
  padding: 18px 22px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal-header {
  border-bottom: 1px solid var(--border);
}

.modal-header h2,
.drawer-header h2 {
  margin-top: 3px;
  font-size: 19px;
  line-height: 1.3;
}

.modal-close {
  margin-right: -8px;
}

.modal-body {
  display: grid;
  max-height: calc(100vh - 230px);
  overflow-y: auto;
  padding: 22px;
  gap: 9px;
}

.modal-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
}

.switch-list {
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

.switch-row,
.setting-row {
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.switch-row > span:first-child,
.setting-row > span:first-child {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.switch-row small,
.setting-row small {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.switch-row input,
.setting-row input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex: 0 0 38px;
  border-radius: 12px;
  background: #b8c2bf;
  transition: background-color 120ms ease;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(23, 35, 33, 0.25);
  content: "";
  transition: transform 120ms ease;
}

.switch-row input:checked + .switch,
.setting-row input:checked + .switch {
  background: var(--primary);
}

.switch-row input:checked + .switch::after,
.setting-row input:checked + .switch::after {
  transform: translateX(16px);
}

.switch-row input:focus-visible + .switch,
.setting-row input:focus-visible + .switch {
  outline: 3px solid rgba(8, 124, 101, 0.2);
  outline-offset: 2px;
}

.drawer {
  width: min(100%, 720px);
  max-width: none;
  height: 100vh;
  max-height: none;
  margin: 0 0 0 auto;
  overflow: hidden;
}

.drawer-panel {
  display: flex;
  height: 100%;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface);
  box-shadow: -18px 0 42px rgba(23, 35, 33, 0.15);
}

.drawer-header {
  display: flex;
  min-height: 82px;
  padding: 18px 24px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--border);
}

.drawer-header > div {
  min-width: 0;
}

.drawer-header h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 40px;
}

.drawer-section {
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
}

.drawer-section:last-child {
  border-bottom: 0;
}

.drawer-section-heading {
  display: flex;
  min-height: 38px;
  margin-bottom: 14px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.drawer-section-heading > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.pool-controls {
  display: grid;
  grid-template-columns: auto minmax(150px, 1fr) auto minmax(150px, 1fr);
  align-items: center;
  gap: 10px;
}

.number-action {
  display: flex;
  align-items: center;
  gap: 6px;
}

.number-action input {
  min-width: 0;
}

.alias-list {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.alias-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  min-height: 66px;
  padding: 10px 10px 10px 14px;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.alias-row:last-child {
  border-bottom: 0;
}

.alias-main {
  min-width: 0;
}

.alias-address-line,
.alias-key-line {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
}

.alias-address {
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alias-key-line {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.alias-key {
  overflow: hidden;
  font-family: var(--font-mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-button,
.alias-delete {
  width: 30px;
  height: 30px;
}

.copy-button svg,
.alias-delete svg {
  width: 15px;
  height: 15px;
}

.copy-button.copy-success {
  color: var(--primary);
  border-color: #9fcfc0;
  background: var(--primary-soft);
}

.copy-button.copy-success svg {
  animation: copy-confirm 320ms ease-out;
}

@keyframes copy-confirm {
  0% { opacity: 0; transform: scale(0.55); }
  65% { opacity: 1; transform: scale(1.18); }
  100% { opacity: 1; transform: scale(1); }
}

.alias-delete:hover:not(:disabled) {
  color: var(--danger);
  border-color: #e7b7bd;
  background: var(--danger-soft);
}

.alias-empty,
.alias-loading {
  display: grid;
  min-height: 130px;
  padding: 24px;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.alias-loading svg {
  animation: spin 900ms linear infinite;
}

.account-settings .drawer-section-heading {
  margin-bottom: 0;
}

.account-settings .setting-row:last-child {
  border-bottom: 0;
}

.danger-row strong {
  color: var(--danger);
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  display: grid;
  width: min(calc(100% - 40px), 370px);
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  min-height: 48px;
  padding: 11px 13px;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid #b7d6cd;
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(23, 35, 33, 0.16);
  animation: toast-in 160ms ease-out;
}

.toast svg {
  margin-top: 1px;
  color: var(--primary);
}

.toast.error {
  border-color: #e4b5bb;
}

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

.toast div {
  min-width: 0;
}

.toast strong,
.toast span {
  display: block;
}

.toast span {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--border);
  }

  .account-table th:nth-child(4),
  .account-table td:nth-child(4),
  .account-table th:nth-child(5),
  .account-table td:nth-child(5) {
    display: none;
  }

  .account-table th:first-child { width: 38%; }
  .account-table th:nth-child(2) { width: 17%; }
  .account-table th:nth-child(3) { width: 27%; }
  .account-table th:last-child { width: 18%; }

  .pool-controls {
    grid-template-columns: auto minmax(160px, 1fr);
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    min-height: 60px;
    padding: 0 14px;
  }

  .topbar .brand-mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .topbar .brand h1 {
    max-width: 150px;
    font-size: 14px;
  }

  .topbar .brand p {
    display: none;
  }

  .topbar-actions {
    gap: 0;
  }

  .topbar-actions .icon-button {
    width: 36px;
  }

  .workspace {
    padding: 24px 14px 48px;
  }

  .page-heading {
    align-items: center;
  }

  .page-heading h2 {
    font-size: 21px;
  }

  .metrics {
    margin-top: 22px;
  }

  .metric {
    min-height: 88px;
    padding: 16px 14px;
    gap: 10px;
  }

  .metric-icon {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .metric strong {
    font-size: 20px;
  }

  .section-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .search-field {
    width: 100%;
  }

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

  .account-table {
    min-width: 560px;
  }

  .account-table th,
  .account-table td {
    padding: 12px;
  }

  .drawer {
    width: 100%;
  }

  .drawer-header {
    min-height: 76px;
    padding: 15px 16px;
  }

  .drawer-header h2 {
    max-width: 270px;
    font-size: 16px;
  }

  .drawer-content {
    padding: 0 16px 32px;
  }

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

  .inline-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .pool-controls {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .pool-controls > label:not(:first-child) {
    margin-top: 8px;
  }

  .alias-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .alias-row .badge {
    grid-column: 1;
    width: max-content;
  }

  .alias-delete {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .modal-header,
  .modal-footer {
    padding: 16px;
  }

  .modal-body {
    padding: 18px 16px;
  }

  .login-view {
    padding: 16px;
  }

  .login-panel {
    padding: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
