:root {
  --blue: #4a90d2;
  --blue-dark: #2f78bd;
  --orange: #e8a04a;
  --red: #d9534f;
  --ink: #222;
  --muted: #6b6b6b;
  --line: #d9d9d9;
  --bg: #ffffff;
  --card: #ffffff;
  --radius: 18px;
  --nav-h: 64px;
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: #eef2f6;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font: inherit; color: inherit; }

#app {
  max-width: 480px;
  min-height: 100%;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

/* ---------- Header ---------- */
.topbar { height: 36px; background: var(--blue); }
.page-head { padding: 20px 20px 4px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.page-head h1 { color: var(--blue); font-size: 28px; font-weight: 700; }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 4px; }
.fab { width: 54px; height: 54px; border-radius: 14px; background: var(--orange); color: #fff; font-size: 32px; line-height: 1; flex: none; }

.hero { background: var(--blue); color: #fff; padding: 24px 20px 22px; display: flex; justify-content: space-between; align-items: center; }
.hero small { letter-spacing: .5px; font-size: 14px; }
.hero h1 { font-size: 28px; margin: 14px 0 2px; }
.hero p { font-size: 14px; }
.hero .pill { display: inline-block; margin-top: 12px; background: var(--orange); color: #fff; font-size: 13px; padding: 4px 14px; border-radius: 99px; }
.hero svg { width: 92px; height: 92px; flex: none; }

/* ---------- Cards ---------- */
.section { padding: 0 16px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--card); }
.card + .card { margin-top: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; }
.badge { font-size: 12px; padding: 3px 12px; border-radius: 99px; color: #fff; background: var(--orange); }
.badge.blue { background: var(--blue); }
.badge.off { background: #999; }
.badge.outline { background: #fff; color: var(--blue); border: 1px solid var(--blue); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; min-height: 76px; }
.stat small { font-size: 10px; color: var(--muted); display: block; }
.stat b { display: block; margin-top: 12px; font-size: 16px; color: var(--blue); }

.btn { display: block; width: 100%; padding: 12px; border-radius: 10px; font-weight: 600; color: #fff; background: var(--orange); text-align: center; }
.btn.blue { background: var(--blue); }
.btn.outline { background: #fff; color: var(--blue); border: 1px solid var(--blue); }
.btn.danger { background: #fff; color: var(--red); border: 1px solid var(--red); }
.btn.small { width: auto; padding: 8px 16px; font-size: 13px; }
.btn[disabled] { opacity: .5; }

.row-title { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 16px 10px; }
.row-title h2 { font-size: 16px; }
.link { color: var(--blue); font-size: 12px; font-weight: 600; }

.reminder { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.reminder header { background: var(--orange); color: #fff; font-weight: 700; padding: 10px 14px; font-size: 15px; word-break: break-word; }
.reminder .body { padding: 10px 14px 14px; font-size: 12px; color: #444; display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.reminder .actions { display: flex; gap: 12px; width: 100%; margin-top: 4px; }
.reminder.done header { background: #aaa; text-decoration: line-through; }

.add-box { margin: 0 16px; border: 2px dashed var(--blue); border-radius: var(--radius); padding: 34px 0; text-align: center; color: var(--blue); font-weight: 700; width: calc(100% - 32px); }

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

/* ---------- Calendar ---------- */
.cal { margin: 18px 16px; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.cal-head b { font-size: 15px; }
.nav-btn { width: 40px; height: 36px; border-radius: 10px; background: #4b4b4b; color: #fff; font-size: 18px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 6px; text-align: center; }
.dow { font-size: 11px; color: var(--muted); padding-bottom: 6px; }
.day { position: relative; height: 42px; font-size: 14px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.day.sel { background: var(--blue); color: #fff; font-weight: 700; width: 42px; margin: 0 auto; }
.day.today:not(.sel) { color: var(--blue); font-weight: 700; }
.day i { position: absolute; bottom: 2px; width: 5px; height: 5px; border-radius: 50%; background: var(--blue); }
.day i.late { background: var(--red); }
.day.sel i { background: #fff; }
.day-title { display: flex; justify-content: space-between; margin: 0 20px 10px; font-weight: 700; font-size: 15px; }
.day-title small { font-weight: 400; color: var(--muted); font-size: 11px; }

/* ---------- History ---------- */
.search { margin: 18px 16px 14px; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; gap: 12px; align-items: center; }
.search svg { width: 22px; height: 22px; stroke: #444; fill: none; stroke-width: 2; flex: none; }
.search input { border: 0; outline: 0; flex: 1; min-width: 0; font-size: 15px; }
.chips { display: flex; gap: 10px; margin: 0 16px 14px; }
.chip { padding: 4px 16px; border-radius: 99px; font-size: 13px; color: #fff; background: var(--orange); opacity: .55; }
.chip.active { opacity: 1; background: var(--blue); }
.chip.fav.active { background: var(--orange); }
.chip.fav { background: var(--orange); }
.convo { margin: 0 16px; padding: 14px 4px; border-bottom: 1px solid #444; }
.convo .top { display: flex; justify-content: space-between; gap: 10px; }
.convo h3 { font-size: 15px; word-break: break-word; }
.convo time { display: block; color: var(--muted); font-size: 12px; margin: 8px 0; }
.convo p { color: var(--muted); font-size: 13px; word-break: break-word; }
.convo p.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.convo { cursor: pointer; }
.star { font-size: 24px; line-height: 1; color: var(--orange); flex: none; height: 28px; }

/* ---------- Settings ---------- */
.dev-card { margin: 18px 16px; }
.dev-card .mascot { display: block; margin: 8px auto; width: 96px; height: 96px; }
.kv { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; font-size: 14px; }
.kv .ok { color: var(--orange); font-weight: 600; }
.kv .bad { color: var(--red); font-weight: 600; }
.switch { width: 50px; height: 28px; border-radius: 99px; background: var(--blue); position: relative; }
.switch.off { background: #bbb; }
.switch::after { content: ""; position: absolute; top: 3px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; }
.switch:not(.off)::after { left: auto; right: 4px; }
.setting { display: block; width: 100%; text-align: left; margin: 12px 0; }
.setting b { display: block; font-size: 15px; }
.setting span { font-size: 14px; color: var(--muted); }
.foot { text-align: center; font-size: 11px; color: var(--muted); margin: 16px 0 24px; }

/* ---------- Nav ---------- */
#tabs { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, 1fr); z-index: 5; }
#tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: #555; }
#tabs svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.active { color: var(--blue); font-weight: 700; }

/* ---------- Modal / toast ---------- */
#overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
#overlay[hidden], #toast[hidden] { display: none; }
.sheet { background: #fff; width: 100%; max-width: 480px; border-radius: 22px 22px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); }
.sheet h2 { color: var(--blue); margin-bottom: 14px; }
.field { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field input, .field textarea { display: block; width: 100%; margin-top: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; color: var(--ink); }
.sheet .btns { display: flex; gap: 12px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #333; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 13px; z-index: 20; max-width: 90%; text-align: center; }
