/* ============================
   Store Visit Tool
   Mobile-first, primary: #1e3a5f
============================ */

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

:root {
  --primary: #1e3a5f;
  --primary-dark: #163050;
  --primary-light: #2a5080;
  --accent: #F4A300;
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1a2332;
  --muted: #6b7a8d;
  --border: #d1dbe6;
  --success: #27ae60;
  --danger: #e74c3c;
  --warning: #f39c12;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(30,58,95,0.10);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ===== LOGIN OVERLAY ===== */
#login-overlay {
  position: fixed; inset: 0; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
#login-overlay.hidden { display: none; }
.login-box {
  background: #fff; border-radius: 14px; padding: 40px 32px;
  width: 320px; box-shadow: 0 8px 32px rgba(0,0,0,.3); text-align: center;
}
.login-box h2 { color: var(--primary); margin-bottom: 8px; font-size: 20px; }
.login-box p { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-box input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px; margin-bottom: 12px;
  outline: none; letter-spacing: 2px; text-align: center;
}
.login-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,.15); }
.login-box button {
  width: 100%; padding: 12px; background: var(--primary); color: #fff;
  border: none; border-radius: 8px; font-size: 15px; cursor: pointer;
  font-weight: 600; transition: background .2s;
}
.login-box button:hover { background: var(--primary-light); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ===== HEADER ===== */
.sv-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--primary); color: #fff;
  padding: 0 16px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.sv-header-left { display: flex; align-items: center; gap: 10px; }
.sv-header-back {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  font-size: 18px; display: flex; align-items: center; justify-content: center;
  transition: background .2s; text-decoration: none;
}
.sv-header-back:hover { background: rgba(255,255,255,.28); }
.sv-header-title { font-size: 17px; font-weight: 700; }
.sv-header-actions { display: flex; gap: 8px; align-items: center; }
.sv-header-btn {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3);
  color: #fff; padding: 6px 12px; border-radius: 20px; cursor: pointer;
  font-size: 13px; transition: background .2s; white-space: nowrap;
}
.sv-header-btn:hover { background: rgba(255,255,255,.28); }
.sv-header-btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.sv-header-btn.accent:hover { background: #d48f00; }

/* ===== NAV TABS (pages) ===== */
.sv-page-tabs {
  display: flex; background: var(--primary-dark);
  border-bottom: 1px solid rgba(255,255,255,.15);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.sv-page-tabs::-webkit-scrollbar { display: none; }
.sv-page-tab {
  flex: 1; min-width: 80px; padding: 10px 8px; text-align: center;
  color: rgba(255,255,255,.65); font-size: 13px; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: color .2s, border-color .2s; white-space: nowrap;
}
.sv-page-tab.active { color: #fff; border-color: var(--accent); }

/* ===== MAIN CONTENT ===== */
.sv-page { display: none; padding: 16px; max-width: 600px; margin: 0 auto; }
.sv-page.active { display: block; }

/* ===== CARD ===== */
.sv-card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.sv-card-title {
  font-size: 14px; font-weight: 700; color: var(--primary);
  margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}
.sv-card-title .icon { font-size: 16px; }

/* ===== FORM ===== */
.sv-form-group { margin-bottom: 14px; }
.sv-form-group:last-child { margin-bottom: 0; }
.sv-label {
  display: block; font-size: 12px; color: var(--muted);
  font-weight: 600; margin-bottom: 5px; text-transform: uppercase; letter-spacing: .5px;
}
.sv-input, .sv-select, .sv-textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 14px; color: var(--text);
  background: #fff; outline: none; transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
}
.sv-input:focus, .sv-select:focus, .sv-textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,.1);
}
.sv-textarea { resize: vertical; min-height: 72px; }
.sv-select { cursor: pointer; }

.sv-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 360px) { .sv-form-row { grid-template-columns: 1fr; } }

