:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1a1f2e;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* —— Login —— */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 480px at 20% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(800px 400px at 100% 0%, #e0e7ff 0%, transparent 50%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 26px 24px;
  display: grid;
  gap: 14px;
}
.login-brand { text-align: center; margin-bottom: 6px; }
.login-brand .logo { font-size: 36px; }
.login-brand h1 { margin: 8px 0 4px; font-size: 24px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 13px; }
.login-submit { width: 100%; margin-top: 4px; padding: 12px 16px; }
.user-chip {
  font-size: 13px;
  color: var(--muted);
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #e0e7ff 0%, transparent 50%),
    var(--bg);
}

/* Author `display:flex` otherwise overrides the HTML hidden attribute */
[hidden] {
  display: none !important;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 28px;
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.02em; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.top-actions { display: flex; gap: 12px; align-items: center; }
.search-box input {
  width: min(320px, 40vw);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 14px;
  outline: none;
}
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s ease;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { background: transparent; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 18px;
  padding: 18px 28px 28px;
  min-height: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-title-wrap { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-sub { color: var(--muted); font-size: 12px; }
.badge {
  background: #eff6ff;
  color: var(--primary);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}

.customer-list {
  overflow: auto;
  padding: 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* —— Company groups —— */
.company-group {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfe;
  overflow: hidden;
}
.company-group.unknown {
  border-style: dashed;
  background: #fafafa;
}
.company-header {
  width: 100%;
  display: grid;
  grid-template-columns: 16px 32px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  border-bottom: 1px solid var(--line);
  transition: background 0.12s ease;
}
.company-header:hover { background: #eef2ff; }
.company-group.collapsed .company-header { border-bottom: none; }
.company-chevron {
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
  display: inline-block;
}
.company-group.collapsed .company-chevron { transform: rotate(-90deg); }
.company-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: #dbeafe;
  color: #1d4ed8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.company-group.unknown .company-mark {
  background: #e2e8f0;
  color: #64748b;
}
.company-info {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.company-name {
  font-weight: 650;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.company-meta {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}
.company-members {
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #fff;
}

.customer-item {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: 0.12s ease;
}
.customer-item:hover { background: #f8fafc; }
.customer-item.active {
  background: #eff6ff;
  border-color: #bfdbfe;
}
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #475569;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.item-main { min-width: 0; }
.item-name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-email { color: #334155; font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.detail-body { padding: 18px; overflow: auto; flex: 1; }
.detail-actions { display: flex; gap: 8px; }

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

.detail-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 14px 18px;
}
.detail-hero {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 18px;
  margin-bottom: 22px;
  align-items: start;
}
.detail-hero img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f8fafc;
  object-fit: contain;
  max-height: 140px;
}
.hero-text h3 { margin: 0 0 6px; font-size: 22px; }
.hero-text .en { color: var(--muted); margin-bottom: 8px; }
.hero-text .company { font-weight: 600; }
.field-label { color: var(--muted); font-size: 13px; padding-top: 2px; }
.field-value { font-size: 14px; word-break: break-word; }
.field-value a { color: var(--primary); text-decoration: none; }
.field-value a:hover { text-decoration: underline; }
.raw-box {
  margin-top: 22px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
}

.modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.25);
}
.modal::backdrop { background: rgba(15, 23, 42, 0.45); }
.modal-card { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-card header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; overflow: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: #fafafa;
}
.icon-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.dropzone {
  display: block;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  background: #f8fafc;
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: 0.15s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}
.dropzone-inner { display: grid; gap: 6px; color: var(--muted); }
.dropzone-inner strong { color: var(--ink); }

.preview-wrap {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #f1f5f9;
  text-align: center;
}
.preview-wrap img {
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
}
.status.info { background: #eff6ff; color: #1d4ed8; }
.status.ok { background: #ecfdf5; color: #047857; }
.status.warn { background: #fffbeb; color: #b45309; border: 1px solid #fcd34d; }
.status.err { background: #fef2f2; color: #b91c1c; }

.dup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.dup-actions .btn { font-size: 13px; padding: 6px 12px; }

.ocr-form, #editForm {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-field { display: grid; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12px; color: var(--muted); }
.form-field input, .form-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  outline: none;
  background: #fff;
}
.form-field input:focus, .form-field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.form-field textarea { min-height: 72px; resize: vertical; }
.notes-list {
  grid-column: 1 / -1;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 50;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: space-between; }
  .search-box input { width: 100%; }
  .detail-hero { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; gap: 4px 0; }
  .ocr-form, #editForm { grid-template-columns: 1fr; }
}
