/* Be Vietnam Pro — hỗ trợ tiếng Việt, an toàn đa nền tảng */
@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800;900&display=swap');

:root {
  --brand: #c62828;
  --text-on-hero: #fff;
  --btn-border: rgba(255,255,255,.65);
  --btn-bg: rgba(255,255,255,.96);
  --btn-bg-hover: #ffe5e5;
  --tap: 38px; /* tap-target tối thiểu cho mobile */

  /* easing + thời lượng hiệu ứng */
  --ease-out: cubic-bezier(.2,.7,.3,1);
  --spin-dur: 8s; /* 5 giây 1 vòng cho logo + sweep */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== HEADER ===== */
.site-header {
  position: sticky;             /* bám trên cùng khi cuộn */
  top: 0;
  z-index: 1000;
  isolation: isolate;           /* tách overlay với nội dung */
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: url('/banner/banner.png') no-repeat center center / cover, var(--brand);
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 10px 12px; /* safe-area + gọn hơn */
  color: var(--text-on-hero);
  gap: 10px;                    /* tránh dính nhau khi wrap */
  border-bottom: 1px solid rgba(0,0,0,.06);
}

/* Đảm bảo nội dung nằm trên overlay */
.site-header > * {
  position: relative;
  z-index: 1;
}

/* Lớp phủ nhẹ cải thiện độ tương phản chữ trên ảnh banner */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, rgba(0,0,0,.18), rgba(0,0,0,.18));
  z-index: 0; /* overlay nằm dưới nội dung */
}

/* Logo + text (trái) */
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;        /* ƯU TIÊN chỗ cho brand */
  min-width: 0;          /* để text có thể ellipsis */
}

.logo-img {
  width: 60px;           /* TO HƠN */
  height: 60px;
  border-radius: 50%;
  background: #fff;
  padding: 4px;          /* VIỀN TRẮNG MỎNG HƠN */
  object-fit: cover;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
  flex: 0 0 auto;

  /* Hiệu ứng xuất hiện + xoay liên tục */
  will-change: transform, opacity, filter;
  animation:
    brand-pop .6s var(--ease-out) .05s both,
    logo-spin var(--spin-dur) linear infinite;
  transition: transform 120ms ease;
}
.header-left:hover .logo-img,
.header-left:active .logo-img {
  transform: scale(1.04);
}

/* Brand text */
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
  flex: 1 1 auto;

  /* từng dùng cho tia sáng; giữ để không ảnh hưởng layout */
  position: relative;
  overflow: hidden;
}

/* Tên “Liên Kết 24h” — TO HƠN, co giãn mượt */
.brand-name {
  font-size: clamp(22px, 6.4vw, 26px);
  font-weight: 900;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: .2px;
  text-shadow: 0 1px 1px rgba(0,0,0,.25);

  /* Hiệu ứng xuất hiện */
  will-change: transform, opacity;
  animation: brand-slide .7s var(--ease-out) .12s both;
}

/* Slogan — TO HƠN đồng loạt, giữ 2 dòng khi cần */
.brand-tagline {
  font-size: clamp(13.5px, 3.8vw, 15px);
  color: rgba(255,255,255,0.94);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 1; /* mobile chỉ 1 dòng mặc định */

  /* Hiệu ứng xuất hiện */
  will-change: opacity, transform;
  animation: brand-fade .8s var(--ease-out) .2s both;
}

/* Bên phải header */
.header-right {
  display: flex;
  align-items: center;
  flex: 0 1 auto;        /* cho phép BÊN PHẢI co lại */
  min-width: 120px;
  max-width: 48vw;       /* tránh lấn hết chỗ của brand */
  gap: 8px;              /* desktop/tablet có khoảng cách nhẹ */
}

/* Đặt thứ tự để có thể gom 2 nút thành segmented pill trên mobile */
#updateLocationBtn { order: 1; }
#viewLocationBtn   { order: 2; }
#headerLocation    { order: 3; }

#headerLocation {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-align: right;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0,0,0,.25);
}

