:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-muted: #eef3f8;
  --surface-hover: #fbfdff;
  --surface-invalid: #f8fafc;
  --surface-details: #fbfdff;
  --border: #dbe3ee;
  --border-strong: #c7d2df;
  --text-main: #172033;
  --text-muted: #64748b;
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #0f8a5f;
  --blue: #2563eb;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.12);
  --card-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
  --scrollbar: #cbd5e1;
  --modal-backdrop: rgba(15, 23, 42, 0.42);
  --focus-ring: rgba(37, 99, 235, 0.14);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1422;
  --surface: #121a2a;
  --surface-soft: #0b1220;
  --surface-muted: #1d2a3d;
  --surface-hover: #182337;
  --surface-invalid: #101827;
  --surface-details: #0f1726;
  --border: #263449;
  --border-strong: #3b4a62;
  --text-main: #e7edf7;
  --text-muted: #94a3b8;
  --primary-color: #4f8df7;
  --primary-hover: #3b76df;
  --danger: #fb7185;
  --danger-hover: #f43f5e;
  --success: #34d399;
  --blue: #72a7ff;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  --card-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
  --scrollbar: #46556c;
  --modal-backdrop: rgba(2, 6, 23, 0.68);
  --focus-ring: rgba(79, 141, 247, 0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-width: 320px;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

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

/* Auth */
.auth-panel {
  position: relative;
  width: min(92vw, 380px);
  padding: 32px 28px 26px;
  text-align: center;
}

.theme-toggle-auth {
  position: absolute;
  top: 14px;
  right: 14px;
}

.auth-header {
  margin-bottom: 24px;
}

.auth-icon {
  width: 44px;
  height: 44px;
  color: var(--primary-color);
  margin-bottom: 14px;
}

.auth-header h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0;
}

.auth-header p,
.auth-hint {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.auth-header p {
  margin-top: 6px;
}

.auth-hint {
  margin-top: 16px;
}

.auth-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.auth-mode-btn {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.auth-mode-btn.active {
  background: var(--surface);
  color: var(--text-main);
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.08);
}

.error-text {
  color: var(--danger);
  font-size: 0.86rem;
  margin-top: 12px;
}

/* Controls */
.input-group {
  position: relative;
  margin-bottom: 16px;
  text-align: left;
}

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

.input-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.input-group input,
.input-group textarea,
.search-box input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.input-group.icon-field input,
.search-box input {
  padding-left: 38px;
}

.input-group input:focus,
.input-group textarea:focus,
.search-box input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.input-group textarea {
  min-height: 92px;
  resize: vertical;
}

.input-group .hint {
  margin: 4px 0 8px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.btn {
  width: 100%;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 650;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.btn:disabled {
  cursor: wait;
  opacity: 0.72;
}

.btn svg,
.btn-icon svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
}

.btn-primary {
  background: var(--primary-color);
  color: #fff;
}

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

.btn-secondary {
  background: var(--surface-soft);
  border-color: var(--border);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--surface-muted);
}

.btn-icon {
  min-width: 34px;
  min-height: 34px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.btn-icon:hover {
  background: var(--surface-soft);
  border-color: var(--border);
  color: var(--text-main);
}

.text-blue {
  color: var(--blue);
}

.text-green {
  color: var(--success);
}

.text-red {
  color: var(--danger);
}

/* App shell */
.app-container {
  width: min(1120px, 100%);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

@media (min-width: 768px) {
  .app-container {
    height: min(92vh, 900px);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
}

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: none;
  border-radius: 0;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
}

.header-left {
  min-width: 0;
  gap: 10px;
}

.header-right {
  flex-shrink: 0;
  gap: 8px;
}

.logo-icon {
  width: 26px;
  height: 26px;
  color: var(--primary-color);
  flex: 0 0 auto;
}

.header-left h2 {
  overflow: hidden;
  color: var(--text-main);
  font-size: 1.05rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-right .btn {
  width: auto;
  padding: 8px 12px;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--surface-soft);
}

.main-content::-webkit-scrollbar {
  width: 8px;
}

.main-content::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 999px;
}

/* Summary and tools */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 10px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: none;
}

.stat-item {
  min-width: 0;
  padding: 7px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.stat-item + .stat-item {
  border-left: 1px solid var(--border);
}

.stat-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.stat-info {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
}

.stat-info h3 {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
}

.stat-info p {
  min-width: 2ch;
  font-size: 1rem;
  font-weight: 760;
  line-height: 1;
  text-align: left;
}

.toolbar-row {
  margin-bottom: 14px;
}

.search-box {
  position: relative;
  width: 100%;
}

.search-box input {
  padding-right: 42px;
}

.search-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transform: translateY(-50%);
}

.search-clear:hover {
  background: var(--surface-soft);
  color: var(--text-main);
}

.search-clear svg {
  width: 17px;
  height: 17px;
}

/* Account list */
.section-title {
  margin: 14px 0 8px;
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 750;
}

.account-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 82px;
  grid-auto-flow: dense;
  gap: 8px;
}

