/* ---------------------------------------------------------------- tokens */

:root {
  color-scheme: light;
  --page: #f8f4ee;
  --surface: #fffdfa;
  --surface-2: #f1ebe1;
  --ink: #211a12;
  --ink-2: #5b5348;
  --muted: #94897a;
  --hairline: #e7dfd2;
  --border: rgba(33, 26, 18, 0.10);
  --accent: #d9762c;
  --accent-ink: #ffffff;
  --danger: #d03b3b;
  --good: #0ca30c;

  /* 이벤트 종류별 색 */
  --t-meal: #d9762c;
  --t-snack: #e0679d;
  --t-water: #2a8fd6;
  --t-litter: #1baf7a;
  --t-vomit: #c94f4f;

  /* 고양이 색 */
  --cat-mini: #d6558e;
  --cat-taek: #2a78d6;
  --cat-both: #7a6f60;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(33, 26, 18, 0.05), 0 4px 16px rgba(33, 26, 18, 0.05);
  --nav-h: 62px;
  font-family: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #121110;
    --surface: #1d1b18;
    --surface-2: #2a2722;
    --ink: #f7f3ec;
    --ink-2: #c9c1b2;
    --muted: #8f8676;
    --hairline: #332f28;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #e8944a;
    --shadow: none;

    --t-meal: #e8944a;
    --t-snack: #e87bab;
    --t-water: #4aa3e0;
    --t-litter: #2cc08c;
    --t-vomit: #e06a6a;

    --cat-mini: #e87bab;
    --cat-taek: #4a95e8;
    --cat-both: #a99c88;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121110;
  --surface: #1d1b18;
  --surface-2: #2a2722;
  --ink: #f7f3ec;
  --ink-2: #c9c1b2;
  --muted: #8f8676;
  --hairline: #332f28;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #e8944a;
  --shadow: none;

  --t-meal: #e8944a;
  --t-snack: #e87bab;
  --t-water: #4aa3e0;
  --t-litter: #2cc08c;
  --t-vomit: #e06a6a;

  --cat-mini: #e87bab;
  --cat-taek: #4a95e8;
  --cat-both: #a99c88;
}

/* ---------------------------------------------------------------- base */

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
a { color: var(--accent); }

.boot-message { padding: 40px; text-align: center; color: var(--muted); }

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

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

.sidenav {
  display: none;
  flex-direction: column;
  gap: 6px;
  width: 200px;
  padding: 20px 12px;
  border-right: 1px solid var(--hairline);
  background: var(--surface);
  position: sticky;
  top: 0;
  height: 100dvh;
  flex-shrink: 0;
}
.sidenav .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
  font-weight: 700;
  font-size: 18px;
}
.sidenav .brand img { width: 32px; height: 32px; border-radius: 8px; }

.main {
  flex: 1;
  min-width: 0;
  padding: 16px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 14px;
}
.topbar h1 { font-size: 22px; font-weight: 700; }
.topbar .sub { color: var(--muted); font-size: 13.5px; margin-top: 1px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar h1.clock { font-size: 30px; font-variant-numeric: tabular-nums; }

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.tabbar button {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 8px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

.navlink {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-2);
  font-size: 15.5px;
  cursor: pointer;
  text-align: left;
}
.navlink svg { width: 22px; height: 22px; }
.navlink:hover { background: var(--surface-2); }
.navlink.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }

.navbadge {
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
  border-radius: 999px;
  padding: 1px 7px;
  line-height: 1.6;
  white-space: nowrap;
}
.sidenav .navbadge { margin-left: auto; }
.tabbar .navbadge { position: absolute; top: 3px; right: calc(50% - 34px); }

@media (min-width: 860px) {
  .sidenav { display: flex; }
  .tabbar { display: none; }
  .main { padding: 20px 28px 32px; }
}

/* ---------------------------------------------------------------- components */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}
.card-title .cnt { margin-left: auto; font-size: 12.5px; color: var(--muted); font-weight: 500; }

.grid-2 { display: grid; gap: 12px; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; } }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 9px; }
.btn.icon svg { width: 19px; height: 19px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.chip.cat.mini { background: color-mix(in srgb, var(--cat-mini) 16%, transparent); color: var(--cat-mini); }
.chip.cat.taek { background: color-mix(in srgb, var(--cat-taek) 16%, transparent); color: var(--cat-taek); }
.chip.cat.both { background: color-mix(in srgb, var(--cat-both) 16%, transparent); color: var(--cat-both); }

.row-list { display: flex; flex-direction: column; }
.row-list > * { padding: 11px 2px; border-bottom: 1px solid var(--hairline); }
.row-list > *:last-child { border-bottom: 0; padding-bottom: 2px; }
.row-list > *:first-child { padding-top: 2px; }

.empty {
  padding: 26px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.section-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  margin: 18px 2px 8px;
}
.list-title { font-size: 16.5px; font-weight: 700; margin: 4px 2px 10px; }

.add-row {
  border: 1.5px dashed var(--hairline);
  background: none;
  border-radius: var(--radius);
  padding: 13px;
  color: var(--muted);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 10px;
}
.add-row:hover { background: var(--surface-2); color: var(--ink-2); }

/* ---------------------------------------------------------------- 메인: 큰 버튼 그리드 */

.home-grid { display: grid; gap: 14px; }

.big-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  grid-auto-rows: minmax(140px, 1fr);
}

