:root {
  --bg: #fffdf7;
  --bg-2: #f6f2e8;
  --line: #e6ddc6;
  --line-strong: #d4c6a3;
  --navy: #1b2a41;
  --text: #1f2430;
  --muted: #7a776d;
  --gold: #a8823e;
  --sun: #b0574b;
  --sat: #3f6f99;
  --danger: #a23b2a;
  --radius: 2px;
  --bar-h: 17px;
  --bar-gap: 2px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  overscroll-behavior: none;
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg); color: var(--navy); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fffdf7; }
.btn.danger { color: var(--danger); border-color: #dcb9b0; }
.btn.wide { width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; background: none; color: var(--navy); cursor: pointer; border-radius: var(--radius); }
.icon-btn:active { background: var(--bg-2); }
.text-btn { border: 0; background: none; color: var(--navy); font-size: 15px; padding: 8px 4px; min-height: 42px; cursor: pointer; }
.text-btn.strong { font-weight: 700; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--bg-2); }
.login-box { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 36px 28px; max-width: 400px; width: 100%; text-align: center; }
.login-logo { margin: 0 0 32px; }
.login-logo img { width: min(260px, 80%); height: auto; display: block; margin: 0 auto; }
.login p { color: var(--muted); line-height: 1.7; margin: 0 0 24px; }
.login .hint { font-size: 12px; margin: 16px 0 0; }

