/* ============================================================
   TagFind — Design tokens & base styles
   Phong cách: "Pro nhưng ấm áp" — xanh dương/ngọc làm chủ đạo, tin cậy;
   đỏ/cam nhấn riêng cho trạng thái "đang mất" để tạo cảm giác khẩn cấp.
   Nền sáng là mặc định (dễ đọc ngoài trời khi quét NFC thực tế).
   QUAN TRỌNG: không gán cứng color đen — luôn dùng biến --color-text.
   ============================================================ */

:root {
  /* Màu nền & bề mặt */
  --color-bg: #F6FAF9;
  --color-surface: #FFFFFF;
  --color-surface-alt: #EEF5F4;
  --color-border: #DCE8E6;

  /* Màu thương hiệu — xanh ngọc/dương: tin cậy */
  --color-primary: #0E7C86;
  --color-primary-dark: #0A5F68;
  --color-primary-light: #E3F3F2;
  --color-primary-contrast: #FFFFFF;

  /* Màu nhấn khẩn cấp — dùng riêng cho trạng thái "đang mất" */
  --color-urgent: #E1552B;
  --color-urgent-dark: #B8431F;
  --color-urgent-light: #FDECE5;

  /* Trạng thái phụ */
  --color-success: #2E9E6D;
  --color-success-light: #E4F5EC;
  --color-warning: #C98A12;
  --color-warning-light: #FBF1DE;

  /* Chữ */
  --color-text: #142B29;
  --color-text-secondary: #5A716E;
  --color-text-muted: #8A9C9A;
  --color-text-on-primary: #FFFFFF;
  --color-text-on-urgent: #FFFFFF;

  --font-display: 'Be Vietnam Pro', 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', 'Be Vietnam Pro', system-ui, sans-serif;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(20, 43, 41, 0.04), 0 6px 20px rgba(20, 43, 41, 0.06);
  --shadow-nav: 0 -2px 16px rgba(20, 43, 41, 0.06);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --nav-height: 64px;
  --header-height: 56px;
}

/* Dark mode: tuỳ chọn phụ, không đặt mặc định — bật qua data-theme="dark" trên <html> */
:root[data-theme='dark'] {
  --color-bg: #0F1C1B;
  --color-surface: #16302E;
  --color-surface-alt: #1C3936;
  --color-border: #2A4A47;
  --color-primary-light: #1D3F3C;
  --color-urgent-light: #3A241D;
  --color-success-light: #1C3A2E;
  --color-warning-light: #3A3120;
  --color-text: #EAF3F1;
  --color-text-secondary: #AEC4C1;
  --color-text-muted: #7E9895;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--color-text);
  margin: 0 0 var(--space-2);
  line-height: 1.25;
}
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 var(--space-3); color: var(--color-text-secondary); line-height: 1.55; }
a { color: var(--color-primary); text-decoration: none; }
small { color: var(--color-text-muted); }

img { max-width: 100%; display: block; }

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

/* ---------------- App shell ---------------- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--color-primary-dark);
  font-size: 1.05rem;
}
.app-header .brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--color-primary);
}

.app-main {
  flex: 1;
  padding: var(--space-4) var(--space-4) calc(var(--nav-height) + var(--space-6));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: var(--shadow-nav);
  display: flex;
  z-index: 30;
  max-width: 640px;
  margin: 0 auto;
}
.bottom-nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  padding: var(--space-1) 0;
}
.bottom-nav .nav-item .icon { font-size: 1.25rem; line-height: 1; }
.bottom-nav .nav-item.active { color: var(--color-primary); }

/* ---------------- Cards & layout helpers ---------------- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }

.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--color-text-muted);
}
.empty-state .emoji { font-size: 2.4rem; margin-bottom: var(--space-2); }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: none;
  border-radius: var(--radius-pill);
  padding: 12px 20px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); color: var(--color-text-on-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary { background: var(--color-primary-light); color: var(--color-primary-dark); }

.btn-outline { background: transparent; color: var(--color-text); border: 1.5px solid var(--color-border); }

.btn-urgent { background: var(--color-urgent); color: var(--color-text-on-urgent); }
.btn-urgent:hover { background: var(--color-urgent-dark); }

.btn-ghost { background: transparent; color: var(--color-primary); width: auto; padding: 8px 4px; }

.btn-sm { padding: 8px 14px; font-size: 0.82rem; width: auto; }
.btn-block-group { display: flex; gap: var(--space-3); }

/* ---------------- Forms ---------------- */

