:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e0e2e7;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #3b6fd6;
  --primary-hover: #2f5bb8;
  --danger: #d5473c;
  --today-bg: #eaf1ff;
  --day-off-bg: #eceef1;
  --radius: 8px;
  --client-oc: #3b6fd6;
  --client-as: #23a06b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.config-banner {
  background: #fff3cd;
  color: #664d03;
  padding: 10px 16px;
  font-size: 14px;
  text-align: center;
  border-bottom: 1px solid #ffe69c;
}
.hidden { display: none !important; }

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.app-header h1 {
  font-size: 18px;
  margin: 0;
  margin-right: 8px;
}

.view-tabs { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.view-tab {
  border: none;
  background: var(--surface);
  padding: 6px 14px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
}
.view-tab + .view-tab { border-left: 1px solid var(--border); }
.view-tab.active { background: var(--primary); color: #fff; }

.date-nav { display: flex; align-items: center; gap: 6px; }
.date-nav button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 5px 10px;
  cursor: pointer;
}
.current-label { font-weight: 600; margin-left: 6px; min-width: 140px; cursor: pointer; }
.current-label:hover { text-decoration: underline; }
.current-label-wrap { position: relative; display: flex; justify-content: center; }
#current-label::after { content: " ▾"; font-size: 0.8em; color: var(--text-muted); } /* 押すと月/日を選べることを示す */
/* タッチ端末（iPhone等）の日・週表示は、日付入力をラベルに透明で重ねてタップで直接カレンダーを開く */
@media (hover: none) {
  .current-label-wrap.date-mode .jump-input { top: 0; left: 0; width: 100%; height: 100%; pointer-events: auto; font-size: 16px; }
}

.month-picker {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  width: 250px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  cursor: default;
}
.month-picker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 600; }
.month-picker button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 8px 0;
  cursor: pointer;
  color: var(--text);
}
.month-picker-head button { padding: 5px 12px; }
.month-picker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.month-picker-grid button { font-size: 14px; white-space: nowrap; }
.month-picker-grid button.this-month { border-color: var(--primary); color: var(--primary); }
.month-picker-grid button.selected { background: var(--primary); border-color: var(--primary); color: #fff; }
.month-picker-this { width: 100%; margin-top: 8px; }
.jump-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: none;
  opacity: 0;
  pointer-events: none;
}

.client-filter { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-muted); }
.client-filter select {
  padding: 5px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* スタッフ絞り込み（複数選択）: ボタンを押すとチェックボックスの一覧が開く */
.multi-select { position: relative; }
.multi-select-btn {
  position: relative;
  max-width: 180px;
  padding: 5px 24px 5px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.multi-select-btn::after { content: "▾"; position: absolute; right: 8px; color: var(--text-muted); }
.multi-select-btn.active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.multi-select-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  width: 240px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  color: var(--text);
}
.multi-select-hint { margin: 0 0 6px; font-size: 12px; color: var(--text-muted); }
.multi-select-list { max-height: 300px; overflow-y: auto; overscroll-behavior: contain; }
.multi-select-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-radius: 4px; font-size: 14px; cursor: pointer; }
.multi-select-item:hover { background: var(--bg); }
.multi-select-item input { width: 16px; height: 16px; cursor: pointer; }
.multi-select-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.multi-select-actions button:not(.primary) {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
}

