:root,
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-subtle: #eef2f7;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --brand-gradient: linear-gradient(135deg, #2563eb, #4f46e5);
  --gold: #f59e0b;
  --gold-border: #fcd34d;
  --gold-soft: #fffbeb;
  --gold-card-bg: linear-gradient(180deg, #fffdf5 0%, #ffffff 78px);
  --gold-avatar-text: #b45309;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --pill-bg: rgba(15, 23, 42, 0.07);
  --badge-phone-bg: #dbeafe;
  --badge-phone-text: #1d4ed8;
  --badge-email-bg: #dcfce7;
  --badge-email-text: #15803d;
  --badge-social-bg: #f3e8ff;
  --badge-social-text: #7e22ce;
  --badge-address-bg: #ffedd5;
  --badge-address-text: #c2410c;
  --badge-other-bg: #e2e8f0;
  --badge-other-text: #334155;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --card-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-muted: #1e293b;
  --surface-subtle: #334155;
  --border: #273449;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --brand-gradient: linear-gradient(135deg, #3b82f6, #6366f1);
  --gold: #fbbf24;
  --gold-border: #d97706;
  --gold-soft: rgba(245, 158, 11, 0.14);
  --gold-card-bg: linear-gradient(180deg, rgba(245, 158, 11, 0.11) 0%, #111827 84px);
  --gold-avatar-text: #fcd34d;
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --pill-bg: rgba(241, 245, 249, 0.12);
  --badge-phone-bg: rgba(59, 130, 246, 0.22);
  --badge-phone-text: #93c5fd;
  --badge-email-bg: rgba(34, 197, 94, 0.2);
  --badge-email-text: #86efac;
  --badge-social-bg: rgba(168, 85, 247, 0.22);
  --badge-social-text: #d8b4fe;
  --badge-address-bg: rgba(249, 115, 22, 0.22);
  --badge-address-text: #fdba74;
  --badge-other-bg: rgba(148, 163, 184, 0.22);
  --badge-other-text: #cbd5e1;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.42);
  --card-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

:root[data-theme="ocean"] {
  --bg: #ecfeff;
  --surface: #ffffff;
  --surface-muted: #f0f9ff;
  --surface-subtle: #dbeafe;
  --border: #bae6fd;
  --text: #0c4a6e;
  --text-muted: #0369a1;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-soft: #e0f2fe;
  --brand-gradient: linear-gradient(135deg, #0284c7, #0d9488);
  --gold: #f59e0b;
  --gold-border: #fbbf24;
  --gold-soft: #fefce8;
  --gold-card-bg: linear-gradient(180deg, #fefce8 0%, #ffffff 78px);
  --gold-avatar-text: #b45309;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --pill-bg: rgba(2, 132, 199, 0.12);
  --badge-phone-bg: #e0f2fe;
  --badge-phone-text: #0369a1;
  --badge-email-bg: #ccfbf1;
  --badge-email-text: #0f766e;
  --badge-social-bg: #e0e7ff;
  --badge-social-text: #4338ca;
  --badge-address-bg: #ffedd5;
  --badge-address-text: #c2410c;
  --badge-other-bg: #e2e8f0;
  --badge-other-text: #334155;
  --shadow: 0 10px 26px rgba(2, 132, 199, 0.1);
  --card-shadow: 0 4px 14px rgba(2, 132, 199, 0.07);
}

:root[data-theme="warm"] {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-muted: #faf5eb;
  --surface-subtle: #ede4d3;
  --border: #e5d8c3;
  --text: #3b2f24;
  --text-muted: #7c6a58;
  --primary: #b45309;
  --primary-hover: #92400e;
  --primary-soft: #fef3c7;
  --brand-gradient: linear-gradient(135deg, #b45309, #d97706);
  --gold: #d97706;
  --gold-border: #f59e0b;
  --gold-soft: #fef3c7;
  --gold-card-bg: linear-gradient(180deg, #fef9e7 0%, #fffdf8 78px);
  --gold-avatar-text: #92400e;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --pill-bg: rgba(120, 53, 15, 0.09);
  --badge-phone-bg: #fde68a;
  --badge-phone-text: #92400e;
  --badge-email-bg: #dcfce7;
  --badge-email-text: #166534;
  --badge-social-bg: #ede9fe;
  --badge-social-text: #6d28d9;
  --badge-address-bg: #fed7aa;
  --badge-address-text: #9a3412;
  --badge-other-bg: #e7e5e4;
  --badge-other-text: #44403c;
  --shadow: 0 8px 24px rgba(68, 49, 28, 0.08);
  --card-shadow: 0 4px 14px rgba(68, 49, 28, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background 0.2s ease, color 0.2s ease;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 20px 56px;
}

.top-bar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.top-bar-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--brand-gradient);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.25;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.appearance-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px 6px;
}

.compact-select {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  font-family: inherit;
  padding: 4px 22px 4px 4px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 20 20' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
}

.compact-select:focus {
  outline: none;
}

.btn-ghost-icon {
  background: transparent;
  border: none;
  padding: 4px 6px;
  font-size: 0.95rem;
  line-height: 1;
}

.lang-btn {
  min-width: 82px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 15px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

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

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

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

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

.btn-accent-soft {
  background: var(--gold-soft);
  color: var(--gold-avatar-text);
  border-color: var(--gold-border);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
}

.controls-panel {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.view-tabs {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tab-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.star-glyph {
  color: var(--gold);
}

.count-pill {
  background: var(--pill-bg);
  color: inherit;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.78rem;
}

.search-sort-group {
  display: flex;
  flex: 1;
  min-width: 280px;
  max-width: 720px;
  gap: 10px;
  align-items: center;
}

.search-box {
  flex: 1;
  min-width: 240px;
  position: relative;
}

.search-box input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-clear-btn {
  position: absolute;
  inset-inline-end: 6px;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

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

.search-clear-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.search-box input,
.sort-select,
.form-field input,
.form-field textarea,
.method-row select,
.method-row input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.search-box input:focus,
.sort-select:focus,
.form-field input:focus,
.form-field textarea:focus,
.method-row select:focus,
.method-row input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--primary);
}

.search-box.has-query input {
  padding-inline-end: 4.2rem;
}

.sort-select {
  width: auto;
  min-width: 195px;
  padding-right: 32px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 20 20' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
}

.full-width {
  width: 100%;
}

.result-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.contacts-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(335px, 1fr));
  gap: 18px;
}

.contact-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.contact-card.is-favorite {
  border-color: var(--gold-border);
  background: var(--gold-card-bg);
}

.contact-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.identity-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 1rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.contact-card.is-favorite .avatar {
  background: var(--gold-soft);
  color: var(--gold-avatar-text);
  border: 1px solid var(--gold-border);
}

.contact-name {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  word-break: break-word;
}

.contact-meta {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-word;
}

.favorite-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1.15rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.favorite-btn:hover {
  border-color: var(--gold-border);
  color: var(--gold);
  background: var(--gold-soft);
}

.favorite-btn.active {
  border-color: var(--gold-border);
  background: var(--gold-soft);
  color: var(--gold);
}

.method-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.method-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--surface-subtle);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 0.88rem;
}

.method-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--badge-other-bg);
  color: var(--badge-other-text);
}

.method-badge.type-phone {
  background: var(--badge-phone-bg);
  color: var(--badge-phone-text);
}

.method-badge.type-email {
  background: var(--badge-email-bg);
  color: var(--badge-email-text);
}

.method-badge.type-social {
  background: var(--badge-social-bg);
  color: var(--badge-social-text);
}

.method-badge.type-address {
  background: var(--badge-address-bg);
  color: var(--badge-address-text);
}

.method-label {
  color: var(--text-muted);
  font-weight: 600;
  flex-shrink: 0;
}

.method-value {
  color: var(--text);
  word-break: break-all;
  flex: 1;
}

.method-link {
  color: var(--primary);
  text-decoration: none;
}

.method-link:hover {
  text-decoration: underline;
}

.copy-method-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.copy-method-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.contact-notes {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  background: var(--surface-muted);
  border-left: 3px solid var(--border);
  padding: 6px 10px;
  border-radius: 0 8px 8px 0;
}

.contact-card-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.empty-state {
  margin-top: 36px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 44px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 2.3rem;
}

.empty-state h2 {
  margin: 10px 0 6px;
  font-size: 1.2rem;
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--text-muted);
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.25);
}

.modal-card-sm {
  max-width: 540px;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.icon-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
}

.required {
  color: var(--danger);
}

.favorite-toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--gold-border);
  border-radius: 10px;
  background: var(--gold-soft);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  align-self: end;
  cursor: pointer;
}

.methods-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--surface-muted);
}

.methods-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.methods-header h3 {
  margin: 0;
  font-size: 0.98rem;
}

.helper-text {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.methods-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.method-row {
  display: grid;
  grid-template-columns: 128px 140px 1fr 36px;
  gap: 8px;
  align-items: center;
}

.remove-method-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--danger);
  font-size: 1.15rem;
  cursor: pointer;
}

.remove-method-btn:hover {
  background: var(--danger-soft);
}

.file-dropzone {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 18px;
  background: var(--surface-muted);
}

.import-summary {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.88rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.import-summary.has-errors {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 6px;
}

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

.toast {
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.25);
}

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

.toast.success {
  background: #15803d;
}

@media (max-width: 720px) {
  .form-grid,
  .method-row {
    grid-template-columns: 1fr;
  }

  .search-sort-group {
    max-width: none;
    width: 100%;
    flex-wrap: wrap;
  }
}
