:root {
  /* tokens.css を優先。未読込時のフォールバック */
  --primary: #0b6e99;
  --danger: #c62828;
  --warning: #ef6c00;
  --bg: #f0f4f8;
  --card: #fff;
  --text: #222;
  --tab-h: 60px;
  --header-h: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-sans, system-ui, -apple-system, sans-serif);
  font-size: var(--font-size-body, 1rem);
  line-height: var(--line-height-body, 1.5);
  color: var(--text);
  background: var(--bg);
}

/* Login */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
}
.login-card {
  background: var(--card);
  padding: 1.5rem;
  border-radius: var(--radius-lg, 12px);
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-md, 0 2px 12px rgba(0,0,0,0.08));
  margin: min(12vh, 4rem) auto 2rem;
}
.login-card__header { margin-bottom: 1rem; }
.login-card h1 { margin: 0 0 0.35rem; color: var(--primary); font-size: 1.35rem; }
.login-sub {
  color: var(--color-text-muted, #666);
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}
.login-field { margin-bottom: 1rem; }
.login-field label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.login-field input,
.login-card input {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--color-border, #ccc);
  border-radius: var(--radius-md, 8px);
  min-height: var(--tap-min, 44px);
}
.login-password-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.login-password-row input { flex: 1; min-width: 0; }
.login-password-toggle {
  flex-shrink: 0;
  min-width: 4.5rem;
  min-height: var(--tap-min, 44px);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.login-caps {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--color-warning, #ef6c00);
  font-weight: 600;
}
.login-note {
  font-size: 0.85rem;
  color: var(--color-text-muted, #666);
  margin: 1rem 0 0.5rem;
  line-height: 1.45;
}
.login-pwa-note {
  font-size: 0.8rem;
  color: var(--color-text-muted, #666);
  margin: 0;
  line-height: 1.4;
}
.login-card .ui-alert { margin-bottom: 1rem; }
.login-card #login-error:focus {
  outline: 2px solid var(--color-danger, #c62828);
  outline-offset: 2px;
}
.error-msg { color: var(--danger); font-size: 0.85rem; }

/* App shell */
.app-body { padding-bottom: calc(var(--tab-h) + var(--safe-b)); }
.mobile-header {
  display: flex; justify-content: space-between; align-items: center;
  height: var(--header-h); padding: 0 1rem; background: var(--primary); color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.mobile-header__title {
  font-weight: 600;
  font-size: 1rem;
  margin: 0;
}
.mobile-header__actions {
  display: flex; align-items: center; gap: 0.5rem;
}
.mobile-header__user {
  font-size: 0.8rem;
  opacity: 0.9;
  max-width: 7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout-form { display: inline; margin: 0; }
.logout-button {
  font-size: 0.72rem;
  color: #fff;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  min-height: 44px;
  cursor: pointer;
}
.logout-button:hover,
.logout-button:focus-visible {
  background: rgba(255, 255, 255, 0.15);
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.admin-schedule-link {
  font-size: 0.72rem; color: #fff; text-decoration: none;
  padding: 0.2rem 0.45rem; border: 1px solid rgba(255,255,255,0.55);
  border-radius: 4px; white-space: nowrap;
}
.admin-schedule-link.hidden { display: none; }

.app-content { padding: 0.75rem; min-height: calc(100dvh - var(--header-h) - var(--tab-h)); }

.offline-banner {
  background: var(--warning); color: #fff; text-align: center; padding: 0.5rem; font-size: 0.85rem;
}
.offline-banner.hidden { display: none; }

.push-area {
  padding: 0.5rem 0.75rem 0;
  font-size: 0.8rem;
}
.push-area.hidden { display: none; }
.push-unsupported { margin: 0; text-align: center; }

.no-staff-mode .tab-bar { display: none; }
.no-staff-mode .app-content { min-height: calc(100dvh - var(--header-h)); }
.no-staff-card {
  background: var(--card); border-radius: 12px; padding: 1.25rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06); max-width: 420px; margin: 1rem auto;
}
.no-staff-card h2 { margin: 0 0 0.75rem; font-size: 1.05rem; color: var(--primary); }
.no-staff-card p { margin: 0 0 0.75rem; font-size: 0.9rem; line-height: 1.5; }
.no-staff-card .btn-block { margin-top: 0.5rem; text-align: center; text-decoration: none; display: block; }

.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--card); border-top: 1px solid #ddd;
  padding-bottom: var(--safe-b); height: calc(var(--tab-h) + var(--safe-b));
  z-index: 20;
}
.tab {
  flex: 1; border: none; background: none; padding: 0.35rem 0;
  font-size: 0.7rem; color: #666; cursor: pointer; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tap-min, 44px);
}
.tab.active { color: var(--primary); font-weight: 600; }
.tab-icon { font-size: 1.25rem; }
.tab-badge {
  position: absolute; top: 2px; right: calc(50% - 24px);
  background: var(--danger); color: #fff; font-size: 0.6rem;
  min-width: 16px; height: 16px; border-radius: 8px; line-height: 16px; text-align: center;
}
.tab-badge.hidden { display: none; }

/* Cards */
.card {
  background: var(--card); border-radius: 12px; padding: 1rem;
  margin-bottom: 0.75rem; box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.card h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.card-hero {
  text-align: center; padding: 1.25rem;
  background: linear-gradient(135deg, #0b6e99, #0a5a7a); color: #fff;
}
.card-hero .shift-name { font-size: 1.75rem; font-weight: 700; margin: 0.25rem 0; }
.card-hero .shift-date { opacity: 0.9; font-size: 0.9rem; }
.home-hero-heading {
  margin: 0; font-size: 0.9rem; font-weight: 600; opacity: 0.95;
}

.btn {
  display: inline-block; border: none; border-radius: var(--radius-md, 8px); padding: 0.65rem 1rem;
  font-size: 1rem; cursor: pointer; text-align: center; text-decoration: none;
  min-height: var(--tap-min, 44px);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-block { display: block; width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li { padding: 0.5rem 0; border-bottom: 1px solid #eee; font-size: 0.9rem; }
.member-list li:last-child { border-bottom: none; }

.cta-card {
  border: 2px solid var(--primary); background: #e3f2fd;
}
.countdown { font-size: 0.85rem; color: var(--danger); font-weight: 600; }

/* Calendar */
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: 0.7rem; color: #666; padding: 0.25rem; }
.cal-dow--sat { color: #1565c0; font-weight: 600; }
.cal-dow--sun { color: #c62828; font-weight: 600; }
.cal-day-kind {
  display: inline-block; margin-left: 0.15rem; font-size: 0.55rem;
  color: #c62828; font-weight: 700; vertical-align: super;
}
.cal-day.day-sat .cal-day-num { color: #1565c0; }
.cal-day.day-sun .cal-day-num, .cal-day.day-holiday .cal-day-num { color: #c62828; }
.cal-day {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 8px; font-size: 0.85rem; cursor: pointer; background: var(--card);
  border: 1px solid #eee; min-height: 44px; position: relative;
}
.cal-day.other { color: #bbb; background: #fafafa; }
.cal-day.today { border-color: var(--primary); font-weight: 700; }
.cal-day.has-req::after {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--warning); position: absolute; bottom: 4px;
}
.cal-day.has-shift { background: #e3f2fd; }

/* Rich month calendar (Step 21) */
.cal-grid--month { gap: 3px; }
.cal-day--rich {
  aspect-ratio: auto; min-height: 72px; align-items: stretch;
  justify-content: flex-start; padding: 3px 2px 2px; overflow: hidden;
}
.cal-day--rich .cal-day-num {
  font-size: 0.75rem; font-weight: 600; align-self: flex-start; line-height: 1.1;
}
.cal-day-chips {
  display: flex; flex-direction: column; gap: 2px; width: 100%; margin-top: 2px;
}
.cal-chip {
  display: block; font-size: 0.58rem; line-height: 1.2; padding: 1px 3px;
  border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: #fff;
}
.cal-chip--confirmed { border: 1px solid rgba(0,0,0,0.08); }
.cal-chip--request {
  background: rgba(255,255,255,0.85); color: #333;
  border: 1px dashed var(--warning);
}
.cal-chip--leave { border-color: var(--danger); color: #8b0000; }
.cal-chip--sample { display: inline-block; vertical-align: middle; }
.cal-chip-tag { font-size: 0.5rem; opacity: 0.85; margin-right: 2px; }
.cal-chip-pri { font-size: 0.5rem; margin-left: 2px; opacity: 0.9; }
.cal-more { font-size: 0.55rem; color: #666; text-align: center; }
.cal-legend {
  display: flex; flex-wrap: wrap; gap: 0.75rem; font-size: 0.75rem;
  margin-bottom: 0.5rem; color: #555;
}
.cal-legend-item { display: inline-flex; align-items: center; gap: 0.25rem; }
.cal-hint { margin-bottom: 0.5rem; }
.cal-feed-details { margin-top: 0.75rem; font-size: 0.85rem; }
.cal-oauth-panel {
  margin: 0.5rem 0 0.75rem; padding: 0.65rem 0.7rem;
  border: 1px solid var(--color-border, #ddd); border-radius: 6px; background: #fff;
}
.cal-status { font-weight: 700; margin: 0 0 0.35rem; }
.cal-status--connecting,
.cal-status--syncing { color: var(--color-info, #1565c0); }
.cal-status--sync_success { color: var(--color-success, #2e7d32); }
.cal-status--partial,
.cal-status--expired,
.cal-status--needs_reauth,
.cal-status--error { color: var(--color-warning, #ef6c00); }
.cal-sync-meta { margin: 0.35rem 0 0.6rem; font-size: 0.8rem; }
.cal-sync-meta div { display: flex; gap: 0.5rem; margin: 0.15rem 0; }
.cal-sync-meta dt { font-weight: 600; min-width: 4.5rem; color: #555; }
.cal-sync-meta dd { margin: 0; }
.cal-sync-error { color: var(--color-error, #c62828); }
.cal-consent,
.cal-calendar-id,
.cal-feed-filter { display: block; margin: 0.45rem 0; font-size: 0.82rem; }
.cal-calendar-id select,
.cal-calendar-id input {
  display: block; width: 100%; margin-top: 0.25rem; font: inherit;
  padding: 0.4rem; border: 1px solid var(--color-border, #ccc); border-radius: 4px;
}
.cal-oauth-actions { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.5rem; }
.cal-ics-block { margin-top: 0.75rem; }
.cal-ics-heading { font-size: 0.95rem; margin: 0 0 0.35rem; }
.feed-url {
  word-break: break-all; font-size: 0.75rem; padding: 0.4rem;
  background: #f5f5f5; border-radius: 4px;
}
.cal-day.day-holiday { background: #ffebee; }
.cal-day.day-weekend:not(.day-holiday) { background: #fff8e1; }
.day-section { margin-bottom: 1rem; }
.day-section h3 { font-size: 0.9rem; margin: 0 0 0.35rem; }
.day-assignment { display: inline-block; padding: 0.35rem 0.6rem; border-radius: 6px; }
.day-change-area { margin-top: 0.75rem; }
.day-change-form label { display: block; margin: 0.4rem 0; font-size: 0.85rem; }
.day-change-form select,
.day-change-form textarea {
  display: block; width: 100%; margin-top: 0.2rem; font: inherit;
  padding: 0.4rem; border: 1px solid var(--color-border, #ccc); border-radius: 4px;
}
.day-change-list { list-style: none; margin: 0; padding: 0; }
.day-change-list li {
  border-bottom: 1px solid #eee; padding: 0.5rem 0; font-size: 0.85rem;
}
.day-request-list { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.day-req-btn {
  border: none; background: none; padding: 0.25rem 0; width: 100%; text-align: left; cursor: pointer;
}
.sheet-panel--day { max-height: 90vh; }

.shift-chip {
  display: inline-block; padding: 0.35rem 0.6rem; border-radius: 6px;
  font-size: 0.85rem; margin: 0.25rem 0;
}

/* Request form — bottom drawer (not centered modal) */
.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50;
  display: flex; align-items: flex-end;
}
.sheet.hidden { display: none; }
.sheet-panel {
  background: var(--card); width: 100%; max-height: min(85vh, 100dvh);
  overflow: auto; border-radius: 16px 16px 0 0; padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-b));
  display: flex; flex-direction: column;
}
.sheet-panel label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; }
.sheet-panel select, .sheet-panel textarea, .sheet-panel input {
  width: 100%; padding: 0.65rem; margin-top: 0.25rem; font-size: 1rem;
  border: 1px solid #ccc; border-radius: 8px;
}
.sheet-actions {
  display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: auto;
  padding-top: 0.75rem; position: sticky; bottom: 0;
  background: var(--card); border-top: 1px solid #eee;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 2;
}
.sheet--keyboard .sheet-panel {
  max-height: var(--sheet-vh, 70vh);
}

.text-truncate {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}

/* Messages */
.msg-item {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit;
  padding: 0.75rem; margin-bottom: 0.5rem; border-radius: 8px;
  background: var(--card); border: none; border-left: 4px solid #ccc;
  cursor: pointer;
}
.msg-item:focus-visible {
  outline: 3px solid var(--color-focus, var(--primary));
  outline-offset: 2px;
}
.msg-item.unread { background: #fff8e1; font-weight: 500; }
.msg-item.cat-emergency { border-left-color: var(--danger); }
.msg-item.cat-handover { border-left-color: var(--primary); }
.msg-item.cat-notice { border-left-color: var(--warning); }
.msg-meta { font-size: 0.75rem; color: #666; margin-bottom: 0.25rem; }

.toast-container {
  position: fixed; bottom: calc(var(--tab-h) + 12px); left: 1rem; right: 1rem; z-index: 100;
}
.toast {
  background: #333; color: #fff; padding: 0.75rem 1rem; border-radius: var(--radius-md, 8px);
  margin-top: 0.5rem; font-size: 0.95rem;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--color-success, #2e7d32); }
.toast.hint { background: #5f6368; }

.hidden { display: none !important; }
.muted { color: #666; font-size: 0.85rem; }
.badge-finalized { background: #2e7d32; color: #fff; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.75rem; }

/* Home (Step 4) */
.home-shift-meta { margin: 0.35rem 0 0; opacity: 0.9; font-size: 0.9rem; }
.home-disclaimer { font-size: 0.85rem; color: var(--color-text-muted, #555); margin: 0.35rem 0 0.75rem; line-height: 1.4; }
.home-week-list { list-style: none; margin: 0; padding: 0; }
.home-week-list li {
  display: flex; justify-content: space-between; gap: 0.75rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--color-border-subtle, #eee);
  font-size: 0.9rem;
}
.home-week-list li:last-child { border-bottom: none; }
.home-week-date { color: var(--color-text-muted, #555); flex-shrink: 0; }
.home-week-shift { font-weight: 600; text-align: right; }
.home-action-list { list-style: none; margin: 0.5rem 0; padding: 0; font-size: 0.9rem; }
.home-action-list li { padding: 0.35rem 0; }

.cal-view-toggle {
  display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem;
}
.cal-view-toggle .btn.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.cal-agenda { list-style: none; margin: 0 0 1rem; padding: 0; }
.cal-agenda-item {
  width: 100%; text-align: left; border: 1px solid var(--color-border-subtle, #eee);
  background: var(--card); border-radius: var(--radius-md, 8px);
  padding: 0.75rem; margin-bottom: 0.5rem; cursor: pointer;
  min-height: var(--tap-min, 44px);
}
.cal-agenda-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.cal-agenda-date { font-weight: 600; margin-bottom: 0.35rem; }
.cal-agenda-body { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }

.msg-summary { font-size: 0.9rem; margin: 0 0 0.75rem; }
.msg-heading { font-size: 1rem; margin: 1rem 0 0.5rem; }
.msg-unread-label {
  display: inline-block; font-size: 0.7rem; font-weight: 700;
  color: #fff; background: var(--danger); padding: 0.1rem 0.4rem; border-radius: 4px;
}
.msg-read-label {
  display: inline-block; font-size: 0.7rem; color: var(--color-text-muted, #666);
  border: 1px solid #ccc; padding: 0.1rem 0.4rem; border-radius: 4px;
}

@media (min-width: 768px) {
  .cal-view-body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .msg-panes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: start;
  }
  .msg-pane {
    min-width: 0;
    background: var(--card);
    border-radius: 12px;
    padding: 0.75rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  }
  .sheet {
    align-items: center;
    justify-content: center;
  }
  .sheet-panel {
    max-width: 480px;
    max-height: 85vh;
    border-radius: 12px;
    margin: 1rem;
  }
}

@media (max-width: 430px) {
  .app-content { padding: 0.5rem; }
  .card { padding: 0.85rem; }
  .card-hero .shift-name {
    font-size: 1.45rem;
    overflow-wrap: anywhere;
  }
  .mobile-header__user { max-width: 5.5rem; }
  .home-week-list li { gap: 0.35rem; }
  .home-week-shift {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%;
  }
  .cal-day--rich { min-height: 48px; }
  .tab { font-size: 0.65rem; }
  /* 横長表は縮小せずスクロール（職員側に表が出た場合の保険） */
  .schedule-grid, table.data-table {
    width: max-content; min-width: 100%;
  }
}

/* Voice input */
.voice-bar {
  display: flex; align-items: center; gap: 0.5rem; margin: 0.75rem 0;
  padding: 0.5rem; background: var(--card); border-radius: 8px;
}
.voice-bar.disabled { opacity: 0.55; }
.voice-mic {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 1.2rem; cursor: pointer;
  flex-shrink: 0;
}
.voice-mic:disabled { background: #aaa; cursor: not-allowed; }
.form-error {
  margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--color-error, #c62828);
}
.form-error.hidden { display: none; }
.voice-mic.listening { background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
@media (prefers-reduced-motion: reduce) {
  .voice-mic.listening { animation: none; }
  .toast { animation: none; }
}
.voice-status { flex: 1; font-size: 0.85rem; min-height: 1.2em; color: #444; }
.voice-status--hint { color: #666; }
.voice-status--warning { color: #5d4037; }
.voice-hint { font-size: 0.75rem; color: #666; margin-bottom: 0.5rem; }
.voice-hint--unsupported { color: #777; }
.voice-transcript {
  font-size: 0.75rem; color: #555; background: #f5f5f5;
  padding: 0.35rem 0.5rem; border-radius: 4px; margin-bottom: 0.75rem;
}
.voice-confirm-msg { color: var(--warning); font-size: 0.85rem; margin-bottom: 0.5rem; }
.date-list { margin: 0.25rem 0 0.75rem; padding-left: 1.2rem; font-size: 0.85rem; }
