/* =========================================================
   GIAO DIỆN TRANG
   ========================================================= */
:root {
  --teal: #1f8a80;
  --teal-d: #136a62;
  --ink: #18272a;
  --muted: #6b7b7d;
  --line: #dfe8e7;
  --bg: #f3f7f6;
  --radius: 14px;
  --sans: 'Be Vietnam Pro', system-ui, sans-serif;
  --serif: 'Noto Serif', Georgia, serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); color: var(--ink); background: var(--bg); }
a { color: var(--teal-d); }

.topnav {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px); background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topnav .brand { font-weight: 700; text-decoration: none; color: var(--ink); font-size: 17px; }
.topnav .links { display: flex; gap: 4px; }
.topnav .links a { text-decoration: none; color: var(--muted); padding: 8px 14px; border-radius: 999px; font-weight: 500; font-size: 14px; }
.topnav .links a.on, .topnav .links a:hover { background: #e4f2f0; color: var(--teal-d); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px) 60px; }
.page-title { font-size: clamp(22px, 3vw, 30px); margin: 0 0 6px; }
.lead { color: var(--muted); margin: 0 0 22px; max-width: 680px; line-height: 1.55; }
.section-title { margin: 34px 0 14px; }
.hint { color: var(--muted); font-size: 13px; text-align: center; }
.muted { color: var(--muted); }
.center { text-align: center; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }

.create-grid { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 28px; align-items: start; }
.preview-sticky { position: sticky; top: 84px; display: grid; gap: 12px; justify-items: center; }
@media (max-width: 900px) {
  .create-grid { grid-template-columns: 1fr; }
  .preview-col { order: -1; }
  .preview-sticky { position: static; }
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fld { display: grid; gap: 6px; }
.fld.full, .full { grid-column: 1 / -1; }
.fld > span { font-size: 13px; font-weight: 600; color: #3b4b4d; }
.fld small { font-weight: 400; color: var(--muted); }
input, select {
  width: 100%; font: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid #cfdcda;
  border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid #9fd6cf; border-color: var(--teal); }
input[type=file] { padding: 8px; background: #f7faf9; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: auto; }

fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend { font-weight: 700; color: var(--teal-d); margin-bottom: 10px; font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 14px; padding: 11px 18px; border-radius: 10px;
  border: 1px solid #cfdcda; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-d); }
.btn.ghost { background: transparent; }
.btn.danger { color: #b42318; border-color: #f1c4bf; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: wait; }

.alert { padding: 14px 16px; border-radius: 12px; margin-bottom: 18px; line-height: 1.6; }
.alert.ok { background: #e6f6f1; border: 1px solid #b5e3d5; }
.alert.err { background: #fdecea; border: 1px solid #f5c2bc; color: #8a1f14; }
.code-big {
  font-family: ui-monospace, Menlo, monospace; font-size: 1.1em; font-weight: 700; letter-spacing: .06em;
  background: #e4f2f0; color: var(--teal-d); padding: 3px 10px; border-radius: 8px; display: inline-block;
}

.card-page { display: grid; justify-items: center; gap: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.actions form { margin: 0; }

.search { display: flex; gap: 10px; margin-bottom: 22px; padding: 14px; }
.search input { flex: 1; font-size: 16px; text-transform: uppercase; }
.search input::placeholder { text-transform: none; }

.profile { display: grid; grid-template-columns: 280px 1fr; gap: 28px; }
.profile-photo img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 14px; display: block; }
.profile-info h2 { font-size: 32px; margin: 6px 0 10px; font-family: var(--serif); }
.verified { color: #12805c; font-weight: 600; font-size: 14px; }
.profile dl { display: grid; grid-template-columns: max-content 1fr; gap: 10px 22px; margin: 22px 0 0; }
.profile dt { color: var(--muted); font-size: 14px; }
.profile dt small { display: block; font-style: italic; font-size: 12px; }
.profile dd { margin: 0; font-weight: 600; }
@media (max-width: 700px) { .profile { grid-template-columns: 1fr; } .profile-photo { max-width: 260px; } }

.login { max-width: 420px; margin: 40px auto; display: grid; gap: 14px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500; font-size: 14px; background: #fff; border: 1px solid var(--line); }
.tabs a.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.table-wrap { overflow-x: auto; padding: 0; }
.list { width: 100%; border-collapse: collapse; font-size: 14px; }
.list th, .list td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.list th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.thumb { width: 40px; height: 52px; object-fit: cover; border-radius: 6px; display: block; }

/* =========================================================
   THẺ CĂN CƯỚC — mọi kích thước tính theo chiều rộng thẻ (cqw)
   nên thẻ co giãn đúng tỉ lệ ở mọi màn hình.
   ========================================================= */
.card-holder { width: 100%; max-width: 860px; container-type: inline-size; }

/* Tông vàng kem – hoa văn đỏ. Đổi màu toàn thẻ chỉ cần sửa các biến dưới đây */
.pet-card {
  --c-red: #b3121f;
  --c-red-d: #7e0c16;
  --c-gold: #c99a2e;
  --c-cream: #fff8e7;
  --c-ink: #24140e;
  --c-label: #5b4334;
  --c-accent: var(--c-red);
  position: relative; width: 100%; aspect-ratio: 85.6 / 54; overflow: hidden;
  border-radius: 4.2cqw; color: var(--c-ink);
  background:
    radial-gradient(55% 75% at 92% 88%, rgba(240, 196, 120, .45), transparent 70%),
    radial-gradient(45% 60% at 6% 72%, rgba(250, 220, 160, .45), transparent 70%),
    linear-gradient(160deg, #fffbf1 0%, #fcf1d6 55%, #f6e3b4 100%);
  box-shadow: 0 1.5cqw 4cqw rgba(120, 60, 20, .2), 0 0 0 .12cqw rgba(179, 18, 31, .25);
  font-family: var(--sans);
}
/* khung viền đỏ kép bên trong thẻ */
.pet-card::after {
  content: ''; position: absolute; inset: 1cqw; border-radius: 3.3cqw; pointer-events: none; z-index: 3;
  border: .22cqw solid rgba(179, 18, 31, .55);
  box-shadow: inset 0 0 0 .45cqw rgba(255, 248, 231, .0), inset 0 0 0 .62cqw rgba(179, 18, 31, .25);
}
/* hoa văn guilloche đỏ */
.pc-guilloche {
  position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='44'%3E%3Cg fill='none' stroke-width='.7'%3E%3Cpath d='M0 22C20 0 60 0 80 22S140 44 160 22' stroke='%23c8323c'/%3E%3Cpath d='M0 22C20 44 60 44 80 22S140 0 160 22' stroke='%23e48a6a'/%3E%3Cpath d='M0 0C20 22 60 22 80 0M80 44C100 22 140 22 160 44' stroke='%23c8323c' opacity='.55'/%3E%3Cpath d='M0 44C20 22 60 22 80 44M80 0C100 22 140 22 160 0' stroke='%23e48a6a' opacity='.55'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 19cqw 5.2cqw;
  -webkit-mask-image: linear-gradient(90deg, #000 0%, rgba(0,0,0,.45) 45%, #000 100%);
          mask-image: linear-gradient(90deg, #000 0%, rgba(0,0,0,.45) 45%, #000 100%);
}
/* dấu chân mờ chìm phía sau */
.pc-body::before {
  content: ''; position: absolute; right: 3cqw; top: 10cqw; width: 21cqw; height: 21cqw; pointer-events: none; opacity: .055;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' fill='%23b3121f'%3E%3Cellipse cx='32' cy='43' rx='13' ry='11'/%3E%3Cellipse cx='14' cy='27' rx='5.5' ry='7' transform='rotate(-20 14 27)'/%3E%3Cellipse cx='25' cy='15' rx='5.5' ry='7.5' transform='rotate(-6 25 15)'/%3E%3Cellipse cx='39' cy='15' rx='5.5' ry='7.5' transform='rotate(6 39 15)'/%3E%3Cellipse cx='50' cy='27' rx='5.5' ry='7' transform='rotate(20 50 27)'/%3E%3C/svg%3E") center / contain no-repeat;
  transform: rotate(-14deg);
}

/* đầu thẻ */
.pc-head {
  position: relative; height: 15.5cqw; display: grid; grid-template-columns: 27cqw 1fr; align-items: center;
  padding: 0 3cqw 0 3.6cqw;
  background:
    radial-gradient(70% 140% at 15% 0%, rgba(255,255,255,.7), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cg fill='none' stroke='%23b3121f' stroke-opacity='.13' stroke-width='.8'%3E%3Ccircle cx='20' cy='20' r='14'/%3E%3Ccircle cx='0' cy='0' r='14'/%3E%3Ccircle cx='40' cy='0' r='14'/%3E%3Ccircle cx='0' cy='40' r='14'/%3E%3Ccircle cx='40' cy='40' r='14'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 4.4cqw 4.4cqw,
    linear-gradient(180deg, #fff5da, #f5dc9c);
}
.pc-logo { display: flex; align-items: center; height: 100%; }
.pc-logo img { max-width: 100%; max-height: 11.5cqw; object-fit: contain; }
.pc-logo-text {
  font-family: var(--sans); font-weight: 700; font-size: 5.2cqw; letter-spacing: -.05em; line-height: 1;
  color: var(--c-red); text-shadow: 0 .15cqw 0 rgba(255,255,255,.7);
}
.pc-org { text-align: center; display: grid; gap: .55cqw; color: #3d2416; }
.pc-org strong { font-family: var(--serif); font-weight: 800; font-size: 2.7cqw; line-height: 1.15; color: var(--c-red-d); }
.pc-org span { font-size: 1.95cqw; line-height: 1.15; }
.pc-org i { font-size: 1.95cqw; line-height: 1.15; font-weight: 500; }

/* dải viền hoa văn đỏ */
.pc-band {
  position: relative; height: 1.3cqw;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M6 1 10 4 6 7 2 4Z' fill='%23fff3d6' fill-opacity='.95'/%3E%3C/svg%3E") 0 50% / 1.3cqw .9cqw repeat-x,
    linear-gradient(90deg, #8e0f1a, #c4222e 30%, #d94a3f 50%, #c4222e 70%, #8e0f1a);
  border-top: .18cqw solid var(--c-gold);
  border-bottom: .18cqw solid var(--c-gold);
  box-shadow: 0 .3cqw .6cqw rgba(120, 30, 20, .2);
}

/* thân thẻ */
.pc-body {
  position: relative; display: grid; grid-template-columns: 25cqw 1fr; gap: 3.2cqw;
  padding: 2.2cqw 3.4cqw 0 4cqw; height: calc(100% - 17.2cqw);
}
.pc-left { display: flex; flex-direction: column; gap: 1.2cqw; }
.pc-id { font-family: var(--serif); font-weight: 800; font-size: 3.2cqw; line-height: 1; white-space: nowrap; }
.pc-id b { font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; font-size: 2.15cqw; letter-spacing: .04em; color: var(--c-red); font-weight: 700; vertical-align: .25cqw; }
.pc-photo {
  width: 100%; flex: 1 1 0; min-height: 0; border-radius: 2.4cqw; overflow: hidden; background: #fff;
  display: grid; place-items: center;
  box-shadow: 0 0 0 .55cqw #fffaf0, 0 0 0 .75cqw rgba(179, 18, 31, .55), 0 .6cqw 1.8cqw rgba(120, 60, 20, .2);
}
.pc-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pc-photo-ph { color: #9a8170; font-size: 1.9cqw; }
.pc-issue { font-family: var(--serif); color: var(--c-label); padding-bottom: 2.6cqw; line-height: 1.1; flex: none; }
.pc-issue > div { font-size: 2.15cqw; font-weight: 700; white-space: nowrap; }
.pc-issue b { color: var(--c-ink); }
.pc-issue em { display: block; font-size: 1.5cqw; font-weight: 600; margin-top: .3cqw; }

.pc-main { min-width: 0; position: relative; }
.pc-main h2 {
  margin: 0; text-align: center; font-family: var(--serif); font-weight: 800; font-size: 4.7cqw;
  letter-spacing: .02em; line-height: 1.05; white-space: nowrap; color: var(--c-red-d);
}
.pc-main h3 {
  margin: .4cqw 0 1.6cqw; text-align: center; font-weight: 500; font-size: 2.55cqw; letter-spacing: .14em; color: #7a5a44; line-height: 1.1;
}
.pc-fields { display: grid; gap: .55cqw; }
.pc-fields > .pc-f { max-width: 50cqw; }
.pc-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5cqw; }
.pc-f { display: grid; grid-template-columns: 3.6cqw 1fr; align-items: center; gap: .9cqw; min-width: 0; }
.pc-paw { width: 3.4cqw; height: 3.4cqw; color: var(--c-red); opacity: .85; }
.pc-lbl { min-width: 0; line-height: 1.05; }
.pc-lbl .vi {
  font-family: var(--serif); font-size: 2.3cqw; color: var(--c-label); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pc-lbl em { display: block; font-family: var(--serif); font-size: 1.45cqw; font-weight: 600; color: #8a6a55; }
.pc-val { font-family: var(--sans); font-weight: 700; font-size: 2.15cqw; color: var(--c-ink); margin-left: .4cqw; }

/* mã QR */
.pc-qr {
  position: absolute; right: 3.2cqw; bottom: 3cqw; width: 10cqw; text-align: center; z-index: 2;
  display: grid; gap: .4cqw; justify-items: center;
}
.pc-qr-box { width: 10cqw; height: 10cqw; background: #fff; padding: .6cqw; border-radius: 1cqw; box-shadow: 0 0 0 .18cqw rgba(179, 18, 31, .45), 0 .3cqw 1cqw rgba(120, 60, 20, .15); }
.pc-qr-box svg { width: 100%; height: 100%; display: block; }
.pc-qr-box svg path { fill: #3a0a0f; }
.pc-qr small { font-size: 1.1cqw; color: var(--c-red-d); font-weight: 600; white-space: nowrap; }

/* =========================================================
   CÔNG CỤ TẠO ẢNH THẺ
   ========================================================= */
.photo-tool { display: grid; grid-template-columns: 150px 1fr; gap: 14px; margin-top: 6px; padding: 12px; background: #f7faf9; border: 1px solid var(--line); border-radius: 12px; }
.photo-tool[hidden] { display: none; }
.pt-stage { position: relative; align-self: start; border-radius: 10px; overflow: hidden; box-shadow: 0 0 0 1px #d5e1df; }
.pt-stage canvas { width: 100%; height: auto; display: block; cursor: grab; touch-action: none; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.pt-stage canvas:active { cursor: grabbing; }
.pt-status { position: absolute; inset: auto 0 0 0; padding: 8px; font-size: 12px; line-height: 1.35; color: #fff; background: rgba(15, 40, 38, .82); display: none; }
.pt-status.show { display: block; }
.pt-status button { font: inherit; font-weight: 700; color: #fff; background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.5); border-radius: 6px; padding: 2px 8px; margin-top: 4px; cursor: pointer; }
.pt-status .spin { display: inline-block; width: 11px; height: 11px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; margin-right: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.pt-controls { display: grid; gap: 12px; align-content: start; }
.pt-group { display: grid; gap: 6px; font-size: 13px; }
.pt-group b { font-weight: 600; color: #3b4b4d; }
.pt-group input[type=range] { padding: 0; accent-color: var(--teal); }
.pt-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pt-chips button {
  font: inherit; font-size: 12.5px; padding: 6px 10px; border-radius: 999px; border: 1px solid #cfdcda; background: #fff; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; color: var(--ink);
}
.pt-chips button i { width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 0 1px #b9c9c7; }
.pt-chips button.on { border-color: var(--teal); background: #e4f2f0; color: var(--teal-d); font-weight: 600; }
.pt-chips button:disabled { opacity: .45; cursor: not-allowed; }
.pt-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pt-hint { font-size: 12px; color: var(--muted); }
@media (max-width: 420px) { .photo-tool { grid-template-columns: 120px 1fr; } }

@media (max-width: 600px) {
  .topnav { padding: 10px 12px; }
  .topnav .brand { font-size: 14px; white-space: nowrap; }
  .topnav .links { gap: 0; }
  .topnav .links a { padding: 6px 8px; font-size: 12.5px; white-space: nowrap; }
  .wrap { padding-top: 18px; }
}

/* hộp lưu ảnh trên điện thoại */
.save-dialog {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 25, 25, .72);
  display: grid; place-items: center; padding: 16px;
}
.save-box {
  background: #fff; border-radius: 16px; padding: 14px; width: min(100%, 640px);
  max-height: 92vh; overflow: auto; display: grid; gap: 12px;
}
.save-box img { width: 100%; height: auto; display: block; border-radius: 10px; -webkit-touch-callout: default; user-select: auto; }
.save-tip { margin: 0; font-size: 14px; line-height: 1.5; color: #3b4b4d; text-align: center; }
.save-box .actions .btn { flex: 1 1 auto; }

/* =========================================================
   IN THẺ: đúng khổ 85.6 × 54 mm
   ========================================================= */
@media print {
  @page { size: auto; margin: 10mm; }
  body { background: #fff; }
  .topnav, .actions, .alert, .search, .profile, .section-title, .page-title, .hint { display: none !important; }
  .wrap { padding: 0; }
  .card-holder { width: 85.6mm; max-width: none; }
  .pet-card { box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
