/* Kasey Labs 標準10章の配色（design.md 6.2） */
:root {
  --bg: #151a1b;
  --panel: #1c2324;
  --panel-2: #243032;
  --line: #2e3a3c;
  --text: #e9edeb;
  --muted: #9aa5a2;
  --accent: #b5c6aa;
  --on-accent: #151a1b;
  --danger: #e59a8c;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 Manrope, 'Noto Sans JP', -apple-system, system-ui, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 24px 4px 8px; }

/* 全体の枠：スマホは下タブ、768px〜は左メニュー */
.shell { min-height: 100vh; }
main { padding: 16px 16px calc(var(--tabs-h) + 32px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; outline: none; }
.tabs {
  position: fixed; z-index: 10; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  height: var(--tabs-h); display: flex; background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; box-shadow: 0 6px 24px rgba(0,0,0,.4); padding: 6px;
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; border-radius: 16px; }
.tabs a .ic { font-size: 18px; line-height: 1; }
.tabs a[aria-current="page"] { color: var(--on-accent); background: var(--accent); }
.tabs .brand { display: none; }
/* スマホだけ：上のヘッダー（アプリ名）。768px〜は左メニューにあるので出さない */
.appbar { position: sticky; top: 0; z-index: 9; background: rgba(21, 26, 27, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); padding: calc(8px + env(safe-area-inset-top)) 16px 8px; }
.appbar a { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 16px; }
.appbar img { border-radius: 7px; display: block; }
@media (min-width: 768px) {
  .shell { display: grid; grid-template-columns: 220px 1fr; }
  .appbar { display: none; }
  .tabs { position: sticky; top: 0; left: auto; right: auto; bottom: auto; height: 100vh; flex-direction: column;
    border-radius: 0; border-width: 0 1px 0 0; box-shadow: none; padding: 16px 12px; gap: 4px; }
  .tabs a { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; font-size: 15px; }
  .tabs .brand { display: block; color: var(--text); font-weight: 700; font-size: 17px; padding: 6px 14px 18px; }
  main { padding: 32px; width: 100%; }
}

/* 区切られたリスト */
.group { background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.group > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px; color: var(--text); text-decoration: none; }
a.row::after { content: '›'; margin-left: auto; color: var(--muted); font-size: 20px; }
.row .sub { color: var(--muted); font-size: 13px; }
.row .grow { flex: 1; min-width: 0; }
.empty { color: var(--muted); padding: 16px; text-align: center; }
.note { color: var(--muted); font-size: 13px; margin: 6px 4px; }

/* 入力欄 */
.field { display: block; padding: 10px 16px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.field input:not([type=checkbox]):not([type=range]):not([type=color]), .field textarea, .field select {
  width: 100%; font: inherit; color: var(--text); background: transparent; border: 0; padding: 4px 0; outline: none;
}
.field textarea { resize: vertical; min-height: 3.2em; }
.field select { appearance: none; }
.field .err { color: var(--danger); font-size: 12px; }
.field.invalid input { color: var(--danger); }
.check { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* 丸い切り替えボタン（iPhone版 Kit の Segmented と同じ見た目） */
.seg { display: flex; background: var(--bg); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { flex: 1; font: inherit; font-size: 14px; border: 0; border-radius: 999px; padding: 6px 10px; background: transparent; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* ボタン */
.btn { display: inline-flex; align-items: center; justify-content: center; font: inherit; font-weight: 600; border: 0; border-radius: 999px;
  padding: 10px 20px; background: var(--panel-2); color: var(--text); cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .4; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }

.seal-preview { max-width: 96px; max-height: 96px; background: #fff; border-radius: 8px; padding: 4px; }

#toast { position: fixed; z-index: 30; left: 50%; bottom: calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }

/* シート（下から出る確認画面） */
dialog.sheet { border: 0; padding: 20px; background: var(--panel); color: var(--text); border-radius: 18px; width: min(480px, calc(100% - 24px)); }
dialog.sheet::backdrop { background: rgba(0,0,0,.55); }
dialog.sheet p { margin: 0 0 12px; }
dialog.sheet .actions { flex-direction: column; margin-bottom: 0; }

/* 書類 */
.right { text-align: right; flex-shrink: 0; }
.badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.badge.issued { background: #3b4a55; color: #cfe0ea; }
.badge.paid { background: var(--accent); color: var(--on-accent); }
.accent { color: var(--accent); font-weight: 600; }
button.row { width: 100%; font: inherit; background: transparent; border: 0; text-align: left; cursor: pointer; }
.btn.link, button.link { background: none; border: 0; font: inherit; font-size: 13px; color: var(--accent); cursor: pointer; padding: 0; }
button.link.danger { color: var(--danger); }
.item { margin-bottom: 10px; }
.item-head { padding: 8px 16px 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr 1.4fr; }
.cols > * + * { border-left: 1px solid var(--line); }
.totalbar { position: sticky; bottom: calc(var(--tabs-h) + 20px + env(safe-area-inset-bottom)); z-index: 5; margin-top: 20px;
  display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: var(--radius); padding: 10px 10px 10px 16px; box-shadow: 0 4px 16px rgba(0,0,0,.35); }
.totalbar strong { font-size: 20px; }
.pages canvas, .live canvas { display: block; margin: 0 auto 16px; border-radius: 4px; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.warn { background: #3a2f22; color: #f0d9b5; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 14px; }
.warn ul { margin: 6px 0 0; padding-left: 1.2em; }
dialog.sheet .pick { max-height: 60vh; overflow: auto; margin-top: 12px; }
dialog.sheet .group + .pick { margin-top: 8px; }
dialog.sheet > .group { margin-top: 12px; }
@media (min-width: 768px) {
  .totalbar { bottom: 16px; }
}
@media (min-width: 1100px) {
  main:has(.edit-wide) { max-width: none; }
  .edit-wide { display: grid; grid-template-columns: minmax(380px, 520px) 1fr; gap: 32px; align-items: start; }
  .live { position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow: auto; }
}
.check input[type=color] { width: 44px; height: 30px; border: 0; padding: 0; background: none; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ホーム */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 768px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 16px; background: var(--panel); border-radius: var(--radius); color: var(--text); text-decoration: none; min-height: 84px; justify-content: center; }
.tile-name { font-size: 17px; font-weight: 700; }
.tile-add { font-size: 13px; color: var(--accent); }
.tile:active { background: var(--panel-2); }
