:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #1c2230;
  --muted: #667085;
  --border: #d9dee6;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --inuse-bg: #e7f5f3;
  --danger: #b42318;
  --warn-bg: #fff6e0;
  --warn: #8a5a00;
  --ok: #067647;
  --radius: 12px;
  color-scheme: light;
  font-family: system-ui, -apple-system, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Yu Gothic UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101318;
    --surface: #1a1e25;
    --surface-2: #20252d;
    --text: #e8eaee;
    --muted: #9aa3b0;
    --border: #2f3641;
    --primary: #2bb3a3;
    --primary-ink: #04201c;
    --inuse-bg: #12302c;
    --danger: #f97066;
    --warn-bg: #3a2c0c;
    --warn: #f5c56b;
    --ok: #47cd89;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- ヘッダー ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 8px 18px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 600; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--primary); color: var(--primary-ink); }
.clock { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }

/* ---------- 部品 ---------- */
button, .button {
  font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 42px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; touch-action: manipulation;
}
button:hover, .button:hover { background: var(--surface-2); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
button.primary:hover { filter: brightness(1.08); background: var(--primary); }
button.danger { color: var(--danger); border-color: currentColor; background: transparent; }
button.big { min-height: 52px; padding: 10px 28px; font-size: 18px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
input, select, textarea {
  font: inherit; width: 100%; min-height: 42px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
input[type='number'] { text-align: right; font-variant-numeric: tabular-nums; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0 14px; }
.form-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.readonly { min-height: 42px; display: flex; align-items: center; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 40px; padding: 6px 14px; border-radius: 999px; }
.chip[aria-pressed='true'] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }

/* ---------- 会計画面 ---------- */
.summary-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.table-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.table-card {
  display: flex; flex-direction: column; min-height: 230px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.table-card.in-use { background: var(--inuse-bg); border: 2px solid var(--primary); }
.table-card header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 0; }
.table-card h3 { margin: 0; font-size: 20px; }
.badge { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; }
.in-use .badge { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.card-body { flex: 1; padding: 4px 14px; }
.free-body { display: flex; align-items: center; justify-content: center; }
.elapsed { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.meta { font-size: 14px; color: var(--muted); }
.meta.note { color: var(--text); }
.amount { margin-top: 6px; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.amount small { margin-left: 6px; font-size: 12px; font-weight: 400; color: var(--muted); }
/* 個人ごとの表示 */
.register-hint { margin: -4px 0 12px; font-size: 13px; }
.waiting-panel { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 10px 14px 12px; margin-bottom: 14px; }
.waiting-panel h2 { margin: 0 0 8px; font-size: 16px; }
.waiting-panel h2 small { font-weight: 400; font-size: 13px; margin-left: 6px; }
.waiting-panel p { margin: 0; }
.card-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-summary .elapsed { font-size: 28px; }
.card-summary .amount { margin-top: 0; font-size: 20px; }
.player-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 4px; }
.player-list.row { flex-direction: row; flex-wrap: wrap; margin: 0; }
.player-list.row .player-chip { width: auto; min-width: 220px; }
.player-chip {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; align-items: baseline;
  width: 100%; min-height: 44px; padding: 5px 10px; text-align: left; line-height: 1.35;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; font-weight: 400;
}
.player-chip:hover { border-color: var(--primary); }
.player-chip { cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.player-chip.dragging { opacity: 0.35; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; margin: 0;
  border-color: var(--primary); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25); opacity: 0.95;
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }
.table-card.drop-target { outline: 3px dashed var(--primary); outline-offset: 3px; background: var(--inuse-bg); }
.player-chip .pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-chip.member .pname::before { content: '★'; color: var(--primary); margin-right: 3px; font-size: 12px; }
.player-chip .pamt { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; text-align: right; }
.player-chip .psub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-chip .pgroup { margin-left: 6px; padding: 0 6px; border: 1px solid var(--border); border-radius: 999px; }
.player-chip .ptime { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
details.person { border: 1px solid var(--border); border-radius: 10px; margin: 8px 0; background: var(--surface); }
details.person > summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 10px 12px; cursor: pointer; }
details.person > summary .pname { font-weight: 700; }
details.person > summary .ptype { font-size: 13px; color: var(--muted); }
details.person > summary .ptime { font-size: 13px; }
details.person > summary .pamt { margin-left: auto; font-variant-numeric: tabular-nums; }
.person-body { padding: 0 12px 10px; }
.person-body .stints { margin: 0 0 6px; font-size: 14px; }
.status-line { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.check-line { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.check-line input, .who-row input { width: 20px; height: 20px; }
details.who { margin: 10px 0; }
details.who > summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.who-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; margin-top: 8px; }
.who-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.mt { margin-top: 8px; }
.member-chips { max-height: 220px; overflow-y: auto; }
.card-footer { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px 14px 14px; }
.card-footer.single { grid-template-columns: 1fr; }
.card-footer button { padding: 8px 4px; }

/* ---------- モーダル ---------- */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: none; border-radius: 16px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
}
dialog.wide { width: min(760px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 14, 20, 0.5); }
.modal-body { padding: 20px 22px; }
.modal-title { margin: 0 0 14px; font-size: 20px; }
.sub { margin: 18px 0 8px; font-size: 15px; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.actions .spacer { flex: 1; }
.meta-line { margin: -4px 0 8px; font-size: 14px; }

.steppers { border-top: 1px solid var(--border); }
.stepper-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 46px; height: 46px; padding: 0; font-size: 22px; }
.stepper output { min-width: 2.2ch; text-align: center; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper.small button { width: 36px; height: 36px; min-height: 36px; font-size: 18px; }
.stepper.small output { font-size: 16px; }
.qty-cell { width: 1%; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.product-grid button { flex-direction: column; min-height: 64px; }
.product-grid small { color: var(--muted); }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.data th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.data th.num, table.data td.num { text-align: right; }
table.data tfoot td { font-weight: 700; border-bottom: none; }
table.data.compact { margin-bottom: 10px; font-size: 13px; }
table.data.compact th, table.data.compact td { padding: 4px 8px; white-space: nowrap; }
table.data tr.subtotal td { font-weight: 700; border-bottom-width: 2px; }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 11px; font-weight: 700; background: var(--primary); color: var(--primary-ink); }
.rate-note { margin: 0 0 8px; padding: 6px 10px; border-radius: 8px; font-size: 13px; background: var(--warn-bg); color: var(--warn); }
.sub.cat { margin: 12px 0 6px; font-size: 13px; color: var(--muted); }
.sub.cat:first-of-type { margin-top: 0; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; margin: 4px 0 10px; }
.switch input, .check-cell input { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); }
.check-cell { text-align: center; }
.form-grid.days { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--surface-2); }
.usage { margin: 4px 0 8px; }
.hint { font-size: 13px; color: var(--muted); }

.total-box {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 14px 0 2px; padding: 12px 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border);
}
.total-box .value { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tax-note { text-align: right; font-size: 13px; margin-bottom: 10px; }
.cash-area { padding: 12px 0 0; border-top: 1px dashed var(--border); }
.quick { margin: -4px 0 10px; }
.change-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 18px; }
.change-row strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.change-row .change { color: var(--ok); }
.change-row .short { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 1000;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  padding: 12px 20px; border-radius: 10px; background: #1c2230; color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 管理画面 ---------- */
.admin-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 16px; align-items: start; }
.admin-tabs { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 4px; }
.admin-tabs button { justify-content: flex-start; border-color: transparent; background: transparent; }
.admin-tabs button.active { background: var(--surface); border-color: var(--border); font-weight: 700; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 6px; font-size: 18px; }
.panel > .hint { margin: 0 0 14px; }
.edit-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.edit-table th { padding: 4px 6px; font-size: 12px; color: var(--muted); text-align: left; white-space: nowrap; }
.edit-table td { padding: 4px 6px; }
.edit-table input { min-width: 90px; }
.edit-table td:first-child input { min-width: 150px; }
.edit-table input[type='time'] { min-width: 110px; }
.row-actions { width: 1%; white-space: nowrap; }
.row-actions button { min-height: 38px; padding: 4px 10px; }
.notice { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-top: 8px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.ok { background: var(--inuse-bg); color: var(--ok); }
.error-box { margin-bottom: 16px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--danger); color: var(--danger); background: var(--surface); }
.error-box ul { margin: 6px 0 0; padding-left: 20px; }
.save-bar {
  position: sticky; bottom: 12px; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px 16px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
.save-bar .spacer { flex: 1; }
.sim-result { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.filter-row { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.filter-row .field { margin-bottom: 0; width: 170px; }
.pin-box { max-width: 360px; margin: 60px auto; }
.error-text { color: var(--danger); margin: 8px 0 0; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .clock { font-size: 13px; }
  .admin-layout { grid-template-columns: minmax(0, 1fr); }
  .admin-tabs { position: static; flex-direction: row; overflow-x: auto; }
  .admin-tabs button { white-space: nowrap; }
  .form-grid2 { grid-template-columns: 1fr; }
  .card-footer { grid-template-columns: repeat(2, 1fr); }
  .total-box .value { font-size: 26px; }
}

/* ---------- お店のアカウント（ログイン・保存の状態） ---------- */
.sync { font-size: 12px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; color: var(--muted); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.sync:empty { display: none; }
.sync.ok { color: var(--ok); border-color: currentColor; }
.sync.ok::before { content: '● '; }
.sync.sending { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.sync.offline, .sync.error { color: var(--danger); border-color: currentColor; font-weight: 600; }
body.auth .nav, body.auth .sync { visibility: hidden; }
.login-box { max-width: 440px; margin: 40px auto; }
.login-box h2 { margin-top: 0; }
.login-box hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0 12px; }
.login-box .field { margin-bottom: 12px; }
.store-list { display: grid; gap: 8px; margin: 12px 0; }
.store-list button { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px; text-align: left; }
.store-list small { color: var(--muted); }
.sync:not(:empty) { margin-left: auto; }
.sync:not(:empty) + .clock { margin-left: 0; }
.boot-msg { text-align: center; padding: 60px 0; }
