:root {
  --bg: #f4f6f6;
  --card: #ffffff;
  --text: #1c2424;
  --muted: #5e6b6b;
  --faint: #8a9696;
  --line: #e1e6e6;
  --brand: #0F766E;
  --brand-soft: #e3f3f1;
  --brand-text: #0b5953;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --ok: #1b6e3a;
  --ok-soft: #e4f4ea;
  --radius: 12px;
  --tabbar-h: 62px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111717;
    --card: #1a2222;
    --text: #e8eeee;
    --muted: #a3b0b0;
    --faint: #7c8a8a;
    --line: #2b3636;
    --brand: #2bb3a6;
    --brand-soft: #143331;
    --brand-text: #8fe0d7;
    --danger: #ff7b7b;
    --danger-soft: #3a1c1c;
    --warn: #ffcf66;
    --warn-soft: #3a2f12;
    --ok: #7ad69c;
    --ok-soft: #173323;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back {
  border: none; background: transparent; color: var(--brand); font-weight: 700; font-size: 16px;
  padding: 6px 10px 6px 0; margin-right: 4px; cursor: pointer; flex: none;
}
.user-chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 4px 12px 4px 6px; display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer;
}
.dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; flex: none; }

.offline-bar { background: var(--warn-soft); color: var(--warn); font-size: 13px; padding: 8px 16px; text-align: center; }

.view {
  max-width: 760px; margin: 0 auto;
  padding: 14px 16px calc(var(--tabbar-h) + 90px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; font-size: 12px; color: var(--faint); gap: 2px;
}
.tabbar a .ico { font-size: 19px; line-height: 1; }
.tabbar a.on { color: var(--brand); font-weight: 700; }

.fab {
  position: fixed; right: max(16px, calc(50% - 364px)); bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); z-index: 11;
  height: 52px; padding: 0 20px; border-radius: 26px; border: none; background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.18); cursor: pointer;
}

h2.sec { font-size: 15px; margin: 22px 0 8px; color: var(--muted); font-weight: 700; }
h2.sec:first-child { margin-top: 4px; }
.big-date { font-size: 22px; font-weight: 800; margin: 4px 0 2px; }
.sub { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; display: block; text-decoration: none;
}
a.card:active { background: var(--bg); }
.card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.card-addr { font-weight: 700; font-size: 15px; }
.card-meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; }
.empty { text-align: center; color: var(--faint); padding: 26px 10px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }

.badge { font-size: 12px; padding: 1px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.b-plan { background: var(--brand-soft); color: var(--brand-text); }
.b-done { background: var(--line); color: var(--muted); }
.b-paid { background: var(--ok-soft); color: var(--ok); }
.b-unpaid { background: var(--warn-soft); color: var(--warn); }
.b-revisit { background: #f3e8fd; color: #6b2a96; }
@media (prefers-color-scheme: dark) { .b-revisit { background: #2f1f3b; color: #d6aef5; } }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }

.actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); text-decoration: none; font-weight: 600; font-size: 14px; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.block { width: 100%; min-height: 48px; font-size: 16px; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }

/* 검색, 필터 */
.search { width: 100%; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); padding: 0 12px; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.filters select { height: 34px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); padding: 0 10px; font-size: 13px; flex: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: none; background: var(--card); }
.seg button { border: none; background: transparent; padding: 0 12px; height: 32px; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; font-weight: 700; }
.count { font-size: 13px; color: var(--muted); margin: 6px 0; }

/* 폼 */
.form .field { margin-bottom: 16px; }
.form label.lbl { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.form input[type=text], .form input[type=tel], .form input[type=date], .form input[type=time],
.form input[type=number], .form input[inputmode], .form textarea, .form select {
  width: 100%; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); padding: 8px 12px;
}
.form textarea { min-height: 88px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 13px; font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.chip.add-chip { border-style: dashed; color: var(--brand-text); }
.hint { font-size: 12px; color: var(--faint); margin-top: 4px; }
.err { font-size: 13px; color: var(--danger); margin-top: 4px; }
.toggle { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--brand); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photo .x {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.6); color: #fff; font-size: 15px; line-height: 26px; cursor: pointer;
}
.photo-add {
  aspect-ratio: 1; border-radius: 10px; border: 1.5px dashed var(--faint); display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--muted); font-size: 12px; cursor: pointer; background: var(--card);
}
.photo-add span { font-size: 24px; line-height: 1; }

.notice { border-radius: var(--radius); padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.notice.revisit { background: #f3e8fd; color: #4f1f70; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--brand-soft); color: var(--brand-text); }
@media (prefers-color-scheme: dark) { .notice.revisit { background: #2f1f3b; color: #e5c9fa; } }
.notice a { font-weight: 700; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

/* 상세 */
.detail dl { margin: 0; }
.detail .kv { display: grid; grid-template-columns: 112px 1fr; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.detail .kv:last-child { border-bottom: none; }
.detail dt { color: var(--muted); font-size: 13px; }
.detail dd { margin: 0; white-space: pre-wrap; word-break: break-word; }

details.history summary { cursor: pointer; font-weight: 700; color: var(--muted); padding: 8px 0; }
.hist-item { font-size: 13px; padding: 8px 0; border-top: 1px solid var(--line); }
.hist-item .who { font-weight: 700; }
.hist-item .when { color: var(--faint); }
.hist-item ul { margin: 4px 0 0; padding-left: 18px; color: var(--muted); }

/* 캘린더 */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head .m { font-size: 19px; font-weight: 800; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--line); }
.cal .dow.sun, .cal .day.sun .n { color: var(--danger); }
.cal .dow.sat, .cal .day.sat .n { color: #1e63c4; }
@media (prefers-color-scheme: dark) { .cal .dow.sat, .cal .day.sat .n { color: #7fb1ff; } }
.cal .day {
  min-height: 76px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px 2px;
  cursor: pointer; overflow: hidden; background: transparent; text-align: left; border-top: none; border-left: none;
}
.cal .day:nth-child(7n+7) { border-right: none; }
.cal .day.other { opacity: .4; }
.cal .day.sel { background: var(--brand-soft); }
.cal .day .n { font-size: 12px; font-weight: 700; padding-left: 3px; display: inline-block; }
.cal .day.today .n { background: var(--brand); color: #fff !important; border-radius: 999px; padding: 0 6px; }
.cal .ev { font-size: 10.5px; line-height: 1.35; color: #fff; border-radius: 3px; padding: 0 3px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .more { font-size: 10.5px; color: var(--muted); padding-left: 3px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.ev-row { display: flex; gap: 10px; align-items: flex-start; }
.ev-bar { width: 5px; align-self: stretch; border-radius: 3px; flex: none; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.swatch { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; background: var(--card); cursor: pointer; font-size: 13px; }
.swatch.on { outline: 2px solid var(--text); outline-offset: -1px; font-weight: 700; }

/* 더보기 */
.list-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 84px + env(safe-area-inset-bottom));
  background: #1c2424; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: 90vw;
}
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 40; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; }
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 45; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 520px; border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
}
.sheet-title { font-weight: 800; font-size: 17px; }
.sheet-addr { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.postcode { position: fixed; inset: 0; z-index: 46; background: var(--card); display: flex; flex-direction: column; }
.postcode-head { display: flex; justify-content: space-between; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); }
.postcode-box { flex: 1; min-height: 0; }
/* 시간 돌림판 */
.time-btn {
  width: 100%; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  padding: 8px 12px; text-align: left; font-size: 16px; font-weight: 700; cursor: pointer;
}
.time-btn.empty { font-weight: 400; color: var(--faint); }
.tp-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55; display: flex; align-items: flex-end; justify-content: center; }
.tp-wheels { position: relative; display: flex; justify-content: center; align-items: center; gap: 6px; height: 132px; margin: 4px 0 6px; }
.tp-band { position: absolute; left: 6px; right: 6px; top: 44px; height: 44px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.tp-col {
  position: relative; height: 132px; width: 76px; overflow-y: scroll; scroll-snap-type: y mandatory;
  scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  -webkit-mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
  mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
}
.tp-col::-webkit-scrollbar { display: none; }
.tp-col.editing { overflow: hidden; }
.tp-pad { height: 44px; }
.tp-item { height: 44px; line-height: 44px; text-align: center; font-size: 22px; color: var(--faint); scroll-snap-align: center; cursor: pointer; user-select: none; }
.tp-item.on { color: var(--text); font-weight: 700; font-size: 26px; }
.tp-ap .tp-item { font-size: 16px; }
.tp-ap .tp-item.on { font-size: 18px; }
.tp-colon { position: relative; font-size: 24px; font-weight: 800; }
.tp-item input {
  width: 58px; height: 38px; font-size: 24px; font-weight: 700; text-align: center;
  border: 2px solid var(--brand); border-radius: 8px; background: var(--card); color: var(--text);
}
.tp-actions { display: flex; gap: 8px; }
.tp-actions .btn { flex: 1; min-height: 48px; }
.addr-row { display: flex; gap: 8px; }
.addr-row input { flex: 1; min-width: 0; }
.addr-row .btn { flex: none; min-height: 44px; }
.past { border: 1px solid rgba(107,42,150,.25); border-radius: 10px; padding: 8px 10px; margin-top: 6px; background: var(--card); color: var(--text); }
.past summary { cursor: pointer; font-weight: 700; }
.past .photos { margin-top: 6px; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
.dlg-bg { z-index: 50; align-items: center; padding: 16px; }
.dlg-bg .sheet { border-radius: 16px; max-width: 420px; }
.dlg-msg { white-space: pre-wrap; line-height: 1.55; }
.dlg-code { font-size: 30px; font-weight: 800; letter-spacing: 6px; text-align: center; padding: 12px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-text); user-select: all; }
body.locked .tabbar, body.locked .fab { display: none !important; }
.sync-bar { background: var(--brand-soft); color: var(--brand-text); font-size: 13px; padding: 6px 16px; text-align: center; }
[hidden] { display: none !important; }

@media (min-width: 700px) {
  .cal .day { min-height: 96px; padding: 4px; }
  .cal .ev { font-size: 12px; }
}