.hide-unavailable-toggle { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.hide-unavailable-toggle input { cursor: pointer; }

.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; margin-left: auto; }
.header-actions button { white-space: nowrap; }
.current-user-label { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.mobile-filter-toggle { display: none; }

/* PC幅はフルの表示、携帯幅は短い表示（名字だけ等）に切り替える */
.label-short { display: none; }
.current-user-label { font-size: 13px; color: var(--text-muted); margin-left: 8px; white-space: nowrap; }
.mobile-menu-toggle { display: none; }

button { font: inherit; }
button.primary {
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
}
button.primary:hover { background: var(--primary-hover); }
.header-actions button:not(.primary) {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
}

.calendar-root { padding: 16px 20px 60px; }

/* ---- Hours legend (クライアント標準時間) ---- */
.hours-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.hours-legend:empty { display: none; }
.hours-legend .legend-item { display: flex; align-items: center; gap: 5px; }
.hours-legend .client-dot { width: 8px; height: 8px; }

.field-hint { font-size: 12px; color: var(--text-muted); margin: -6px 0 12px; }

/* ---- Login screen ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 26px;
  width: min(340px, 100%);
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
}
.login-form h1 { margin: 0 0 4px; font-size: 20px; text-align: center; }
.login-sub { margin: 0 0 18px; text-align: center; color: var(--text-muted); font-size: 13px; }
.login-form label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.login-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.login-form button.primary { width: 100%; padding: 9px 0; margin-top: 4px; }
.login-error { color: var(--danger); font-size: 13px; margin: -4px 0 12px; }
.loading-message { color: var(--text-muted); }

/* ---- Month view ---- */
.month-view-scroll { overflow-x: auto; }
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.month-weekday {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding-bottom: 4px;
}
.month-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 108px;
  min-width: 0;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}
