:root {
  color-scheme: light;
  --bg: #f0f2f7;
  --surface: #ffffff;
  --surface-dim: #f6f7fb;
  --line: #e2e5ed;
  --line-light: #eceef4;
  --text: #1a1d26;
  --text-secondary: #5a5f72;
  --text-tertiary: #8b90a0;
  --accent: #5c71d9;
  --accent-hover: #4b5ec5;
  --accent-active: #3f4fae;
  --accent-subtle: rgba(92, 113, 217, 0.08);
  --accent-tint: rgba(92, 113, 217, 0.12);
  --accent-ink: #ffffff;
  --green: #2ea44f;
  --green-bg: rgba(46, 164, 79, 0.1);
  --amber: #d97706;
  --amber-bg: rgba(217, 119, 6, 0.1);
  --red: #cf222e;
  --red-bg: rgba(207, 34, 46, 0.1);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Top bar ────────────────────────────────────────────── */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
}

.topbar-logo {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 13px;
}

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

.topbar-sync-status {
  font-size: 12px;
  color: var(--text-tertiary);
  padding-right: 12px;
  border-right: 1px solid var(--line);
  margin-right: 4px;
}

/* ── Layout ─────────────────────────────────────────────── */

.layout {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

/* ── Stats row ──────────────────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.stat-value.loading {
  color: var(--text-tertiary);
  font-size: 14px;
  font-weight: 400;
}

/* ── Toolbar ────────────────────────────────────────────── */

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.search-wrapper {
  flex: 1;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  width: 16px;
  height: 16px;
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  font: inherit;
  font-size: 13px;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-sm);
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.status-select {
  width: 170px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  font: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b90a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.status-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* ── Buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
}

.btn-primary:active {
  background: var(--accent-active);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--surface-dim);
  border-color: #cdd1dc;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  padding: 8px 12px;
}

.btn-ghost:hover {
  background: var(--accent-subtle);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Content grid ───────────────────────────────────────── */

.content {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 20px;
  align-items: start;
}

/* ── Card ───────────────────────────────────────────────── */

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-light);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.card-meta {
  font-size: 12px;
  color: var(--text-tertiary);
}

.card-body {
  padding: 12px;
}

.card-body-padded {
  padding: 20px;
}

/* ── Account list ───────────────────────────────────────── */

.accounts-scroll {
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.list {
  display: grid;
  gap: 4px;
}

.list-item {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  font: inherit;
  color: var(--text);
}

.list-item:hover {
  background: var(--surface-dim);
}

.list-item.active {
  background: var(--accent-subtle);
}

.list-item-name {
  font-weight: 600;
  font-size: 13px;
  grid-column: 1;
}

.list-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
  grid-column: 1;
}

.list-item-badge {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
}

/* ── Status badges ──────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge-green {
  background: var(--green-bg);
  color: var(--green);
}

.badge-amber {
  background: var(--amber-bg);
  color: var(--amber);
}

.badge-red {
  background: var(--red-bg);
  color: var(--red);
}

.badge-neutral {
  background: var(--accent-subtle);
  color: var(--accent);
}

/* ── Detail panel ───────────────────────────────────────── */

.detail-card {
  position: sticky;
  top: 80px;
}

.detail-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

.detail-empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--surface-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
}

.detail-section {
  padding: 16px 20px;
}

.detail-section + .detail-section {
  border-top: 1px solid var(--line-light);
}

.detail-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.detail-field-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-field-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.detail-field-value.muted {
  color: var(--text-tertiary);
  font-weight: 400;
}

.detail-actions {
  padding: 16px 20px;
  border-top: 1px solid var(--line-light);
  display: flex;
  gap: 8px;
}

/* ── Spinner ────────────────────────────────────────────── */

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

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

.spinner-sm {
  width: 12px;
  height: 12px;
  border-width: 1.5px;
}

/* ── Toast ──────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 200ms ease-out;
  max-width: 360px;
}

.toast-success {
  background: var(--green);
}

.toast-error {
  background: var(--red);
}

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

/* ── Empty / loading states ─────────────────────────────── */

.list-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  gap: 10px;
  color: var(--text-tertiary);
  font-size: 13px;
}

.list-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 960px) {
  .content {
    grid-template-columns: 1fr;
  }

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

  .toolbar {
    flex-direction: column;
  }

  .status-select {
    width: 100%;
  }

  .detail-card {
    position: static;
  }

  .topbar {
    padding: 0 16px;
  }

  .layout {
    padding: 16px 16px 32px;
  }

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

@media (max-width: 600px) {
  .topbar-sync-status {
    display: none;
  }
}
