:root {
  --bg: #f6f6f9;
  --surface: #ffffff;
  --surface-2: #f0f0f5;
  --border: #e3e3ea;
  --text: #1d1d24;
  --muted: #6b6b78;
  --accent: #7c6cf0;
  --accent-text: #ffffff;
  --danger: #e5484d;
  --sun: #e5484d;
  --sat: #0b84d6;
  --today: #7c6cf0;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131318;
    --surface: #1c1c23;
    --surface-2: #26262f;
    --border: #33333d;
    --text: #ececf1;
    --muted: #9a9aa8;
    --accent: #9488ff;
    --accent-text: #131318;
    --sun: #ff6b70;
    --sat: #4db3ff;
    --today: #9488ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.loading { text-align: center; color: var(--muted); padding: 40px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- 상단 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-row {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand img { width: 26px; height: 26px; }
.spacer { flex: 1; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer;
  width: 38px; height: 38px; border-radius: 10px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }

.chips {
  max-width: 1100px; margin: 0 auto;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 0 16px 10px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; cursor: pointer; white-space: nowrap;
  font-size: 14px;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.soon { opacity: .5; }

main { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

/* ---------- 공통 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.btn {
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  border-radius: 10px; padding: 8px 14px; min-height: 40px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.ask-msg { margin: 0; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 9px 12px; min-height: 42px;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.error-box { color: var(--danger); font-size: 14px; min-height: 20px; }

/* ---------- 로그인 ---------- */
.auth { max-width: 380px; margin: 12vh auto 0; padding: 28px 24px; }
.auth h1 { font-size: 22px; margin: 0 0 4px; display: flex; gap: 10px; align-items: center; }
.auth h1 img { width: 34px; height: 34px; }
.auth p { margin: 0 0 18px; }
.auth form { display: grid; gap: 10px; }

/* ---------- 캘린더 ---------- */
.cal-head { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.cal-head h2 { margin: 0 6px; font-size: 20px; }
.cal { overflow: hidden; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); padding: 8px 0; border-bottom: 1px solid var(--border); }
.cal-dow.sun, .cal-day.sun .num { color: var(--sun); }
.cal-dow.sat, .cal-day.sat .num { color: var(--sat); }
.cal-day {
  min-height: 108px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0;
  background: var(--surface); text-align: left; border-top: 0; border-left: 0;
}
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day:hover { background: var(--surface-2); }
.cal-day.other { opacity: .4; }
.cal-day .num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.cal-day.today .num { background: var(--today); color: var(--accent-text) !important; }
.cal-label {
  font-size: 11.5px; line-height: 1.35; padding: 1px 5px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: color-mix(in srgb, var(--c) 16%, transparent);
  border-left: 3px solid var(--c);
}
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.cal-dots { display: none; flex-wrap: wrap; gap: 3px; padding: 0 2px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

@media (max-width: 700px) {
  .cal-day { min-height: 64px; padding: 4px 2px; align-items: center; }
  .cal-label, .cal-more { display: none; }
  .cal-dots { display: flex; justify-content: center; }
}

/* ---------- 하루 보기 ---------- */
.day-head { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.day-head h2 { margin: 0; font-size: 19px; flex: 1; text-align: center; }
.day-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.day-actions .btn { flex: 1; }
.sections { display: grid; gap: 12px; }
.section { padding: 14px 16px; border-top: 4px solid var(--c); }
.section h3 { margin: 0 0 8px; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.section h3 .spacer { flex: 1; }
.entry { padding: 10px 0; border-top: 1px solid var(--border); }
.entry:first-of-type { border-top: 0; }
.entry-head { display: flex; align-items: flex-start; gap: 8px; }
.entry-title { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.entry-type { font-size: 12px; color: var(--muted); font-weight: 400; margin-right: 4px; }
.entry dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 6px 0 0; font-size: 14px; }
.entry dt { color: var(--muted); }
.entry dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.items-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.items-table td { padding: 2px 0; }
.items-table td.num { text-align: right; white-space: nowrap; padding-left: 10px; }
.items-table tr.total td { border-top: 1px solid var(--border); font-weight: 600; padding-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* 타임라인 */
.track-map { height: 320px; border-radius: 10px; overflow: hidden; margin: 4px 0 8px; background: var(--surface-2); z-index: 0; position: relative; }
.track-dot { display: inline-block; margin-right: 6px; vertical-align: middle; width: 10px; height: 10px; }
.sketch-link { display: block; width: 160px; max-width: 45%; float: right; margin: 6px 0 4px 12px; }
.route-sketch { display: block; width: 100%; height: auto; background: var(--surface-2); border-radius: 8px; }
.entry::after { content: ''; display: block; clear: both; }
.map-section h3 .map-count { font-size: 13px; font-weight: 400; }

/* 지도로 보기 */
.page-title { margin: 0 0 12px; font-size: 20px; }
.chips.flat { padding: 0 0 10px; }
.cat-toggle { opacity: .5; }
.cat-toggle.on { opacity: 1; border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, var(--surface)); }
.map-range { margin-bottom: 10px; }
.map-range input { width: auto; flex: 1; min-width: 140px; }
.big-map { height: max(360px, calc(100dvh - 330px)); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); position: relative; z-index: 0; background: var(--surface-2); }
.map-info { margin: 10px 2px; font-size: 14px; }
.map-list { display: grid; gap: 4px; }
.map-item {
  display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 12px;
}
.map-item:hover { background: var(--surface-2); }
.map-item .dot { flex: none; }
.map-item-date { flex: none; width: 42px; font-size: 13px; }
.map-item-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-popup { display: grid; gap: 4px; min-width: 160px; font: 14px/1.4 inherit; }
.map-popup a { color: var(--accent); }
@media (prefers-color-scheme: dark) {
  .big-map .leaflet-tile-pane, .pick-map .leaflet-tile-pane { filter: brightness(.8) contrast(1.1); }
  .leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
}

/* 위치 입력 */
.loc-field { display: grid; gap: 6px; }
.loc-label { font-size: 14px; }
.pick-map { height: min(52dvh, 420px); border-radius: 10px; overflow: hidden; position: relative; z-index: 0; background: var(--surface-2); }
.recent-places { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.small-label { width: 100%; font-size: 13px; }
.loc-link { color: var(--accent); }

.upload-status { display: grid; gap: 4px; font-size: 14px; }
.upload-line { overflow-wrap: anywhere; }
@media (prefers-color-scheme: dark) {
  .track-map .leaflet-tile-pane { filter: brightness(.8) contrast(1.1); }
}

/* 할 일 */
.todo { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); }
.todo:first-of-type { border-top: 0; }
.todo input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.todo .text { flex: 1; overflow-wrap: anywhere; }
.todo.done .text { text-decoration: line-through; color: var(--muted); }
.todo .since { font-size: 12px; color: var(--muted); white-space: nowrap; }
.todo-add { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- 카테고리 보기 ---------- */
.list-tools { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.list-tools input { flex: 1; min-width: 180px; }
.date-group { margin: 18px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.date-group a:hover { text-decoration: underline; }
.list-item { padding: 12px 16px; margin-bottom: 8px; border-left: 4px solid var(--c); }

/* ---------- 모달 ---------- */
dialog {
  border: 0; padding: 0; border-radius: 16px; width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); gap: 8px; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; display: grid; gap: 14px; }
.modal-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.modal-foot .spacer { flex: 1; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field .req { color: var(--danger); }
.field .with-unit { display: flex; align-items: center; gap: 8px; }
.field .unit { color: var(--muted); font-size: 14px; white-space: nowrap; }
.rating { display: flex; gap: 4px; }
.rating button { border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--border); padding: 0 2px; }
.rating button.on { color: #f5a524; }
.items-edit { display: grid; gap: 6px; }
.items-row { display: grid; gap: 6px; }
.items-line { display: grid; gap: 6px; }
.items-row input { min-height: 38px; padding: 6px 8px; min-width: 0; }
.items-row input.wide { min-height: 34px; font-size: 14px; }
.cat-select { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.cat-select select { min-height: 34px; padding: 4px 6px; font-size: 13px; text-overflow: ellipsis; }
.cat-select select:disabled { opacity: .45; }
.items-row.multi { padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.items-table tr.item-note td { color: var(--muted); font-size: 13px; padding: 0 0 4px 10px; white-space: pre-wrap; }
.items-edit > .btn { justify-self: start; }
.items-total { text-align: right; font-weight: 600; font-size: 14px; }

.recall-btn { width: 100%; border-style: dashed; color: var(--accent); }
.recall-list { display: grid; gap: 6px; }
.recall-item {
  display: flex; gap: 10px; align-items: baseline; text-align: left; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 10px 12px;
}
.recall-item:hover { background: var(--surface-2); }
.recall-item .muted { flex: none; font-size: 13px; width: 40px; }

/* 사진 */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; margin-top: 8px; max-width: 480px; }
.photo-thumb { border: 0; padding: 0; background: var(--surface-2); border-radius: 8px; overflow: hidden; aspect-ratio: 1; cursor: zoom-in; }
.photo-thumb img, .photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-full { display: block; max-width: 100%; max-height: 70dvh; margin: 0 auto; border-radius: 8px; }
.photo-edit { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px; }
.photo-tile { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.photo-remove {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0,0,0,.6); color: #fff; font-size: 12px; line-height: 1;
}
.photo-add {
  aspect-ratio: 1; border: 1.5px dashed var(--border); border-radius: 8px; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 22px; color: var(--muted);
}
.photo-add span { font-size: 12px; }
.photo-add:disabled { opacity: .5; }

.type-picker { display: grid; gap: 14px; }
.type-picker h4 { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.type-btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 12px; cursor: pointer;
  padding: 12px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  border-bottom: 3px solid var(--c);
}
.type-btn:hover { background: var(--surface-2); }
.type-btn .ic { font-size: 22px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px;
  z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

.settings { display: grid; gap: 12px; max-width: 520px; }
.settings .card { padding: 16px; }
.settings h3 { margin: 0 0 10px; font-size: 16px; }
.settings form { display: grid; gap: 10px; }
