* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif; color: #1a1f2e; background: #f5f7fb; }
body { min-height: 100vh; }
#app, .view { min-height: 100vh; }
[hidden] { display: none !important; }

/* ------- Login ------- */
.login-view { display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg,#eef1fb 0%,#f7f0ff 100%); }
.login-card { background: #fff; border-radius: 20px; padding: 40px 36px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(20,24,60,0.08); text-align: center; }
.brand { margin-bottom: 32px; }
.brand-mark { display: inline-block; width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(135deg,#5b7cfa,#7b5bfa); color: #fff; font-size: 28px; line-height: 56px; margin-bottom: 16px; }
.brand-mark.small { width: 28px; height: 28px; font-size: 16px; line-height: 28px; border-radius: 8px; margin: 0 8px 0 0; vertical-align: middle; }
.brand h1 { margin: 0 0 6px; font-size: 24px; font-weight: 700; }
.brand p { margin: 0; color: #6b7285; font-size: 14px; }
.g-btn-wrap { display: flex; justify-content: center; min-height: 44px; }
.login-hint { margin-top: 20px; color: #8a92a3; font-size: 12px; }

/* ------- App shell ------- */
.app-view { display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: #fff; border-bottom: 1px solid #eef0f4; }
.topbar-left { display: flex; align-items: center; }
.app-title { font-weight: 700; font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; color: #6b7285; font-size: 13px; }

.main { display: grid; grid-template-columns: 240px 1fr; flex: 1; min-height: 0; }
.sidebar { background: #fff; border-right: 1px solid #eef0f4; padding: 16px; overflow-y: auto; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: #8a92a3; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }
.site-list { list-style: none; margin: 0; padding: 0; }
.site-list li { display: flex; align-items: center; gap: 4px; padding: 0 4px 0 12px; border-radius: 8px; font-size: 14px; color: #1a1f2e; margin-bottom: 4px; min-height: 36px; }
.site-list li:hover { background: #f5f7fb; }
.site-list li.active { background: #eef0ff; color: #4854e5; font-weight: 600; }
.site-list .site-name { flex: 1; padding: 8px 0; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-list .site-edit { background: transparent; border: 0; color: #8a92a3; cursor: pointer; font-size: 13px; padding: 6px 8px; border-radius: 6px; opacity: 0; transition: opacity 0.15s; }
.site-list li:hover .site-edit { opacity: 1; }
.site-list li.active .site-edit { opacity: 0.7; color: #4854e5; }
.site-list .site-edit:hover { background: rgba(91,124,250,0.15); color: #4854e5; opacity: 1; }

.content { padding: 24px 32px; overflow-y: auto; }
.empty-state { text-align: center; padding: 80px 20px; color: #6b7285; }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h2 { margin: 0 0 8px; color: #1a1f2e; font-weight: 600; }

/* ------- Site panel ------- */
.embed-section { background: #fff; border-radius: 16px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 12px rgba(20,24,60,0.04); }
.embed-section h2 { margin: 0 0 16px; font-size: 20px; }
.embed-block { background: #f5f7fb; border-radius: 10px; padding: 12px 14px; font-size: 12px; }
.embed-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: #6b7285; }
.embed-header code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.embed-block pre { margin: 0; font-family: ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size: 12px; color: #1a1f2e; white-space: pre-wrap; word-break: break-all; }
.site-actions { margin-top: 16px; text-align: right; }

.products-section { background: #fff; border-radius: 16px; padding: 24px; box-shadow: 0 2px 12px rgba(20,24,60,0.04); }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-head h3 { margin: 0; font-size: 16px; }
.products-empty { text-align: center; padding: 40px 20px; color: #8a92a3; font-size: 13px; }
.products-table { width: 100%; border-collapse: collapse; }
.products-table th { text-align: left; padding: 10px 12px; font-size: 12px; color: #8a92a3; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid #eef0f4; }
.products-table td { padding: 12px; border-bottom: 1px solid #f5f7fb; font-size: 14px; vertical-align: middle; }
.products-table tbody tr:hover { background: #fafbfd; }
.products-table .thumb { width: 40px; height: 40px; border-radius: 8px; background: #eef0f4; display: flex; align-items: center; justify-content: center; overflow: hidden; font-size: 14px; color: #5b7cfa; font-weight: 600; }
.products-table .thumb img { width: 100%; height: 100%; object-fit: cover; }
.type-tag { padding: 2px 8px; border-radius: 6px; font-size: 11px; }
.type-link { background: #e6f2ff; color: #1e6ed0; }
.type-qrcode { background: #ffe9e0; color: #d8570c; }
.status-toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; }
.status-toggle input { margin: 0; }

/* ------- Buttons ------- */
.primary-btn { background: linear-gradient(135deg,#5b7cfa,#7b5bfa); color: #fff; border: 0; padding: 8px 16px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.primary-btn:hover { opacity: 0.92; }
.ghost-btn { background: transparent; border: 1px solid #d8dce6; color: #4a5060; padding: 6px 12px; border-radius: 8px; font-size: 12px; cursor: pointer; }
.ghost-btn:hover { border-color: #a8aec0; }
.danger-btn { background: transparent; border: 1px solid #f5c6c6; color: #c74848; padding: 6px 14px; border-radius: 8px; font-size: 12px; cursor: pointer; }
.danger-btn:hover { background: #fdeeee; }
.mini-btn { background: transparent; border: 1px solid #d8dce6; color: #4a5060; padding: 3px 10px; border-radius: 6px; font-size: 11px; cursor: pointer; }
.mini-btn:hover { border-color: #5b7cfa; color: #5b7cfa; }
.link-btn { background: transparent; border: 0; color: #5b7cfa; cursor: pointer; padding: 0; font-size: 12px; }
.link-btn.danger { color: #c74848; }
.link-btn:hover { text-decoration: underline; }

/* ------- Modal ------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,24,36,0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 24px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 24px; box-shadow: 0 24px 80px rgba(0,0,0,0.24); }
.modal.modal-sm { max-width: 400px; }
.modal .hint-row { color: #8a92a3; font-size: 12px; line-height: 1.6; background: #f5f7fb; border-radius: 8px; padding: 10px 12px; }
.modal h3 { margin: 0 0 16px; }
.modal .row { margin-bottom: 14px; }
.modal label { display: block; font-size: 12px; color: #6b7285; margin-bottom: 6px; font-weight: 500; }
.modal input[type=text], .modal input[type=url], .modal input[type=number], .modal textarea, .modal select { width: 100%; padding: 8px 10px; border: 1px solid #d8dce6; border-radius: 8px; font-size: 14px; font-family: inherit; }
.modal textarea { min-height: 60px; resize: vertical; }
.modal input:focus, .modal textarea:focus, .modal select:focus { outline: none; border-color: #5b7cfa; }
.modal .radios { display: flex; gap: 8px; }
.modal .radios label { flex: 1; border: 1px solid #d8dce6; border-radius: 8px; padding: 10px; cursor: pointer; display: flex; align-items: center; gap: 8px; margin: 0; }
.modal .radios label.checked { border-color: #5b7cfa; background: #eef0ff; color: #4854e5; }
.modal .radios input { margin: 0; }
.modal .radios label > span { display: flex; flex-direction: column; line-height: 1.35; }
.modal .radios label strong { font-size: 13px; font-weight: 600; color: inherit; }
.modal .radios label em { font-style: normal; font-size: 11px; color: #8a92a3; margin-top: 2px; }
.modal .radios label.checked em { color: #6b7cd0; }
.modal .upload-row { display: flex; align-items: center; gap: 12px; }
.modal .thumb-preview { width: 56px; height: 56px; border-radius: 10px; background: #f5f7fb; display: flex; align-items: center; justify-content: center; overflow: hidden; color: #8a92a3; font-size: 11px; }
.modal .thumb-preview img { width: 100%; height: 100%; object-fit: cover; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal .error { color: #c74848; font-size: 12px; margin-top: 8px; }

/* ------- Confirm dialog ------- */
.modal.modal-confirm { max-width: 380px; padding: 24px; }
.modal-confirm .confirm-icon { width: 44px; height: 44px; border-radius: 50%; background: #fdeeee; color: #c74848; display: flex; align-items: center; justify-content: center; font-size: 22px; margin: 0 auto 12px; }
.modal-confirm h3 { text-align: center; margin: 0 0 8px; font-size: 16px; }
.modal-confirm .confirm-body { text-align: center; color: #6b7285; font-size: 13px; line-height: 1.6; margin: 0 0 20px; }
.modal-confirm .confirm-body strong { color: #1a1f2e; }
.modal-confirm .actions { justify-content: center; gap: 10px; margin-top: 0; }
.modal-confirm .actions button { min-width: 96px; padding: 8px 14px; font-size: 13px; }
.modal-confirm .danger-btn.solid { background: #d94848; border-color: #d94848; color: #fff; }
.modal-confirm .danger-btn.solid:hover { background: #c74848; border-color: #c74848; }

/* ------- Stats section ------- */
.stats-section { background: #fff; border-radius: 16px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 12px rgba(20,24,60,0.04); }
.stats-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: #f5f7fb; border: 1px solid transparent; color: #4a5060; padding: 5px 12px; border-radius: 999px; font-size: 12px; cursor: pointer; }
.chip:hover { background: #eef0f4; }
.chip.active { background: #eef0ff; border-color: #c8d0ff; color: #4854e5; font-weight: 600; }
.stats-custom-range { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 12px; color: #6b7285; }
.stats-custom-range input[type=date] { border: 1px solid #d8dce6; border-radius: 8px; padding: 6px 10px; font-size: 13px; font-family: inherit; }
.stats-summary { display: flex; align-items: baseline; gap: 12px; margin: 16px 0 4px; }
.stats-summary-label { color: #6b7285; font-size: 12px; }
.stats-summary-value { font-size: 24px; font-weight: 700; color: #1a1f2e; }
.stats-summary-range { color: #8a92a3; font-size: 12px; margin-left: auto; }
.stats-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.stats-table th { text-align: left; padding: 10px 12px; font-size: 12px; color: #8a92a3; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid #eef0f4; }
.stats-table td { padding: 10px 12px; border-bottom: 1px solid #f5f7fb; font-size: 14px; }
.stats-table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.stats-table .muted { color: #8a92a3; }
.stats-empty { text-align: center; padding: 32px 20px; color: #8a92a3; font-size: 13px; }
.stats-loading { text-align: center; padding: 24px; color: #8a92a3; font-size: 13px; }

/* ------- Login error notice ------- */
.login-error { margin-top: 16px; background: #fdeeee; color: #c74848; border-radius: 10px; padding: 12px 14px; font-size: 13px; line-height: 1.5; text-align: left; }
.login-error strong { display: block; margin-bottom: 4px; color: #a63a3a; }

@media (max-width: 720px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { max-height: 200px; }
  .content { padding: 16px; }
  .stats-summary { flex-wrap: wrap; }
  .stats-summary-range { margin-left: 0; width: 100%; }
  .stats-custom-range { flex-wrap: wrap; }
  .embed-block pre { font-size: 11px; }
  .products-table th, .products-table td { padding: 8px 6px; font-size: 12px; }
}

/* Narrow phones: shrink modal chrome and let radios stack */
@media (max-width: 560px) {
  .modal-backdrop {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    max-height: min(92dvh, calc(100dvh - 24px));
    padding: 18px 18px 20px;
    border-radius: 18px 18px 12px 12px;
  }
  .modal.modal-sm { max-width: 100%; }
  .modal.modal-confirm { max-width: 100%; }
  .modal h3 { font-size: 15px; margin-bottom: 12px; }
  .modal .row { margin-bottom: 12px; }
  .modal .radios { flex-direction: column; }
  .modal .actions { flex-wrap: wrap; }
  .modal .actions button { flex: 1; min-width: 0; }
  .login-card { padding: 28px 22px; }
  .topbar { padding: 10px 14px; }
  .topbar-right { font-size: 12px; gap: 8px; }
}

/* Very short viewports (landscape phones) */
@media (max-height: 520px) {
  .modal-backdrop { align-items: flex-start; padding-top: 12px; }
  .modal { max-height: calc(100dvh - 24px); }
}