/* ---------- app shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.hd { padding: calc(8px + env(safe-area-inset-top)) 8px 2px; background: var(--bg); }
.hd-brand { display: flex; justify-content: center; padding-bottom: 2px; }
.hd-brand img { height: 22px; width: auto; display: block; }
.hd-row { display: grid; grid-template-columns: 48px 1fr 64px; align-items: center; }
.hd-title { display: flex; align-items: center; justify-content: center; gap: 2px; }
.hd-title h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .06em; color: var(--navy); min-width: 128px; text-align: center; font-variant-numeric: tabular-nums; }
.today-btn { justify-self: end; border: 1px solid var(--line-strong); background: var(--bg); color: var(--navy); border-radius: var(--radius); height: 32px; padding: 0 10px; font-size: 13px; font-weight: 600; cursor: pointer; }

.filters { display: flex; align-items: center; gap: 6px; padding: 4px 12px 8px; overflow-x: auto; }
.fchip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg); color: var(--muted);
  font-size: 12px; cursor: pointer; white-space: nowrap;
}
.fchip[aria-pressed="true"] { color: var(--navy); border-color: var(--navy); font-weight: 600; }
.fchip[aria-pressed="false"] .sw { opacity: .3; }
.sw { width: 10px; height: 10px; background: var(--c); display: inline-block; border-radius: 1px; }
.viewer-badge { margin-left: auto; font-size: 11px; color: var(--muted); border: 1px solid var(--line); padding: 3px 8px; border-radius: var(--radius); white-space: nowrap; }

.notice { margin: 0 12px 8px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg-2); font-size: 13px; line-height: 1.6; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.notice.error { color: var(--danger); border-color: #dcb9b0; }

.main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- month grid ---------- */
.month { flex: 1; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--line); touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.dow { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); }
.dow div { text-align: center; font-size: 11px; padding: 5px 0; color: var(--muted); }
.dow .sun { color: var(--sun); } .dow .sat { color: var(--sat); }
.weeks { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.week { position: relative; flex: 1; min-height: 0; border-bottom: 1px solid var(--line); }
.week:last-child { border-bottom: 0; }
.days { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(7, 1fr); }
.day {
  border: 0; border-right: 1px solid var(--line); background: transparent; padding: 3px 0 0; margin: 0;
  display: flex; justify-content: center; align-items: flex-start; cursor: pointer;
}
.day:last-child { border-right: 0; }
.day .num { font-size: 12px; font-weight: 600; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.day.sun .num { color: var(--sun); } .day.sat .num { color: var(--sat); }
.day.out .num { opacity: .35; }
.day.selected { background: #f4ecd9; }
.day.today .num { background: var(--navy); color: #fffdf7; }
.bars {
  position: absolute; top: 25px; left: 0; right: 0; pointer-events: none;
  display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: var(--bar-h); row-gap: var(--bar-gap);
}
.bar {
  margin: 0 2px; padding: 0 4px; border-radius: var(--radius);
  font-size: 10.5px; line-height: var(--bar-h); white-space: nowrap; overflow: hidden; text-overflow: clip;
}
.bar.solid { background: var(--c); color: #fffdf7; font-weight: 600; }
.bar.soft { background: color-mix(in srgb, var(--c) 14%, #fffdf7); color: var(--c); font-weight: 600; }
.bar.cont-l { margin-left: 0; } .bar.cont-r { margin-right: 0; }
.bar.tentative { opacity: .6; }
.more { font-size: 10px; color: var(--muted); text-align: center; line-height: var(--bar-h); font-weight: 600; }

/* ---------- day sheet ---------- */
.sheet { display: none; background: var(--bg); border-top: 1px solid var(--line-strong); overflow-y: auto; }
.main.sheet-open .sheet { display: block; flex: 0 0 44%; }
.sheet-head { position: sticky; top: 0; background: var(--bg); display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; border-bottom: 1px solid var(--line); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 16px; color: var(--navy); letter-spacing: .04em; }
.sheet-list { list-style: none; margin: 0; padding: 0 0 88px; }
.ev {
  display: grid; grid-template-columns: 52px 12px 1fr; gap: 8px; align-items: start;
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 12px 16px; cursor: pointer;
}
.ev:active { background: var(--bg-2); }
.ev .t { font-size: 12px; color: var(--muted); line-height: 1.45; font-variant-numeric: tabular-nums; }
.ev .dot { width: 10px; height: 10px; margin-top: 4px; background: var(--c); border-radius: 1px; }
.ev .ttl { font-size: 14px; font-weight: 600; line-height: 1.45; word-break: break-word; }
.ev .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.empty { padding: 20px 16px; color: var(--muted); font-size: 13px; }

.fab {
  position: fixed; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 5;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--navy); color: #fffdf7;
  display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- dialogs (bottom sheet on mobile) ---------- */
.dlg {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 100%; max-height: 92vh;
  background: var(--bg); color: var(--text); border-radius: var(--radius) var(--radius) 0 0;
}
.dlg::backdrop { background: rgba(27, 42, 65, .4); }
.dlg-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 6px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.dlg-head > :first-child { justify-self: start; } .dlg-head > :last-child { justify-self: end; }
.dlg-head h2 { margin: 0; font-size: 15px; color: var(--navy); }
.dlg-body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }

.title-input { width: 100%; border: 0; border-bottom: 1px solid var(--line-strong); background: none; font: inherit; font-size: 19px; font-weight: 600; padding: 8px 0; color: var(--text); border-radius: 0; }
.title-input:focus { outline: none; border-bottom-color: var(--navy); }
.swatches { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.swatches label { cursor: pointer; }
.swatches input { position: absolute; opacity: 0; pointer-events: none; }
.swatches i { display: block; width: 28px; height: 28px; background: var(--c); border-radius: var(--radius); outline: 2px solid transparent; outline-offset: 2px; }
.swatches input:checked + i { outline-color: var(--navy); }
.swatches input:focus-visible + i { outline-color: var(--gold); }
.row-line { display: flex; align-items: center; gap: 12px; min-height: 50px; border-bottom: 1px solid var(--line); }
.row-line > span { width: 44px; flex: none; font-size: 13px; color: var(--muted); }
.row-line input:not([type=checkbox]), .row-line textarea { flex: 1; min-width: 0; border: 0; background: none; font: inherit; font-size: 16px; color: var(--text); padding: 10px 0; }
.row-line textarea { resize: vertical; }
.row-line input:focus, .row-line textarea:focus { outline: none; }
.memo-line { align-items: flex-start; } .memo-line > span { padding-top: 14px; }
.dt { flex: 1; display: flex; gap: 8px; justify-content: flex-end; }
.dt input { flex: 0 1 auto !important; text-align: right; }
.switch { margin-left: auto; width: 20px; height: 20px; accent-color: var(--navy); }
.form-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }
.form-note { color: var(--muted); font-size: 11px; margin: 14px 0 0; line-height: 1.6; }

/* detail */
.dt-title { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
.dt-title .dot { width: 14px; height: 14px; margin-top: 6px; background: var(--c); border-radius: 1px; flex: none; }
.dt-title h3 { margin: 0; font-size: 19px; line-height: 1.45; word-break: break-word; }
.dt-row { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; line-height: 1.6; word-break: break-word; }
.dt-row svg { width: 18px; height: 18px; color: var(--muted); margin-top: 2px; }
.dt-row .memo { white-space: pre-wrap; max-height: 40vh; overflow-y: auto; }
.dt-actions { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 16px; }

/* settings */
.set-sec { padding: 16px 0; border-bottom: 1px solid var(--line); }
.set-sec:last-child { border-bottom: 0; }
.set-sec h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .06em; }
.set-sec p { margin: 0 0 12px; line-height: 1.7; font-size: 13px; }
.set-sec .btns { display: flex; gap: 10px; flex-wrap: wrap; }
.copy-box { display: flex; gap: 8px; margin: 10px 0; }
.copy-box input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 8px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg-2); color: var(--text); }
.toggle-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 14px; cursor: pointer; }
.toggle-line small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--navy); color: #fffdf7; padding: 10px 16px; border-radius: var(--radius); font-size: 13px; z-index: 50; }

/* ---------- wide screens ---------- */
@media (min-width: 900px) {
  :root { --bar-h: 19px; }
  .bar { font-size: 12px; }
  .hd { display: flex; align-items: center; gap: 12px; padding: 10px 16px 4px; }
  .hd-brand { padding: 0 0 0 4px; }
  .hd-brand img { height: 30px; }
  .hd-row { flex: 1; grid-template-columns: 48px 1fr 80px; }
  .hd-title h1 { font-size: 20px; }
  .filters { padding: 4px 20px 10px; }
  .notice { margin: 0 20px 10px; }
  .main { flex-direction: row; }
  .month { border-right: 1px solid var(--line); }
  .sheet, .main.sheet-open .sheet { display: block; flex: 0 0 340px; border-top: 1px solid var(--line); }
  .sheet-close { display: none; }
  .day .num { font-size: 13px; width: 24px; height: 24px; line-height: 24px; }
  .bars { top: 30px; }
  .dlg { margin: auto; max-width: 480px; border-radius: var(--radius); }
}
