:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #8a90a0;
  --line: #e4e7ee;
  --primary: #3b6ef5;
  --primary-ink: #fff;
  --danger: #e5484d;
  --dog: #f59e0b;
  --cat: #8b5cf6;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 8px; }
.topbar .brand .brand-logo { display: block; width: 24px; height: 24px; }
.topbar nav a { margin-left: 14px; text-decoration: none; color: var(--muted); font-size: 14px; }
.topbar nav a:hover { color: var(--primary); }

.container { max-width: 680px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.card.narrow { max-width: 380px; margin: 40px auto; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: #eef0f5; padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.row-between { display: flex; align-items: center; justify-content: space-between; }
.badge { background: var(--primary); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }

/* forms */
.form label { display: block; margin-bottom: 14px; font-size: 14px; font-weight: 600; }
.form input, .form select, .form textarea {
  width: 100%; margin-top: 6px; padding: 11px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
.field { margin-bottom: 14px; }
.field-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* 시간 입력 — 시계 아이콘 + 통합 둥근 컨테이너 + 강조 "지금" 핕 (form 톤 계승) */
.time-input {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px; padding: 4px 5px 4px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.time-input:hover { border-color: #c7ccd8; }
.time-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 110, 245, .16); }
.time-input input[type="datetime-local"] {
  flex: 1; min-width: 0; margin: 0; padding: 8px 0;
  border: none; border-radius: 0; background: transparent; font-size: 16px;
}
.time-input input[type="datetime-local"]:focus { outline: none; box-shadow: none; border: none; }
.time-input input::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .55; }
.time-input input::-webkit-calendar-picker-indicator:hover { opacity: .9; }
.now-btn {
  flex: none; border: none; border-radius: 9px; cursor: pointer;
  padding: 8px 14px; font-size: 13px; font-weight: 700;
  background: #eef2ff; color: var(--primary); white-space: nowrap;
  transition: background-color .15s ease, transform .08s ease;
}
.now-btn:hover { background: #e0e8ff; }
.now-btn:active { transform: scale(.96); }
textarea { resize: vertical; }

/* 사진 파일 선택 — 네이티브 input 은 숨기고 "파일 선택" 버튼 + 선택된 파일명을 직접 그린다.
   수정 모드에서는 기존 업로드 사진이 선택된 것처럼(파일명+보기 링크) 표시된다(app.js). */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.file-picker {
  display: flex; align-items: center; gap: 12px; margin-top: 6px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.file-picker .file-btn {
  flex: none; padding: 8px 14px; border: none; border-radius: 9px;
  background: #eef2ff; color: var(--primary); font-size: 13px; font-weight: 700;
  cursor: pointer; transition: background-color .15s ease, transform .08s ease;
}
.file-picker .file-btn:hover { background: #e0e8ff; }
.file-picker .file-btn:active { transform: scale(.96); }
.file-picker .file-name {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-picker a.file-name[href] { color: var(--primary); text-decoration: underline; }

/* native select → custom chevron + 부드러운 전환 (전역) */
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a90a0' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  padding-right: 32px !important;
  cursor: pointer;
}
.form input, .form select, .form textarea { transition: border-color .15s ease, box-shadow .15s ease; }

/* 일관된 포커스 링 — 모든 입력 요소 */
input:focus, select:focus, textarea:focus { outline: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible,
.form input:focus, .form select:focus, .form textarea:focus,
.table select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 110, 245, .16);
}
.form input:hover, .form select:hover, .table select:hover {
  border-color: #c7ccd8;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--ink); font-size: 14px; cursor: pointer;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 라벨 종류 이미지 칩 — 라벨명이 이미지 안에 포함되어 텍스트 대신 이미지를 버튼으로 사용. */
/* 이미지를 버튼 테두리에 꽉 차게(여백 0 + overflow 로 모서리 클립). 선택 시 테두리 강조. */
.chip-img { padding: 0; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; line-height: 0; flex: 0 0 calc((100% - 16px) / 3); background: #fff; }
.chip-img img { display: block; width: 100%; height: auto; }
.chip-img.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }
/* 버튼 배경 = 이미지 배경 파스텔(둥근 모서리 클립부가 이미지와 이어져 보이게). */
.chip-img[data-label="drink"]    { background: #e2f1fe; }
.chip-img[data-label="eat"]      { background: #fbe8ec; }
.chip-img[data-label="defecate"] { background: #eef0e7; }
.chip-img[data-label="urinate"]  { background: #fdf1e1; }
.chip-img[data-label="sleep"]    { background: #efe7f5; }
.chip-img[data-label="hr"]       { background: #fae2eb; }
.chip-img[data-label="rr"]       { background: #e8f3fe; }
.chip-img[data-label="stress"]   { background: #f0e8fa; }

/* 펫 선택 토글 — 종 색상(강아지 amber / 고양이 purple) 액센트 카드형 칩 */
.pet-toggle { display: flex; flex-wrap: wrap; gap: 10px; }

/* 접힌 드롭다운 펫 선택기 — 선택된 펫만 보이고 탭하면 목록을 펼침 */
.pet-select { position: relative; width: 100%; }
.pet-trigger {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 14px 9px 9px; border: 1.5px solid var(--line); border-radius: 14px;
  background: #fff; cursor: pointer; text-align: left;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.pet-trigger:hover { border-color: #c7ccd8; }
.pet-trigger .pet-meta { flex: 1; }
.pet-trigger.pet-dog .pet-emoji { background: #fef3e2; }
.pet-trigger.pet-cat .pet-emoji { background: #f1ebff; }
.pet-caret { flex: none; color: var(--muted); font-size: 12px; transition: transform .15s ease; }
.pet-select.open .pet-trigger { border-color: #c7ccd8; box-shadow: 0 3px 10px rgba(31, 36, 48, .1); }
.pet-select.open .pet-caret { transform: rotate(180deg); }
.pet-select.single .pet-trigger { cursor: default; }
.pet-select.single .pet-caret { display: none; }

/* 펼침 패널: 칩을 세로 목록으로 재배치 */
.pet-toggle[hidden] { display: none; }
.pet-select .pet-toggle {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 20;
  flex-direction: column; flex-wrap: nowrap; gap: 4px; margin: 0; padding: 6px;
  background: #fff; border: 1.5px solid var(--line); border-radius: 14px;
  box-shadow: 0 8px 24px rgba(31, 36, 48, .14);
  max-height: 256px; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.pet-select .pet-chip { width: 100%; border-color: transparent; border-radius: 10px; }
.pet-select .pet-chip:hover { background: #f6f7fb; border-color: transparent; }
/* 드롭다운에서는 선택 항목을 진한 종색 대신 옅은 배경 + 체크로 표시 */
.pet-select .pet-chip.active,
.pet-select .pet-chip.pet-dog.active,
.pet-select .pet-chip.pet-cat.active { background: #f0f2f7; box-shadow: none; }
.pet-select .pet-chip.active .pet-name { color: var(--ink); }
.pet-select .pet-chip.active .pet-serial { color: var(--muted); }
.pet-select .pet-chip.pet-dog.active .pet-emoji { background: #fef3e2; }
.pet-select .pet-chip.pet-cat.active .pet-emoji { background: #f1ebff; }
.pet-select .pet-chip.active::after {
  content: "✓"; margin-left: auto; color: var(--primary); font-weight: 700; font-size: 15px;
}
.pet-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px 9px 9px; border: 1.5px solid var(--line); border-radius: 14px;
  background: #fff; cursor: pointer; text-align: left;
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease, transform .08s ease;
}
.pet-chip:hover { border-color: #c7ccd8; }
.pet-chip:active { transform: scale(.98); }
.pet-emoji {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border-radius: 50%; font-size: 19px; background: #eef0f5; line-height: 1;
  overflow: hidden;
}
.pet-emoji img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pet-chip.pet-dog .pet-emoji { background: #fef3e2; }
.pet-chip.pet-cat .pet-emoji { background: #f1ebff; }
.pet-meta { display: flex; flex-direction: column; line-height: 1.2; }
.pet-name { font-size: 15px; font-weight: 700; color: var(--ink); }
.pet-serial { font-size: 11px; color: var(--muted); margin-top: 1px; }

.pet-chip.active { border-color: transparent; box-shadow: 0 3px 10px rgba(31, 36, 48, .12); }
.pet-chip.pet-dog.active { background: var(--dog); }
.pet-chip.pet-cat.active { background: var(--cat); }
.pet-chip.active .pet-name { color: #fff; }
.pet-chip.active .pet-serial { color: rgba(255, 255, 255, .85); }
.pet-chip.active .pet-emoji { background: rgba(255, 255, 255, .22); }

.btn {
  display: inline-block; padding: 11px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-size: 15px; cursor: pointer; text-decoration: none;
  text-align: center; white-space: nowrap;
}
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: #f3c6c7; }
.btn.block { display: block; width: 100%; margin-top: 6px; }

.computed { margin-top: 8px; font-size: 18px; font-weight: 700; color: var(--primary); }

.alert { padding: 11px 14px; border-radius: 10px; background: #eef2ff; color: #33415c; margin-bottom: 14px; font-size: 14px; }
.alert.error { background: #fdecec; color: #a4262c; }

/* list */
.label-list { list-style: none; padding: 0; margin: 0; }
.label-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.label-main { display: flex; gap: 10px; align-items: flex-start; }
.tag { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 8px; background: #eef0f5; white-space: nowrap; }
.tag-dog { background: #fef3e2; color: #b45309; }
.tag-cat { background: #f1ebff; color: #6d28d9; }
.label-actions { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.label-actions form { margin: 0; }

/* 내 기록: 펫 선택 드롭다운은 form 과 동일한 .pet-select 스타일 재사용 */
.pet-select { margin: 4px 0 16px; }
.pet-record-head { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 0 0 12px; }

/* 날짜 그룹 + 라벨타입 컬럼 */
.date-group { margin-top: 18px; }
.date-group:first-of-type { margin-top: 8px; }
.date-heading {
  font-size: 15px; font-weight: 700; margin: 0 0 10px;
  padding-bottom: 6px; border-bottom: 2px solid var(--line);
}
/* 전체 라벨: 펫별 그룹 사이 간격 + 헤딩 종 아이콘 정렬 */
.pet-group { margin-bottom: 28px; }
.pet-group:last-child { margin-bottom: 0; }
.pet-group .date-heading { display: flex; align-items: center; gap: 8px; }
.pet-group .date-heading .pet-emoji { width: 28px; height: 28px; }
/* 전체 라벨 표: 칼럼 폭을 표 너비에 비례(%)해 분배 → '이전'↔'작업' 간격도 화면 비율로 벌어짐 */
.pet-group .table .col-type   { white-space: nowrap; width: 10%; }
.pet-group .table .col-device { white-space: nowrap; word-break: normal; width: 22%; }
.pet-group .table .col-migrate { white-space: nowrap; width: 10%; text-align: center; }
.pet-group .table .col-action { width: 26%; text-align: center; }
/* 라벨 종류 블록을 3열 그리드로(날짜별 최대 2줄: 강 5종=3+2, 고 3종=1줄). */
.date-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-items: start; }
.label-column {
  min-width: 0;
  border: 1px solid var(--line); border-radius: 10px; padding: 6px;
}
.col-head { margin-bottom: 5px; display: flex; justify-content: center; }
/* 라벨명이 포함된 이미지를 컬럼 헤더로 사용(작게). */
.label-icon { display: block; width: 100%; max-width: 88px; height: auto; border-radius: 7px; }
.time-list { list-style: none; padding: 0; margin: 0; }
/* 시각 항목: 인라인 버튼 제거 → 테두리 있는 '버튼'처럼 보이게, 탭하면 다이얼로그(수정/삭제). */
.time-entry {
  display: flex; flex-direction: column; gap: 2px;
  width: 100%; text-align: left; font-family: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 8px; margin-bottom: 6px; font-size: 13px; cursor: pointer;
  transition: border-color .12s ease, background .12s ease, box-shadow .12s ease, transform .04s ease;
}
.time-list li:last-child .time-entry { margin-bottom: 0; }
.time-entry:hover, .time-entry:focus-visible {
  border-color: var(--primary); background: #f7faff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06); outline: none;
}
.time-entry:active { transform: scale(.98); }
/* 잠긴(이전됨) 라벨: 점선 테두리로 '편집 불가' 신호. */
.time-entry.locked { border-style: dashed; color: var(--muted); }
.entry-line { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.entry-caret { color: var(--muted); font-size: 16px; line-height: 1; flex: none; }
.time-text { font-variant-numeric: tabular-nums; word-break: keep-all; }
.lock { font-size: 11px; flex: none; }
.vital-info { font-size: 11px; line-height: 1.3; }
.vital-rate { color: var(--ink); font-weight: 700; }
/* 다이얼로그 안 수정(링크)·삭제(폼)를 같은 폭으로 나란히. */
.dialog-actions form { flex: 1; margin: 0; }

/* tables */
/* 카드 폭을 넘치는 표는 가로 스크롤로 감싸 레이아웃을 깨지 않게 한다. */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 5px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; }
.table .col-name   { min-width: 52px; white-space: nowrap; }
.table .col-breed  { word-break: keep-all; }
.table .col-device { min-width: 60px; word-break: break-all; }
.table .col-action { white-space: nowrap; text-align: right; }
/* 표 안 인라인 select (역할·펫 종 매핑) */
.table select {
  font-family: inherit; font-size: 13px; font-weight: 500; color: var(--ink);
  background-color: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 22px 6px 8px; min-width: 68px;
  background-position: right 6px center; background-size: 13px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.table tbody tr:hover td { background: #fafbfd; }
/* 종 태깅 select: 강아지/고양이는 연한 배경으로 구분, 미태깅은 기본 */
.table select.sp-dog { background-color: #fef3e2; border-color: #f3d9ae; color: #b45309; font-weight: 600; }
.table select.sp-cat { background-color: #f1ebff; border-color: #ddd0fb; color: #6d28d9; font-weight: 600; }
.admin-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.admin-actions form { margin: 0; }
/* 자동 저장 토스트: 우상단 고정, 잠깐 떴다 사라짐 */
.toast { position: fixed; top: 14px; right: 14px; z-index: 1000; padding: 8px 14px; border-radius: 8px;
  background: #16a34a; color: #fff; font-size: 13px; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.toast.toast-err { background: #dc2626; }
/* 기록/수정 완료 다이얼로그(중앙 모달) */
.dialog {
  border: none; border-radius: 16px; padding: 0; width: min(90vw, 340px);
  background: var(--card); color: var(--ink); box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-body { padding: 28px 22px 4px; text-align: center; }
.dialog-icon {
  width: 48px; height: 48px; margin: 0 auto 14px; border-radius: 50%;
  background: #dcfce7; color: #16a34a; font-size: 26px; line-height: 48px; font-weight: 700;
}
.dialog-msg { margin: 0; font-size: 16px; font-weight: 600; }
.dialog-actions { display: flex; gap: 8px; padding: 18px 22px 22px; }
.dialog-actions .btn { flex: 1; text-align: center; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 120px; margin-top: 0; }
.checkbox { display: inline-flex; align-items: center; gap: 4px; font-weight: 400; }
.checkbox input { width: auto; margin: 0; }

@media (max-width: 480px) {
  .grid-2 { grid-template-columns: 1fr; }
  /* 좁은 화면에서 표가 가로 스크롤되지 않도록 더 촘촘하게 */
  .table { font-size: 12px; }
  .table th, .table td { padding: 7px 4px; }
  .table .col-name { min-width: 40px; }
  .table select { font-size: 12px; min-width: 58px; padding: 5px 19px 5px 7px; background-position: right 5px center; }
  .table .col-action .btn.small { padding: 5px 8px; font-size: 12px; }
}