.big-wrap { position: relative; display: flex; }

.big-btn {
  flex: 1;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--hairline);
  border-radius: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 14px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.big-btn:active { transform: scale(0.97); background: var(--surface-2); }
.big-btn.t-meal { border-top-color: var(--t-meal); }
.big-btn.t-snack { border-top-color: var(--t-snack); }
.big-btn.t-water { border-top-color: var(--t-water); }
.big-btn.t-litter { border-top-color: var(--t-litter); }
.big-btn.t-vomit { border-top-color: var(--t-vomit); }

.b-emoji { font-size: 48px; line-height: 1.15; }
.b-label { font-size: 21px; font-weight: 800; }
.b-meta { font-size: 13.5px; color: var(--muted); text-align: center; }

.b-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 19px;
  cursor: pointer;
}
.b-edit:hover { background: var(--surface-2); color: var(--ink-2); }

.today-panel { min-width: 0; }
.today-card .row-list { max-height: none; }

/* 가로 태블릿: 왼쪽 큰 버튼 3열 + 오른쪽 오늘 기록, 한 화면에 다 보이게 */
@media (min-width: 980px) {
  .home-grid {
    grid-template-columns: 1.7fr 1fr;
    align-items: start;
  }
  .big-grid {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: minmax(0, 1fr);
    height: calc(100dvh - 150px);
    min-height: 340px;
  }
  .big-btn { min-height: 0; }
  .today-panel {
    height: calc(100dvh - 150px);
    min-height: 340px;
    overflow-y: auto;
  }
}

/* ---------------------------------------------------------------- 이벤트 줄 */

.event-row {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  width: 100%;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
}
.e-emoji { font-size: 23px; line-height: 1.3; flex-shrink: 0; }
.e-main { flex: 1; min-width: 0; }
.e-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.e-label { font-weight: 600; font-size: 15px; }
.e-sub { font-size: 13px; color: var(--ink-2); }
.e-note {
  font-size: 13.5px;
  color: var(--ink-2);
  margin-top: 2px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.e-time {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}

/* ---------------------------------------------------------------- 건강 */

.hw-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; font-size: 14.5px; }
.hw-line .k { color: var(--muted); }
.hw-line .v { font-weight: 600; }

.due-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--ink-2);
}
.due-badge.urgent { background: var(--danger); color: #fff; }

.hw-log { width: 100%; margin: 10px 0 8px; padding: 13px; font-size: 15.5px; }

/* ---------------------------------------------------------------- forms */

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field input[type="text"], .field input[type="date"], .field input[type="time"],
.field input[type="datetime-local"], .field input[type="password"], .field input[type="number"],
.field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  min-height: 46px;
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible,
.btn:focus-visible, .seg button:focus-visible, .big-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.hint { font-size: 12px; color: var(--muted); }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg.big-seg button { padding: 11px 18px; font-size: 15px; }

.filter-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-row .seg { flex-wrap: nowrap; }

/* ---------------------------------------------------------------- dialog */

dialog.sheet {
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: min(86dvh, 780px);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.3);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}
.sheet-head h2 { font-size: 17px; }
.sheet-head .x { border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.sheet-body { padding: 4px 18px 18px; overflow-y: auto; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 6px; }
.sheet-actions .spacer { margin-right: auto; }

@media (max-width: 640px) {
  dialog.sheet {
    margin: auto 0 0;
    width: 100vw;
    max-width: 100vw;
    border-radius: 18px 18px 0 0;
    max-height: 92dvh;
  }
}

/* ---------------------------------------------------------------- 달력 */

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-title { font-weight: 700; font-size: 15px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0 6px; }
.cal-day {
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 10px;
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0;
  font-size: 14px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.cal-day:hover { background: var(--surface-2); }
.cal-day.today { font-weight: 700; color: var(--accent); }
.cal-day.sel { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

.type-dots { display: flex; gap: 3px; min-height: 6px; }
.type-dots i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.type-dots .d-meal { background: var(--t-meal); }
.type-dots .d-snack { background: var(--t-snack); }
.type-dots .d-water { background: var(--t-water); }
.type-dots .d-litter { background: var(--t-litter); }
.type-dots .d-vomit { background: var(--t-vomit); }
.cal-day.sel .type-dots i { background: var(--accent-ink); }

.cal-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 4px; }
.cal-legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.cal-legend .d-meal { background: var(--t-meal); }
.cal-legend .d-snack { background: var(--t-snack); }
.cal-legend .d-water { background: var(--t-water); }
.cal-legend .d-litter { background: var(--t-litter); }
.cal-legend .d-vomit { background: var(--t-vomit); }

/* ---------------------------------------------------------------- toast */

.toast-region {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--ink);
  color: var(--page);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14.5px;
  font-weight: 600;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.18s ease-out;
  pointer-events: auto;
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }
.toast .t-msg { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast .t-act {
  border: 0;
  background: none;
  color: #ffc46b;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 8px;
  white-space: nowrap;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------------------------------------------------------------- login */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card { width: min(360px, 100%); text-align: center; }
.login-card img { width: 60px; height: 60px; margin: 0 auto 12px; border-radius: 14px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--muted); font-size: 13.5px; margin-bottom: 18px; }