.account-card {
  position: relative;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  contain: layout paint;
  transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.18s ease;
}

.account-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.account-card.invalid {
  background: var(--surface-invalid);
  opacity: 0.78;
}

.account-card.expanded {
  grid-row: span 3;
  display: flex;
  flex-direction: column;
  box-shadow: var(--card-shadow);
}

.account-summary {
  min-height: 82px;
  display: grid;
  grid-template-rows: 20px 18px 24px;
  gap: 3px;
  padding: 7px 8px 7px;
  cursor: pointer;
}

.acc-info-basic {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.acc-logo,
.acc-logo-fallback {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  flex: 0 0 auto;
}

.acc-logo {
  object-fit: cover;
  background: var(--surface-muted);
  padding: 2px;
}

.acc-logo-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-muted);
  color: var(--primary-color);
  font-size: 0.7rem;
  font-weight: 760;
}

.acc-name {
  display: block;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 680;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acc-host {
  min-width: 0;
  overflow: hidden;
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acc-host:empty {
  display: none;
}

.acc-actions {
  display: flex;
  justify-content: flex-end;
  gap: 3px;
  align-self: center;
  padding: 0 2px 0 52px;
}

.acc-actions .btn-icon {
  min-width: 24px;
  min-height: 24px;
  padding: 3px;
}

.acc-actions .btn-icon svg {
  width: 16px;
  height: 16px;
}

.account-details {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-details);
  color: var(--text-muted);
  font-size: 0.86rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.account-card.expanded .account-summary {
  flex: 0 0 82px;
}

.account-card.expanded .account-details {
  min-height: 0;
  flex: 1;
  align-content: start;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.layout-moving {
  z-index: 2;
  will-change: transform;
}

.account-card.expanded .account-details::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

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

.detail-label {
  color: var(--text-main);
  font-weight: 700;
}

.detail-value {
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.password-copy {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  text-align: left;
  cursor: copy;
}

.password-copy:hover {
  text-decoration: underline;
}

.password-copy:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

.detail-value a {
  color: var(--blue);
  text-decoration: none;
}

.detail-value a:hover {
  text-decoration: underline;
}

.pre-wrap {
  white-space: pre-wrap;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 28px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  text-align: center;
  font-size: 0.92rem;
}

.divider {
  display: flex;
  align-items: center;
  margin: 18px 0 8px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px dashed var(--border-strong);
}

.divider span {
  padding: 0 10px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--modal-backdrop);
}

.modal-content {
  width: min(100%, 520px);
  max-height: min(90vh, 720px);
  overflow-y: auto;
  border-radius: 8px;
}

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

.modal-header h2 {
  font-size: 1.05rem;
  font-weight: 750;
}

.modal-body {
  padding: 18px;
}

.parse-panel {
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.parse-panel .input-group {
  margin-bottom: 10px;
}

.parse-panel textarea {
  min-height: 76px;
}

.form-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 16px;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.form-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--border);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 700px) {
  body {
    align-items: stretch;
  }

  .hide-mobile {
    display: none;
  }

  .auth-panel {
    margin: auto;
  }

  .app-container {
    min-width: 0;
  }

  .app-header {
    padding: 10px 12px;
  }

  .header-left {
    gap: 8px;
  }

  .logo-icon {
    width: 23px;
    height: 23px;
  }

  .header-left h2 {
    font-size: 0.98rem;
  }

  .header-right .btn {
    min-width: 38px;
    padding: 8px;
  }

  .main-content {
    padding: 12px;
  }

  .stats-strip {
    margin-bottom: 8px;
  }

  .stat-item {
    padding: 8px 4px;
    gap: 5px;
  }

  .stat-icon {
    width: 17px;
    height: 17px;
  }

  .stat-info h3 {
    font-size: 0.66rem;
  }

  .stat-info p {
    font-size: 0.98rem;
  }

  .toolbar-row {
    margin-bottom: 12px;
  }

  .account-summary {
    min-height: 82px;
    gap: 3px;
    padding: 7px 8px;
  }

  .acc-info-basic {
    align-items: center;
  }

  .acc-actions {
    justify-content: flex-end;
  }

  .acc-name {
    font-size: 0.8rem;
  }

  .acc-host {
    font-size: 0.76rem;
  }

  .account-details {
    padding: 11px;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .modal {
    align-items: flex-end;
    padding: 10px;
  }

  .modal-content {
    max-height: 92vh;
  }

  .modal-header,
  .modal-body {
    padding: 14px;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }
}