/* ===== CHECKBOX MULTI-SELECT ===== */
.sv-checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.sv-checkbox-item { display: flex; align-items: center; gap: 5px; }
.sv-checkbox-item input[type="checkbox"] { display: none; }
.sv-checkbox-label {
  display: inline-block; padding: 6px 12px; border-radius: 20px;
  border: 1px solid var(--border); font-size: 13px; cursor: pointer;
  color: var(--muted); background: #fff; transition: all .2s; user-select: none;
}
.sv-checkbox-item input:checked + .sv-checkbox-label {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

/* ===== RADIO GROUP (single select) ===== */
.sv-radio-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.sv-radio-item { display: flex; align-items: center; gap: 5px; }
.sv-radio-item input[type="radio"] { display: none; }
.sv-radio-label {
  display: inline-block; padding: 6px 12px; border-radius: 20px;
  border: 1px solid var(--border); font-size: 13px; cursor: pointer;
  color: var(--muted); background: #fff; transition: all .2s; user-select: none;
}
.sv-radio-item input:checked + .sv-radio-label {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

/* ===== CATEGORY TABS ===== */
.sv-cat-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.sv-cat-tabs::-webkit-scrollbar { display: none; }
.sv-cat-tab {
  flex: 1; min-width: 80px; padding: 10px 8px; text-align: center;
  font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--muted); border-bottom: 2px solid transparent;
  transition: all .2s; white-space: nowrap;
}
.sv-cat-tab.active { color: var(--primary); border-color: var(--primary); }

.sv-cat-panel { display: none; }
.sv-cat-panel.active { display: block; }

/* ===== IMAGE UPLOAD ===== */
.sv-img-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 6px; }
.sv-img-slot {
  aspect-ratio: 1; border-radius: 8px; border: 2px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; position: relative; background: #fafbfc;
  transition: border-color .2s;
}
.sv-img-slot:hover { border-color: var(--primary); }
.sv-img-slot .plus { font-size: 22px; color: var(--muted); line-height: 1; }
.sv-img-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sv-img-slot .sv-img-del {
  position: absolute; top: 3px; right: 3px;
  background: rgba(0,0,0,.55); color: #fff;
  width: 20px; height: 20px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 13px;
  cursor: pointer; z-index: 2; border: none;
}
.sv-img-input { display: none; }

