:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --text: #1d2321;
  --muted: #66706c;
  --line: #dde2df;
  --primary: #1f6f5c;
  --primary-ink: #ffffff;
  --primary-soft: #e3f1ec;
  --day: #e8902a;
  --day-soft: #fdf0de;
  --night: #3b5bb5;
  --night-soft: #e5ebfa;
  --both: #1f8a5b;
  --both-soft: #def3e8;
  --off: #8a8f8d;
  --off-soft: #eceeed;
  --warn: #c0392b;
  --warn-soft: #fbe5e2;
  --sun: #c0392b;
  --sat: #2f62c4;
  --radius: 12px;
  --nav-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--primary); color: var(--primary-ink);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 17px; }
.who { font-size: 13px; opacity: .9; }

.container { max-width: 760px; margin: 0 auto; padding: 16px; }
.container.wide { max-width: 1200px; }

h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 20px 0 8px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 600;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--warn); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label.field { display: block; font-size: 13px; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; }
input[type=text], input[type=password], input[type=month], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  font-size: 16px; /* iOS のズーム防止 */
}
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.check input { width: 20px; height: 20px; }

.error { color: var(--warn); font-size: 14px; margin-top: 8px; }

/* ----- 月タブ ----- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.tab {
  flex: none; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px;
}
.tab[aria-selected=true] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--off-soft); color: var(--muted);
}
.badge.open { background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.new { background: #fff3c4; color: #8a6400; }
.badge.role-社員 { background: #e9e3f7; color: #5b3fa0; }
.badge.role-パート { background: var(--day-soft); color: #9a5a10; }

/* ----- 希望カレンダー ----- */
.progress { height: 8px; border-radius: 999px; background: var(--off-soft); overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .2s; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.cal .dow.sun { color: var(--sun); } .cal .dow.sat { color: var(--sat); }
.cell {
  aspect-ratio: 1 / 1.05; min-height: 48px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 4px 2px; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
}
.cell:disabled { cursor: default; }
.cell .d { font-size: 13px; font-weight: 600; line-height: 1; }
.cell.sun .d { color: var(--sun); } .cell.sat .d { color: var(--sat); }
.cell .v { font-size: 13px; font-weight: 700; line-height: 1.2; min-height: 1.2em; }
.cell.c-day { background: var(--day-soft); border-color: var(--day); } .cell.c-day .v { color: var(--day); }
.cell.c-night { background: var(--night-soft); border-color: var(--night); } .cell.c-night .v { color: var(--night); }
.cell.c-both { background: var(--both-soft); border-color: var(--both); } .cell.c-both .v { color: var(--both); }
.cell.c-off { background: var(--off-soft); border-color: var(--off); } .cell.c-off .v { color: var(--off); }
.cell.pop { animation: pop .18s ease-out; }
@keyframes pop { 50% { transform: scale(.92); } }

/* 塗りパレット（画面下に固定） */
.palette {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.08);
}
.palette.cols-2 { grid-template-columns: repeat(2, 1fr); }
.pal {
  min-height: 48px; border-radius: 10px; border: 2px solid transparent; cursor: pointer;
  font-weight: 700; font-size: 14px; line-height: 1.15; padding: 4px;
}
.pal small { display: block; font-weight: 500; font-size: 11px; opacity: .85; }
.pal.day { background: var(--day-soft); color: #9a5a10; }
.pal.night { background: var(--night-soft); color: var(--night); }
.pal.both { background: var(--both-soft); color: var(--both); }
.pal.off { background: var(--off-soft); color: #555; }
.pal[aria-pressed=true] { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; }

/* ----- 店長：日別リスト ----- */
.daylist { display: flex; flex-direction: column; gap: 6px; }
.dayrow { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.dayrow > summary {
  list-style: none; cursor: pointer; display: grid;
  grid-template-columns: 84px 1fr 1fr; gap: 8px; align-items: center; padding: 10px 12px;
}
.dayrow > summary::-webkit-details-marker { display: none; }
.dayrow .date { font-weight: 700; }
.dayrow .date.sun { color: var(--sun); } .dayrow .date.sat { color: var(--sat); }
.slot { font-size: 13px; white-space: nowrap; }
.dayrow .warns { display: flex; gap: 4px; flex-wrap: wrap; }
.dayrow .warns:empty { display: none; }
@media (max-width: 560px) { .dayrow .warns { grid-column: 1 / -1; } }
@media (min-width: 561px) { .dayrow > summary { grid-template-columns: 96px 120px 120px 1fr; } }
.slot b { font-size: 17px; }
.slot.day b { color: var(--day); } .slot.night b { color: var(--night); }
.dayrow.has-warn { border-color: var(--warn); }
.dayrow .detail { padding: 0 12px 12px; display: grid; gap: 10px; }
.names { display: flex; flex-wrap: wrap; gap: 4px; }
.name {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line); font-size: 13px;
}
.name .tag { font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: 4px; }
.tag.t-社員 { background: #e9e3f7; color: #5b3fa0; }
.tag.t-パート { background: var(--day-soft); color: #9a5a10; }
.tag.t-new { background: #fff3c4; color: #8a6400; }
.tag.t-both { background: var(--both-soft); color: var(--both); }

/* ----- 店長：一覧表 ----- */
.grid-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 12px; }
table.grid th, table.grid td {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 4px 2px; text-align: center; min-width: 30px; white-space: nowrap;
}
table.grid thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; }
table.grid th.namecol { position: sticky; left: 0; background: var(--surface); z-index: 1; text-align: left; padding: 4px 8px; min-width: 96px; }
table.grid thead th.namecol { z-index: 3; }
table.grid .sun { color: var(--sun); } table.grid .sat { color: var(--sat); }
table.grid td.c-day { background: var(--day-soft); color: #9a5a10; font-weight: 700; }
table.grid td.c-night { background: var(--night-soft); color: var(--night); font-weight: 700; }
table.grid td.c-both { background: var(--both-soft); color: var(--both); font-weight: 700; }
table.grid td.c-off { color: var(--off); }
table.grid td.warn { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
table.grid tfoot th, table.grid tfoot td { background: #fafbfa; font-weight: 700; }

/* ----- リスト（スタッフ・ルール） ----- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.item.off { opacity: .55; }
.item .title { font-weight: 700; }
.item p { margin: 4px 0 0; white-space: pre-wrap; font-size: 14px; color: #39413e; }

/* ----- 下部ナビ ----- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; gap: 2px;
}
.bottomnav a .ico { font-size: 20px; line-height: 1; }
.bottomnav a[aria-current=page] { color: var(--primary); }

/* ----- ダイアログ ----- */
dialog {
  border: none; border-radius: 16px; padding: 0; width: min(92vw, 460px);
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form { padding: 18px; }
dialog h2 { margin-top: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 90px); transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 8px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; white-space: nowrap;
}
.toast.show { opacity: .92; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--warn); }

@media (min-width: 700px) {
  .cell { aspect-ratio: auto; min-height: 64px; }
}

/* ----- ルール：設定内容 ----- */
.item p.setting { background: var(--primary-soft); color: var(--primary); font-weight: 600; padding: 6px 10px; border-radius: 8px; }
table.mini { border-collapse: collapse; }
table.mini th, table.mini td { padding: 4px 6px; text-align: left; white-space: nowrap; font-size: 14px; }
table.mini th { color: var(--muted); font-weight: 600; }
dialog select { width: auto; }

/* ----- シフト作成 ----- */
.shiftday { padding: 10px; }
.shiftday > .date { font-weight: 700; margin-bottom: 6px; }
.shiftday > .date.sun { color: var(--sun); } .shiftday > .date.sat { color: var(--sat); }
.slots { display: grid; gap: 8px; }
@media (min-width: 760px) { .slots { grid-template-columns: 1fr 1fr; } }
.slotblock { border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; padding: 8px; display: grid; gap: 6px; align-content: start; }
.slotblock.day { border-left-color: var(--day); }
.slotblock.night { border-left-color: var(--night); }
.slotblock.has-warn { background: #fff8f7; }
.slotblock .slotname { font-size: 15px; }
.slotblock.day .slotname { color: var(--day); } .slotblock.night .slotname { color: var(--night); }
.slotblock .warns { display: flex; flex-wrap: wrap; gap: 4px; }
.members { display: grid; gap: 4px; }
.member { display: grid; grid-template-columns: 1fr auto auto 32px; gap: 6px; align-items: center; padding: 2px 0; }
.member .mname { font-size: 14px; display: flex; align-items: center; gap: 3px; flex-wrap: wrap; min-width: 0; }
.member.outside .mname { color: var(--warn); }
.member .start { width: 84px; min-height: 34px; padding: 2px 6px; font-size: 14px; }
.duty { min-height: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); font-size: 12px; font-weight: 700; cursor: pointer; width: 70px; }
.duty.kitchen { background: #fdeee9; color: #b4471f; border-color: #f3c7b8; }
.duty.hall { background: #eef3fb; color: #2f5aa8; border-color: #c9d7f1; }
.x { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--muted); }
.tag.t-out { background: var(--warn-soft); color: var(--warn); }
.candlist { display: grid; gap: 4px; max-height: 50vh; overflow: auto; }
.cand { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; min-height: 44px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.cand:hover { border-color: var(--primary); }
table.grid.person td, table.grid.person th { padding: 6px 8px; }
table.grid.person td.issues { text-align: left; color: var(--warn); white-space: normal; min-width: 160px; }
table.grid tr.warnrow th.namecol { color: var(--warn); }

/* ----- 確定シフト ----- */
.myshift { display: grid; grid-template-columns: 96px 32px 1fr auto; align-items: center; gap: 8px; border-left-width: 4px; }
.myshift.day { border-left-color: var(--day); } .myshift.day b { color: var(--day); }
.myshift.night { border-left-color: var(--night); } .myshift.night b { color: var(--night); }
.myshift .date.sun, .dayrow .date.sun { color: var(--sun); } .myshift .date.sat { color: var(--sat); }
.name.me { border-color: var(--primary); background: var(--primary-soft); font-weight: 700; }

/* ----- 定休日 ----- */
.cell.closed { background: repeating-linear-gradient(-45deg, #eceeed, #eceeed 5px, #e2e5e3 5px, #e2e5e3 10px); border-color: #d5d9d7; cursor: default; }
.cell.closed .v { color: #8a8f8d; }
button.cell.closed { cursor: pointer; }
.cell.extra-closed { border-color: var(--warn); }
.cell.extra-closed .v { color: var(--warn); }
.cell.extra-open { border-color: var(--both); background: var(--both-soft); }
.cell.extra-open .v { color: var(--both); }
.dayrow.closed { background: repeating-linear-gradient(-45deg, #f3f4f3, #f3f4f3 6px, #eceeed 6px, #eceeed 12px); }
.closedrow { display: flex; gap: 12px; align-items: center; padding: 8px 12px; }
.closedrow .date { font-weight: 700; }
.closedrow .date.sun { color: var(--sun); } .closedrow .date.sat { color: var(--sat); }
table.grid th.closed, table.grid td.closed { background: #eceeed; color: #9a9f9d; }
.wdpick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.wd { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.wd.sun { color: var(--sun); } .wd.sat { color: var(--sat); }
.wd[aria-pressed=true] { background: #5d6461; border-color: #5d6461; color: #fff; }
dialog .cal .cell { aspect-ratio: auto; min-height: 46px; }
table.grid td.offtarget { background: #fff3c4; color: #8a6400; }