.month-cell:hover { border-color: var(--primary); }
.month-cell.other-month { opacity: 0.45; }
.month-cell.day-off { background: var(--day-off-bg); }
.month-cell.today { background: var(--today-bg); border-color: var(--primary); }
.month-cell.today.day-off { background: var(--today-bg); }
.month-cell-date-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.month-cell-date { font-size: 13px; font-weight: 600; flex-shrink: 0; }
.month-cell-date.clickable-date { cursor: pointer; }
.month-cell-date.clickable-date:hover { text-decoration: underline; }
.month-cell-date-row .event-chip { min-width: 0; max-width: 100%; }
.lock-icon { font-size: 11px; line-height: 1; }
.month-cell-holiday { font-size: 10px; color: var(--danger); line-height: 1.2; overflow-wrap: anywhere; }
.month-cell-shifts { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.shift-chip {
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 4px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.shift-chip.unavailable { opacity: 0.85; }
.shift-chip.pending { text-shadow: 0 0 2px rgba(0, 0, 0, 0.55); } /* 背景は青/緑などの分割グラデーション（JSでインライン指定）。白文字を読みやすくする */
.shift-chip.copy-source { outline: 2px solid var(--primary); outline-offset: 1px; }
.event-chip {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #fff3cd;
  color: #664d03;
  border: 1px solid #ffe69c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.month-cell-more { font-size: 11px; color: var(--text-muted); }

/* ---- 個人メモ（本人にだけ見える。イベントの黄色と区別して薄紫で表示） ---- */
.memo-chip {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #efe9ff;
  color: #4b3a86;
  border: 1px solid #d6c9ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.month-cell-date-row .memo-chip { min-width: 0; max-width: 100%; }
.memo-add-btn { border: none; background: none; padding: 0 2px; font-size: 11px; line-height: 1; cursor: pointer; opacity: 0; margin-left: auto; }
.month-cell:hover .memo-add-btn, .week-table th:hover .memo-add-btn, .memo-add-btn:focus-visible { opacity: 1; }
@media (hover: none) { .memo-add-btn { opacity: 0.4; } } /* タッチ端末はホバーできないため常に薄く表示 */
.week-th-memos { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; font-weight: 400; }
.week-th-memos .memo-chip { white-space: normal; }
.week-th-memos .memo-add-btn { align-self: flex-end; }

/* ---- カレンダーロック ---- */
.month-lock-bar, .day-lock-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.month-lock-bar button, .day-lock-bar button, .table-toolbar > button, .week-copy-btn, .export-actions button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.lock-badge { font-size: 12px; color: #8a6d1f; background: #fff3cd; border: 1px solid #ffe69c; border-radius: 4px; padding: 2px 8px; }
.week-table th.locked { background: #f6f1e4; }

/* ---- Week view ---- */
.week-view { display: flex; flex-direction: column; gap: 24px; }
.week-block-label { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.week-table-wrap { overflow-x: auto; }
.week-table { width: 100%; border-collapse: collapse; background: var(--surface); }
.week-table th, .week-table td {
  border: 1px solid var(--border);
  vertical-align: top;
  padding: 6px;
  min-width: 130px;
}
.week-table th { background: #fafbfc; font-size: 13px; font-weight: 600; text-align: center; }
.week-table th.today { color: var(--primary); }
.week-table th.day-off { background: var(--day-off-bg); }
.week-day-cell { cursor: pointer; min-height: 90px; }
.week-day-cell:hover { background: #fafcff; }
.week-day-cell.day-off { background: var(--day-off-bg); }
.week-day-cell.day-off:hover { background: #e4e6ea; }
.week-day-cell.drag-copy-target, .month-table-cell.drag-copy-target { background: #dbe8ff; outline: 2px dashed var(--primary); outline-offset: -2px; }
.shift-chip[draggable="true"] { cursor: grab; }
.week-staff-name { font-weight: 600; font-size: 13px; padding: 6px; white-space: nowrap; }
.week-cell-shifts { display: flex; flex-direction: column; gap: 4px; }
.week-day-total { text-align: right; font-size: 12px; color: var(--text-muted); background: #fafbfc; }
.week-th-events { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; font-weight: 400; }
.week-th-events .event-chip { white-space: normal; }

/* ---- 月間表（スタッフ×日付の一覧表） ---- */
.month-table-view { display: flex; flex-direction: column; gap: 10px; }
.month-table-wrap { overflow-x: auto; }
.month-table { border-collapse: collapse; background: var(--surface); }
.month-table th, .month-table td {
  border: 1px solid var(--border);
  vertical-align: top;
  padding: 6px;
  min-width: 64px;
}
.month-table th { background: #fafbfc; font-size: 12px; font-weight: 600; text-align: center; white-space: nowrap; }
.month-table th.today { color: var(--primary); }
.month-table th.day-off { background: var(--day-off-bg); }
.month-table th.locked { background: #f6f1e4; }
.month-table td.day-off { background: var(--day-off-bg); }
.month-table-row-label {
  font-weight: 600;
  font-size: 13px;
  padding: 6px 10px;
  white-space: nowrap;
  position: sticky;
  left: 0;
  background: var(--surface);
}
.month-table-cell { cursor: pointer; min-width: 64px; }
.month-table-cell:hover { background: #fafcff; }
.month-table-cell-shifts { display: flex; flex-direction: column; gap: 3px; }
.month-table-cell .shift-chip { text-align: center; }
.month-table-event-cell { min-width: 64px; }
.month-table-event-cell.clickable { cursor: pointer; }
.month-table-event-cell.clickable:hover { background: #fafcff; }
.month-table-total { text-align: center; font-size: 12px; color: var(--text-muted); background: #fafbfc; }

/* ---- Day view ---- */
.day-view { max-width: 720px; margin: 0 auto; }
.day-summary { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--text-muted); font-size: 14px; }
.day-shift-list { display: flex; flex-direction: column; gap: 8px; }
.day-shift-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.day-shift-card:hover { border-color: var(--primary); }
.client-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.day-shift-main { flex: 1; }
.day-shift-name { font-weight: 600; }
.day-shift-meta { font-size: 13px; color: var(--text-muted); }
.day-shift-hours { font-size: 13px; font-weight: 600; color: var(--primary); }
.empty-message { color: var(--text-muted); text-align: center; padding: 30px 0; }
.day-events { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }

/* ---- Modal / dialog ---- */
dialog {
  border: none;
  border-radius: 10px;
  padding: 0;
  width: min(420px, 92vw);
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
dialog::backdrop { background: rgba(20, 24, 35, 0.45); }
dialog form, dialog .panel { padding: 20px; }
dialog h2 { margin: 0 0 14px; font-size: 17px; }
dialog.wide { width: min(760px, 95vw); }
dialog label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
dialog input, dialog select, dialog textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}
dialog textarea { resize: vertical; }
.inline-field { display: flex; gap: 6px; align-items: center; }
.inline-field select { flex: 1; }
.link-btn {
  border: none;
  background: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.time-row { display: flex; gap: 10px; }
.time-row label { flex: 1; }

.checkbox-field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); margin-bottom: 12px; }
.checkbox-field input { width: auto; margin: 0; }

.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }
.modal-actions button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}
.modal-actions button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.modal-actions button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }

.inline-add-form { display: flex; gap: 8px; margin-bottom: 14px; }
.inline-add-form input { flex: 1; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; }
.inline-add-form button { border-radius: 6px; padding: 7px 14px; border: 1px solid var(--primary); cursor: pointer; }

.manage-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.manage-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.manage-list .item-name { flex: 1; font-size: 14px; }
.manage-list .item-name.inactive { color: var(--text-muted); text-decoration: line-through; }
.manage-list button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}
.manage-list button.danger { color: var(--danger); border-color: var(--danger); }
.manage-list select { display: inline-block; width: auto; flex: 0 0 auto; margin-top: 0; padding: 4px 6px; font-size: 12px; }
.manage-list li.access-item { flex-wrap: wrap; align-items: flex-start; }
.staff-access-details { flex: 1 1 220px; font-size: 12px; }
.staff-access-details summary { cursor: pointer; color: var(--text-muted); padding: 4px 0; }
.staff-access-checks { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 6px 0 2px 4px; }
.staff-access-checks label { display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 400; color: var(--text); white-space: nowrap; }
.account-create-form h3 { margin: 0 0 10px; font-size: 14px; }
.account-create-form label { max-width: 320px; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.manage-list li[draggable="true"] { cursor: grab; }
.manage-list li.dragging { opacity: 0.4; }
.manage-list .drag-handle { color: var(--text-muted); font-size: 16px; line-height: 1; cursor: grab; user-select: none; }

/* ---- Attendance view ---- */
.attendance-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 14px;
}
.attendance-controls label { margin-bottom: 0; }
.attendance-controls select { min-width: 160px; }
.attendance-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}
.attendance-summary .summary-main { font-weight: 600; font-size: 14px; color: var(--text); }
.attendance-summary .summary-client { color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.attendance-table-wrap { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.attendance-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.attendance-table th, .attendance-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.attendance-table thead th {
  position: sticky;
  top: 0;
  background: #fafbfc;
  font-weight: 600;
  z-index: 1;
}
.attendance-table tbody tr:hover { background: #fafcff; }
.attendance-table td.attendance-note { white-space: normal; color: var(--text-muted); }
.attendance-table tfoot td { font-weight: 600; background: var(--bg); border-top: 2px solid var(--border); border-bottom: none; }
.attendance-table .empty-row td { text-align: center; color: var(--text-muted); padding: 24px 10px; }

/* ---- 変更履歴（シフト） ---- */
#history-modal.wide { width: min(1040px, 95vw); } /* 内容列（変更前→変更後）が横に切れないよう、他のパネルより広くする */
.history-controls-clear { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 8px 14px; cursor: pointer; }
.history-table-wrap { max-height: 56vh; }
.history-table td { vertical-align: top; }
.history-table td.history-detail { white-space: pre-line; min-width: 260px; }
.history-restore-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.history-restore-btn:hover:not(:disabled) { background: #f0f5ff; border-color: var(--primary); color: var(--primary); }
.history-restore-btn:disabled { opacity: 0.5; cursor: default; }
.history-action { font-weight: 600; }
.history-action.action-INSERT { color: #23a06b; }
.history-action.action-UPDATE { color: var(--primary); }
.history-action.action-DELETE { color: var(--danger); }
.history-table td.history-system { color: var(--text-muted); }

/* 携帯幅では、表だと「内容」と復元ボタンが右にはみ出して見えなくなるため、1件ずつのカード表示にする */
@media (max-width: 640px) {
  .history-table, .history-table tbody { display: block; }
  .history-table thead { display: none; }
  .history-table tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 10px 8px; border-bottom: 1px solid var(--border); }
  .history-table tr.empty-row { display: block; }
  .history-table td { display: block; padding: 0; border: none; white-space: normal; }
  .history-table td.history-detail { flex: 1 1 100%; min-width: 0; margin-top: 2px; }
  .history-table td:last-child { flex: 1 1 100%; text-align: right; }
  .history-table td:empty { display: none; }
  .history-restore-btn { padding: 8px 14px; font-size: 13px; } /* タップしやすい大きさに */
}

/* ---- Payroll view ---- */
.payroll-rate-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.payroll-rate-row label { margin-bottom: 0; }
.payroll-rate-row input { width: 140px; }
.payroll-rate-row button {
  border: 1px solid var(--primary);
  background: var(--surface);
  color: var(--primary);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  height: 37px;
}
.payroll-bonus-section { margin-top: 16px; }
.payroll-bonus-section h3 { margin: 0 0 10px; font-size: 14px; }

/* 携帯（縦向き）と、携帯を横向きにしたとき（高さが低いタッチ端末）に共通の携帯向けレイアウト */
@media (max-width: 640px), (max-height: 500px) and (orientation: landscape) and (hover: none) {
  .app-header { padding: 10px 12px; gap: 8px; }
  .app-header h1 { flex: 1 1 auto; font-size: 16px; margin: 0; order: 1; }

  /* ＋シフト追加とその他の操作は右上のアイコン1つに折りたたみ、タイトルと同じ行に収める */
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    order: 2;
    flex: 0 0 auto;
    width: 40px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
  }
  .header-actions {
    display: none;
    order: 3;
    position: absolute;
    /* ヘッダーは複数行（タイトル・表示切替・日付・絞り込み）になるため、100%だとメニューが画面の下に押し出される。
       1行目（タイトル＋☰ボタン）の直下に出し、ボタンが増えても画面に収まらない分はメニュー内でスクロールさせる */
    top: 56px;
    right: 12px;
    margin-top: 4px;
    max-height: calc(100vh - 72px);
    max-height: calc(100dvh - 72px);
    overflow-y: auto;
    overscroll-behavior: contain;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: min(260px, 90vw);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    padding: 8px;
    margin-left: 0;
    z-index: 20;
  }
  .header-actions.open { display: flex; }
  .header-actions button { width: 100%; padding: 9px 10px; }

  .view-tabs { flex: 1 1 calc(100% - 60px); order: 1; } /* ☰ボタンと同じ1行目に収め、日付は2行目へ */
  .view-tab { flex: 1; padding: 8px 0; }

  .date-nav { flex: 1 1 auto; min-width: 0; justify-content: space-between; order: 5; gap: 4px; }
  .date-nav button { padding: 5px 9px; }
  .current-label-wrap { flex: 1; min-width: 0; }
  .current-label { flex: 1; text-align: center; min-width: 0; font-size: 13px; margin-left: 0; white-space: nowrap; }

  /* スタッフ／クライアント絞り込みは横並びにして高さを節約する */
  .client-filter { flex: 1 1 46%; order: 6; }
  .client-filter select { width: 100%; }
  .client-filter .multi-select { flex: 1; min-width: 0; }
  .multi-select-btn { width: 100%; max-width: none; padding: 7px 24px 7px 8px; }
  .multi-select-panel { width: min(280px, calc(100vw - 24px)); }
  .multi-select-list { max-height: 50vh; max-height: 50dvh; }
  .multi-select-item { padding: 9px 4px; font-size: 15px; } /* タップしやすい大きさに */

  .hide-unavailable-toggle { flex: 1 1 100%; order: 7; justify-content: flex-end; }

  /* 上部を2行（表示切替＋☰／日付＋絞り込み）に詰める。タイトルは省略し、
     スタッフ・クライアント・稼働不可の絞り込みは「絞り込み」ボタンで開閉する */
  .app-header h1 { display: none; }
  .app-header:not(.filters-open) .client-filter,
  .app-header:not(.filters-open) .hide-unavailable-toggle { display: none; }
  .mobile-filter-toggle {
    display: block;
    order: 6;
    flex: 0 0 auto;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
  }
  .mobile-filter-toggle.active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
  .app-header.filters-open .mobile-filter-toggle { background: var(--today-bg); }
  .client-filter { order: 7; }
  .hide-unavailable-toggle { order: 8; }

  .label-full { display: none; }
  .label-short { display: inline; }

  .header-actions .current-user-label { text-align: center; margin: 4px 0 0; }

  .calendar-root { padding: 12px 10px 60px; }
  .hours-legend { padding: 8px 10px; font-size: 11px; }

  /* 月表示は横スクロールさせず、日〜土を画面幅に収める */
  .month-grid { min-width: 0; gap: 3px; }
  .month-cell { min-height: 58px; padding: 3px 2px; gap: 2px; }
  .month-cell-date { font-size: 11px; }
  .month-cell-holiday { font-size: 8px; }
  /* 名字だけの表示にしたぶん文字を大きくする */
  .shift-chip { font-size: 11px; padding: 1px 2px; border-radius: 3px; text-align: center; text-overflow: clip; }
  .event-chip, .memo-chip { font-size: 8px; padding: 1px 3px; border-radius: 3px; }
  .month-cell-more { font-size: 10px; text-align: center; }
  .month-lock-bar button, .day-lock-bar button, .table-toolbar > button, .week-copy-btn, .export-actions button { font-size: 12px; padding: 5px 8px; }

  /* 週表示も横スクロールさせず、日〜土を画面幅に収める（時間は省略しコードのみ表示） */
  /* 来週分はPC画面のみ表示し、モバイルでは今週分だけに絞る */
  .week-block-next { display: none; }
  .week-table-wrap { overflow-x: hidden; }
  .week-table th, .week-table td { min-width: 0; padding: 4px 2px; }
  /* 名前は名字だけ・折り返しなしにして、1文字ずつ縦に並ぶのを防ぐ */
  .week-staff-name { font-size: 12px; padding: 4px 3px; white-space: nowrap; }
  .week-table th { font-size: 10px; padding: 4px 1px; }
  .week-th-wd { display: block; }
  .week-cell-shifts .shift-chip { font-size: 10px; padding: 1px 2px; text-align: center; }
  .week-day-total { font-size: 10px; }

  /* 月間表は列数が多いため横スクロール前提。文字サイズだけ縮小する */
  .month-table th, .month-table td { padding: 4px; min-width: 48px; }
  .month-table th { font-size: 10px; }
  .month-table-row-label { font-size: 12px; padding: 4px 6px; }
  .month-table .shift-chip, .month-table .event-chip, .month-table .memo-chip { font-size: 9px; padding: 1px 3px; }
  .month-table-total { font-size: 10px; }

  /* シフト追加モーダルの時間欄はスマホでは縦積みにしてタップしやすくする */
  .time-row { flex-direction: column; gap: 0; }

  .inline-add-form { flex-wrap: wrap; }
  .inline-add-form input { flex: 1 1 120px; }

  dialog { width: min(420px, 94vw); max-height: 88vh; max-height: 92dvh; overflow-y: auto; }

  /* 入力欄が長くてダイアログがスクロールする場合でも、キャンセル・保存などのボタンを画面下に固定して
     常に押せるようにする（フォームの余白20pxぶんを打ち消して、ダイアログの下端に貼り付ける） */
  dialog .modal-actions {
    position: sticky;
    bottom: 0;
    z-index: 1;
    margin: 6px -20px -20px;
    padding: 12px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  /* iOSは文字サイズが16px未満の入力欄にフォーカスすると画面を自動で拡大してしまう（ログイン時のズーム）。
     携帯幅では入力欄を16px以上にして防ぐ（ピンチ操作による拡大は妨げない） */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px !important; }
}

/* 携帯を横向きにしたとき: 横幅に余裕があるので、上部は1行にまとめ、名前はフルネーム・週表示は来週以降も表示する */
@media (max-height: 500px) and (orientation: landscape) and (hover: none) {
  .view-tabs { flex: 0 0 220px; order: 1; }
  .date-nav { flex: 1 1 auto; order: 2; }
  .mobile-filter-toggle { order: 3; }
  .mobile-menu-toggle { order: 4; }
  .header-actions { top: 50px; max-height: calc(100vh - 60px); max-height: calc(100dvh - 60px); }

  .label-full { display: inline; }
  .label-short { display: none; }

  .shift-chip { font-size: 10px; text-overflow: ellipsis; }

  .week-block-next { display: block; }
  .week-table th { font-size: 12px; padding: 4px 2px; }
  .week-th-wd { display: inline; }
  .week-staff-name { font-size: 12px; padding: 4px 6px; }
  .week-cell-shifts .shift-chip { font-size: 11px; }
}

/* ==========================================================================
   複数社対応版: ログイン・新規登録・会社の登録・ご契約
   ========================================================================== */
.login-screen { flex-direction: column; gap: 16px; }
.auth-card { width: min(400px, 100%); }
.auth-tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 16px;
  padding: 3px;
  background: var(--bg);
  border-radius: var(--radius);
}
.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 7px 4px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}
.auth-tab.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.auth-help { font-size: 12px; color: var(--text-muted); margin: 8px 0 12px; line-height: 1.6; }
.auth-notice {
  background: #eaf1ff;
  color: #1d3f86;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 14px;
}
.login-form .checkbox-field { display: flex; align-items: flex-start; color: var(--text); }
.login-form .checkbox-field input { display: inline-block; width: auto; margin: 3px 0 0; }
.login-form .link-btn { display: block; margin: 12px auto 0; }
.login-form button:not(.primary):not(.link-btn):not(.auth-tab) {
  width: 100%;
  margin-top: 10px;
  padding: 9px 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
}
.legal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.legal-footer a { color: var(--text-muted); }

.paywall-body p { font-size: 14px; line-height: 1.7; margin: 0 0 10px; }
.paywall-actions { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 4px; }
.button-link {
  display: block;
  text-align: center;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.button-link.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button-link.primary:hover { background: var(--primary-hover); }

.tenant-label { font-size: 13px; font-weight: normal; color: var(--text-muted); margin-left: 6px; }

.billing-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 9px 20px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.billing-banner.hidden { display: none; }
.billing-banner .button-link { display: inline-block; padding: 4px 12px; font-size: 13px; }
.billing-banner.tone-info { background: #eaf1ff; color: #1d3f86; }
.billing-banner.tone-warning { background: #fff3cd; color: #664d03; }
.billing-banner.tone-danger { background: #fde8e6; color: #8a1f17; }

.staff-limit-note { margin: 0 0 12px; }
.staff-limit-note.limit-reached { color: var(--danger); font-weight: 600; }

.company-info {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 0 0 12px;
  font-size: 14px;
}
.company-info dt { color: var(--text-muted); }
.company-info dd { margin: 0; word-break: break-all; }
#company-modal .paywall-actions { flex-direction: row; flex-wrap: wrap; }
#company-modal .button-link { display: inline-block; }

/* 給与計算の注意書き */
.payroll-disclaimer { margin: 8px 0 12px; line-height: 1.6; }

/* 表・週表示: 期間内にシフトがある退職済みスタッフの行 */
.retired-staff { color: var(--text-muted); font-style: italic; }

/* 表表示の操作ボタン（確定・CSV出力・印刷） */
.table-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.table-toolbar .month-lock-bar { margin-bottom: 0; }
.export-actions { display: flex; justify-content: flex-end; margin: 0 0 10px; }

/* 印刷（A4 横）。操作部品・個人メモは出さず、会社名と期間の見出しを付ける */
.print-only { display: none; }
@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff; min-height: 0; }
  .print-only { display: block; font-size: 14px; font-weight: 700; margin: 0 0 6px; }
  .app-header, .billing-banner, .no-print, dialog, .month-lock-bar, .day-lock-bar,
  .memo-row, .memo-chip, .memo-add-btn, .week-th-memos, .link-btn, .mobile-filter-toggle { display: none !important; }
  .calendar-root, .month-table-wrap, .week-table-wrap, .month-view-scroll { overflow: visible !important; padding: 0 !important; }
  /* 列幅をそろえ、長いイベント名や「勤務先未定」は折り返す（1 列だけ広がらないように） */
  .month-table { width: 100%; table-layout: fixed; }
  .month-table thead th:first-child { width: 96px; }
  .month-table .shift-chip, .month-table .event-chip { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
  .month-table th, .month-table td { padding: 2px; min-width: 0; font-size: 8px; }
  .month-table-row-label { position: static; font-size: 9px; padding: 2px 4px; white-space: normal; overflow-wrap: anywhere; }
  .shift-chip, .event-chip, .client-dot, .day-off, th.locked {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .month-table .shift-chip, .month-table .event-chip { font-size: 8px; padding: 0 2px; }
  tr { break-inside: avoid; }
}

/* 週表示: 前週コピー・取り消しボタン */
.week-block-label { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.week-copy-btn { font-weight: 400; }