/* ===== Buttons ===== */
.btn {
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--brand);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  text-align: center;
  font-family: inherit;
  min-height: var(--tap);
  box-shadow: 0 1px 1px rgba(0,0,0,.04);
  transition: background .15s ease, transform .05s ease;
}

.btn:hover { background: var(--btn-bg-hover); }
.btn:active { transform: translateY(1px); }
.btn-outline { /* giữ class cũ để tương thích */
  border-color: var(--btn-border);
}

/* Nút xem vị trí (giữ nhỏ hơn 1 nhịp) */
#viewLocationBtn {
  font-size: 13px;
  padding: 8px 12px;
}

/* ===== OVERLAY + DIALOG ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
}

.dialog {
  background: #fff;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1100;
  width: 92%;
  max-width: 600px;
}

.dialog h2 {
  margin-top: 0;
  font-size: 20px;
  color: var(--brand);
}

.location-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.btn-action {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--brand);
  background: #fff;
  color: var(--brand);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

.btn-action:hover {
  background: #ffebee;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.btn-save {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

.btn-cancel {
  background: #eee;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

.suggestions {
  border: 1px solid #ddd;
  background: #fafafa;
  margin-top: 4px;
  max-height: 150px;
  overflow-y: auto;
}
.suggestions div {
  padding: 6px 10px;
  cursor: pointer;
}
.suggestions div:hover {
  background: #eee;
}

/* ===== RESPONSIVE ===== */

/* Màn rất nhỏ: bố cục dọc — Brand (logo + tên + 2 dòng slogan) → Tọa độ → 2 nút (segmented) */
@media (max-width: 480px) {
  /* Header xếp dọc, brand ở trên cùng */
  .site-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: calc(env(safe-area-inset-top, 0px) + 6px) 10px 8px 10px;
  }

  .logo-img { width: 58px; height: 58px; padding: 3px; } /* to hơn + viền mỏng hơn mobile */

  .header-left {
    order: 1;
    width: 100%;
  }

  /* Slogan đủ 2 dòng (mỗi .brand-tagline là 1 dòng) và TO HƠN */
  .brand-name { font-size: clamp(22px, 7vw, 26px); }
  .brand-tagline {
    -webkit-line-clamp: unset;   /* bỏ clamp 1 dòng ở mobile */
    display: block;
    white-space: normal;
    line-height: 1.28;
    font-size: 14px;             /* tăng cỡ slogan mobile */
  }

  /* Khối bên phải: width 100%, nằm dưới brand */
  .header-right {
    order: 2;
    width: 100%;
    max-width: none;     /* chiếm toàn bộ bề ngang */
    flex-wrap: wrap;
    gap: 0;              /* để 2 nút khít nhau như segmented */
    margin-top: 6px;
  }

  /* (1) Tọa độ — nằm ngay dưới brand, full width */
  #headerLocation {
    order: 1;
    flex-basis: 100%;
    width: 100%;
    text-align: left;
    font-size: 12.5px;
    opacity: .95;
    margin: 2px 0 6px 0; /* tạo khoảng cách với nhóm nút */
  }

  /* (2) Hai nút — hàng dưới, dạng segmented pill */
  #updateLocationBtn,
  #viewLocationBtn {
    order: 2;
    min-height: var(--tap, 38px);
    padding: 8px 12px;
    font-size: 12.5px;
    border-radius: 999px; /* bo tròn tổng thể */
  }

  /* Segment trái/phải + chung 1 nhóm viền */
  #updateLocationBtn {
    border-right: none;
    border-radius: 999px 0 0 999px;  /* trái */
  }
  #viewLocationBtn {
    border-left: 1px solid var(--btn-border);
    border-radius: 0 999px 999px 0;  /* phải */
  }

  /* Mặc định mỗi nút full-width (fallback).
     Khi cả hai cùng hiển thị → chia đôi 50/50 */
  .header-right:has(#viewLocationBtn:not([hidden])) #updateLocationBtn,
  .header-right:has(#viewLocationBtn:not([hidden])) #viewLocationBtn {
    flex: 1 1 calc(50% - 0px); /* khít nhau để giống segmented */
  }

  /* Thu gọn chữ bằng pseudo — vẫn giữ icon + nhãn ngắn gọn */
  #updateLocationBtn,
  #viewLocationBtn {
    position: relative;
    color: transparent;             /* ẩn text gốc để tránh dài */
  }
  #updateLocationBtn::after,
  #viewLocationBtn::after {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 0 12px;
    color: var(--brand);
    font-weight: 800;
    letter-spacing: .1px;
  }
  #updateLocationBtn::after { content: "📍 Cập nhật"; }
  #viewLocationBtn::after   { content: "🔎 Xem vị trí"; }

  /* Liên kết/nút quản trị (Expert) – tự xuống dưới 2 nút nếu có */
  .header-right > a.btn {
    order: 4;
    flex: 0 1 auto;
    margin-top: 6px;
  }
}