/* ===== BUTTONS ===== */
.sv-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 20px; border-radius: 8px; font-size: 14px; font-weight: 600;
  cursor: pointer; border: none; transition: all .2s; white-space: nowrap;
}
.sv-btn-primary { background: var(--primary); color: #fff; }
.sv-btn-primary:hover { background: var(--primary-light); }
.sv-btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.sv-btn-accent { background: var(--accent); color: #fff; }
.sv-btn-accent:hover { background: #d48f00; }
.sv-btn-accent:disabled { opacity: .5; cursor: not-allowed; }
.sv-btn-ghost {
  background: transparent; color: var(--primary);
  border: 1px solid var(--primary);
}
.sv-btn-ghost:hover { background: rgba(30,58,95,.06); }
.sv-btn-danger { background: var(--danger); color: #fff; }
.sv-btn-danger:hover { background: #c0392b; }
.sv-btn-sm { padding: 7px 14px; font-size: 13px; }
.sv-btn-full { width: 100%; }

.sv-btn-row { display: flex; gap: 10px; margin-top: 16px; }
.sv-btn-row .sv-btn { flex: 1; }

/* ===== STICKY BOTTOM BAR ===== */
.sv-bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff; border-top: 1px solid var(--border);
  padding: 12px 16px; display: flex; gap: 10px;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08); z-index: 50;
}
.sv-bottom-bar .sv-btn { flex: 1; }

/* ===== HISTORY LIST ===== */
.sv-record-item {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px;
  box-shadow: var(--shadow); cursor: pointer;
  border: 2px solid transparent; transition: border-color .2s, box-shadow .2s;
}
.sv-record-item:hover { box-shadow: 0 4px 16px rgba(30,58,95,.15); }
.sv-record-item.selected { border-color: var(--primary); }
.sv-record-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sv-record-store {
  font-size: 14px; font-weight: 700; color: var(--primary);
  display: flex; align-items: center; gap: 6px;
}
.sv-record-date { font-size: 12px; color: var(--muted); }
.sv-record-meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.sv-record-actions { display: flex; gap: 6px; margin-top: 8px; }

.sv-badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.sv-badge-beijing { background: #e3f0fb; color: #1e3a5f; }
.sv-badge-ningbo { background: #fdf3e3; color: #b35c00; }

/* ===== FILTERS ===== */
.sv-filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.sv-filter-row .sv-select { flex: 1; min-width: 120px; }
.sv-filter-row .sv-btn { flex-shrink: 0; }

/* ===== AI RESULT ===== */
.sv-ai-result {
  background: #f7f9fd; border-radius: var(--radius);
  padding: 14px; margin-top: 12px; border: 1px solid #d1dbe6;
}
.sv-ai-section { margin-bottom: 16px; }
.sv-ai-section:last-child { margin-bottom: 0; }
.sv-ai-section-title {
  font-size: 13px; font-weight: 700; color: var(--primary);
  margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.sv-ai-item {
  display: flex; gap: 8px; margin-bottom: 6px; font-size: 13px;
}
.sv-ai-item-bullet {
  width: 18px; height: 18px; border-radius: 50%; background: var(--primary);
  color: #fff; font-size: 10px; font-weight: 700; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;
}
.sv-ai-item-text { color: var(--text); line-height: 1.5; }

/* product recognition table */
.sv-ai-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.sv-ai-table th {
  background: var(--primary); color: #fff; padding: 6px 8px;
  text-align: left; font-weight: 600;
}
.sv-ai-table td { padding: 6px 8px; border-bottom: 1px solid #e8edf2; }
.sv-ai-table tr:last-child td { border-bottom: none; }
.sv-ai-table tr:nth-child(even) td { background: #f5f7fa; }

/* ===== LOADING SPINNER ===== */
.sv-spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sv-spinner-dark {
  border-color: rgba(30,58,95,.2); border-top-color: var(--primary);
}

/* ===== TOAST ===== */
.sv-toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(30,58,95,.92); color: #fff; border-radius: 24px;
  padding: 10px 20px; font-size: 14px; z-index: 9998;
  pointer-events: none; opacity: 0;
  transition: opacity .25s; white-space: nowrap; max-width: 90vw;
}
.sv-toast.show { opacity: 1; }
.sv-toast.success { background: rgba(39,174,96,.92); }
.sv-toast.error { background: rgba(231,76,60,.92); }

/* ===== MODAL ===== */
.sv-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 9000; display: flex; align-items: flex-end; justify-content: center;
}
.sv-modal-overlay.hidden { display: none; }
.sv-modal {
  background: #fff; border-radius: 16px 16px 0 0;
  width: 100%; max-width: 600px; max-height: 85vh;
  overflow-y: auto; padding: 20px 16px 32px;
}
.sv-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.sv-modal-title { font-size: 16px; font-weight: 700; color: var(--primary); }
.sv-modal-close {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--muted); line-height: 1; padding: 0 4px;
}
.sv-modal-close:hover { color: var(--text); }

/* ===== EMPTY STATE ===== */
.sv-empty {
  text-align: center; padding: 40px 16px; color: var(--muted);
}
.sv-empty-icon { font-size: 40px; margin-bottom: 10px; }
.sv-empty-text { font-size: 14px; }

/* ===== COMPARE SELECT BAR ===== */
.sv-compare-bar {
  background: var(--primary); color: #fff;
  padding: 10px 16px; border-radius: var(--radius);
  margin-bottom: 12px; display: flex; align-items: center;
  justify-content: space-between; gap: 10px;
}
.sv-compare-info { font-size: 13px; flex: 1; }
.sv-compare-count {
  font-size: 18px; font-weight: 700; color: var(--accent);
  margin-right: 6px;
}

/* ===== DIVIDER ===== */
.sv-divider { height: 1px; background: var(--border); margin: 14px 0; }

/* ===== SECTION HEADING ===== */
.sv-section-heading {
  font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .7px;
  margin-bottom: 10px; margin-top: 4px;
}

/* ===== NOTE: general info note ===== */
.sv-note {
  background: #eaf2fb; border-left: 3px solid var(--primary);
  border-radius: 4px; padding: 8px 10px; font-size: 12px; color: var(--primary-light);
  margin-bottom: 12px;
}