.field { margin-bottom: var(--space-4); }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.95rem;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.field textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: 0.78rem; color: var(--color-text-muted); margin-top: var(--space-1); }
.field-error { font-size: 0.78rem; color: var(--color-urgent); margin-top: var(--space-1); }

.checkbox-row { display: flex; align-items: center; gap: var(--space-2); }
.checkbox-row input { width: auto; }

/* ---------------- Badges / status pills ---------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 700;
}
.badge-normal { background: var(--color-success-light); color: var(--color-success); }
.badge-lost { background: var(--color-urgent-light); color: var(--color-urgent); }
.badge-inactive { background: var(--color-surface-alt); color: var(--color-text-muted); }
.badge-pending { background: var(--color-warning-light); color: var(--color-warning); }

/* ---------------- Product grid ---------------- */

.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
.product-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  cursor: pointer;
}
.product-card .thumb {
  aspect-ratio: 1;
  background: var(--color-surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  overflow: hidden;
}
.product-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-card .info { padding: var(--space-3); }
.product-card .name { font-weight: 700; font-size: 0.9rem; margin-bottom: 2px; }
.product-card .price { color: var(--color-primary-dark); font-weight: 800; font-size: 0.95rem; }
.product-card .type-tag { font-size: 0.68rem; color: var(--color-text-muted); }

/* ---------------- Tag public page (/t/:id) ---------------- */

.tag-hero {
  text-align: center;
  padding: var(--space-6) var(--space-4) var(--space-5);
}
.tag-hero .avatar {
  width: 120px; height: 120px;
  border-radius: 50%;
  margin: 0 auto var(--space-4);
  background: var(--color-primary-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem;
  overflow: hidden;
  border: 4px solid var(--color-surface);
  box-shadow: var(--shadow-card);
}
.tag-hero .avatar img { width: 100%; height: 100%; object-fit: cover; }
.tag-hero.is-lost .avatar { border-color: var(--color-urgent); }

.lost-banner {
  background: var(--color-urgent);
  color: var(--color-text-on-urgent);
  text-align: center;
  padding: 10px var(--space-4);
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-4);
}

.contact-buttons { display: flex; flex-direction: column; gap: var(--space-3); }

/* ---------------- Messages ---------------- */

.message-item {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt);
  margin-bottom: var(--space-2);
}
.message-item .meta { font-size: 0.72rem; color: var(--color-text-muted); margin-top: 4px; }

/* ---------------- Admin table ---------------- */

.admin-list-item {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-card);
}
.admin-search {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.admin-search input { flex: 1; }

/* ---------------- Toast ---------------- */

.toast-root {
  position: fixed;
  top: calc(var(--header-height) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(90vw, 420px);
}
.toast {
  background: var(--color-text);
  color: var(--color-bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  box-shadow: var(--shadow-card);
  animation: toast-in 0.2s ease;
}
.toast.toast-error { background: var(--color-urgent); color: var(--color-text-on-urgent); }
.toast.toast-success { background: var(--color-success); color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- Misc ---------------- */

.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--color-primary-light);
  border-top-color: var(--color-primary);
  animation: spin 0.7s linear infinite;
  margin: var(--space-6) auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.divider { height: 1px; background: var(--color-border); margin: var(--space-4) 0; }

.lang-switch {
  display: flex;
  gap: 4px;
  background: var(--color-surface-alt);
  border-radius: var(--radius-pill);
  padding: 3px;
}
.lang-switch button {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-text-muted);
  cursor: pointer;
}
.lang-switch button.active {
  background: var(--color-surface);
  color: var(--color-primary-dark);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.image-picker {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.image-picker .preview {
  width: 72px; height: 72px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  font-size: 1.6rem;
}
.image-picker .preview img { width: 100%; height: 100%; object-fit: cover; }

.link-plain { color: var(--color-primary); font-weight: 600; }

@media (min-width: 700px) {
  .app-main { padding-left: var(--space-6); padding-right: var(--space-6); }
}