/* Màn rất nhỏ hơn nữa: chỉ giữ icon nếu bề ngang quá hẹp */
@media (max-width: 360px) {
  #updateLocationBtn::after { content: "📍"; }
  #viewLocationBtn::after   { content: "🔎"; }
  #headerLocation { font-size: 12px; }
}

/* Tablet (≥768px) — thoáng hơn, vẫn giữ cân đối */
@media (min-width: 768px) {
  .site-header { padding: calc(env(safe-area-inset-top, 0px) + 10px) 20px 12px 20px; }
  .logo-img { width: 72px; height: 72px; padding: 5px; } /* TO HƠN nhưng viền vẫn mỏng */
  .brand-name { font-size: clamp(24px, 3.2vw, 30px); }   /* tăng */
  .brand-tagline {
    font-size: clamp(14px, 2.4vw, 16.5px);              /* tăng */
    -webkit-line-clamp: 2; /* tablet cho phép 2 dòng */
  }
  .header-right { max-width: 50vw; gap: 8px; }
  #headerLocation { font-size: 14px; order: 3; flex-basis: auto; width: auto; margin: 0; text-align: right; }
  .btn { font-size: 15px; padding: 9px 14px; min-height: 40px; }
  #viewLocationBtn { font-size: 14px; }

  /* Trả text nút về bình thường ở tablet trở lên */
  #updateLocationBtn, #viewLocationBtn { color: var(--brand); position: static; }
  #updateLocationBtn::after, #viewLocationBtn::after { content: none; }
}

/* Desktop (≥1024px) — chuyên nghiệp, thoáng */
@media (min-width: 1024px) {
  .site-header { padding: calc(env(safe-area-inset-top, 0px) + 12px) 28px 14px 28px; }
  .logo-img { width: 84px; height: 84px; padding: 5px; }  /* TO HƠN, viền mỏng */
  .brand-name { font-size: clamp(26px, 2.4vw, 34px); }     /* tăng */
  .brand-tagline { font-size: clamp(15px, 1.8vw, 18px); }  /* tăng */
  .header-right { max-width: 40vw; }
  #headerLocation { font-size: 15px; }
  .btn { font-size: 16px; padding: 10px 16px; min-height: 42px; }
  #viewLocationBtn { font-size: 15px; }
  .dialog h2 { font-size: 22px; }
}

/* ====== Animations ====== */
@keyframes brand-pop {
  0%   { transform: scale(.92); filter: blur(1px); opacity: 0; }
  60%  { transform: scale(1.02); filter: blur(0); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes brand-slide {
  0%   { transform: translateY(8px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes brand-fade {
  0%   { opacity: 0 }
  100% { opacity: 1 }
}

/* Logo xoay quanh tâm */
@keyframes logo-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Tôn trọng người dùng hạn chế chuyển động */
@media (prefers-reduced-motion: reduce) {
  .logo-img, .brand-name, .brand-tagline {
    animation: none !important;
    transition: none !important;
  }
}
