/* 看護師 勤務希望入力
   配色・角丸は clinic-tools の /drug/ に合わせている（院内ツールとして見た目を揃える） */

:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --card: #fff;
  --ink: #0f172a;
  --muted: #667085;
  --faint: #98a2b3;
  --line: rgba(15, 23, 42, 0.1);
  --accent: #0f766e;
  --accent-soft: rgba(15, 118, 110, 0.08);
  --danger: #b42318;
  --danger-soft: rgba(180, 35, 24, 0.08);
  --warn: #b54708;
  --warn-soft: rgba(181, 71, 8, 0.1);
  --ok: #067647;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 16px -4px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

/* hidden 属性を常に効かせる。
   .login-wrap の display:grid のようなクラス指定は、ブラウザ既定の [hidden]{display:none}
   より詳細度が高いので、これが無いと hidden を付けても消えない。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Inter", "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* ── ヘッダー ───────────────────────────────── */

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar h1 { font-size: 15px; font-weight: 800; margin: 0; }
.topbar .role {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.topbar .spacer { flex: 1; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

/* ── カード ───────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.card > h2 {
  font-size: 13px;
  font-weight: 800;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}
.card > h2 + .sub { margin-top: 0; }
.sub { font-size: 12px; color: var(--muted); margin: 0 0 14px; }

/* ── フォーム ───────────────────────────────── */

label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; }
label:first-child { margin-top: 0; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px; /* iOS の自動ズーム回避 */
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
}

button {
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 16px;
  min-height: 42px;
  transition: background .15s, border-color .15s, opacity .15s;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0b5d56; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.btn-danger { background: #fff; color: var(--danger); border-color: rgba(180, 35, 24, .3); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: 12.5px; border-radius: 7px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* ── メッセージ ───────────────────────────────── */

.msg { font-size: 13px; margin-top: 10px; min-height: 1.3em; }
.msg:empty { min-height: 0; margin-top: 0; }
.msg.error { color: var(--danger); font-weight: 600; }
.msg.ok { color: var(--ok); font-weight: 600; }
.msg.warn { color: var(--warn); font-weight: 600; }

.notice {
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 13px;
  margin: 12px 0;
  line-height: 1.65;
}
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice b { font-weight: 800; }

/* ── タブ ───────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
  min-height: 38px;
}
.tab[aria-selected="true"] { background: var(--ink); color: #fff; }
.tab:hover:not([aria-selected="true"]) { background: rgba(15, 23, 42, .05); }

.panel[hidden] { display: none; }

/* ── 期間バー ───────────────────────────────── */

.period-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.period-bar select { width: auto; min-width: 150px; font-weight: 700; }
.period-range {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.period-range b { color: var(--ink); font-weight: 700; }

/* ── カレンダー ───────────────────────────────── */

.cal-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--muted);
  margin: 0 0 10px;
}
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.swatch.closed { background: #e4e7ec; }
.swatch.half { background: repeating-linear-gradient(-45deg, #fff, #fff 3px, #e4e7ec 3px, #e4e7ec 6px); border: 1px solid var(--line); }
.swatch.crowd { background: var(--warn-soft); border: 1px solid rgba(181, 71, 8, .35); }
.swatch.short { background: #fff; border: 1px solid rgba(180, 35, 24, .55); }

/* 日別の人数表 */
.head-table { margin: 10px 0 0; font-size: 12.5px; }
.head-table table { width: auto; min-width: 300px; }
.head-table th, .head-table td { padding: 5px 10px 5px 0; }
.head-table td.v { font-variant-numeric: tabular-nums; font-weight: 700; }
.head-table td.v.ng { color: var(--danger); }
.head-table td.v.ng::after { content: " 不足"; font-size: 10.5px; font-weight: 700; }

.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal .dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 0;
}
.cal .dow.sun { color: #d92d20; }
.cal .dow.sat { color: #1570ef; }

.day {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  min-height: 62px;
  padding: 5px 5px 4px;
  text-align: left;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.day.blank { border: none; background: transparent; pointer-events: none; }
.day .d {
  font-size: 12.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.day.sun .d, .day.holiday .d { color: #d92d20; }
.day.sat .d { color: #1570ef; }
.day .tag { font-size: 9.5px; color: var(--faint); line-height: 1.3; }
.day.closed { background: #f2f4f7; }
.day.half { background: repeating-linear-gradient(-45deg, #fff, #fff 4px, #f6f7f9 4px, #f6f7f9 8px); }
.day.crowded { border-color: rgba(181, 71, 8, .4); background: var(--warn-soft); }
.day.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.day:hover:not(.blank) { border-color: var(--accent); }

.day .count {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 2px;
}
.day .count .n { font-variant-numeric: tabular-nums; color: var(--ink); }
.day.crowded .count, .day.crowded .count .n { color: var(--warn); }

/* 午前・午後の見込み人数。狭いセルでは 2 行に折り返す */
.day .head {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 5px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.25;
}
.day .head b { display: inline-flex; align-items: baseline; gap: 1px; font-weight: 800; }
.day .head .ap { font-size: 9px; font-weight: 700; color: var(--faint); }
.day .head .n { font-size: 13px; font-variant-numeric: tabular-nums; }
.day .head.short, .day .head.short .ap { color: var(--danger); }
.day.short { border-color: rgba(180, 35, 24, .45); }
.day.closed .head { opacity: .45; }

/* 看護師モードの自分の印 */
.day .mine {
  margin-top: auto;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  align-self: flex-start;
  line-height: 1.35;
}
.day .mine.night { background: #5925dc; }
.day .mine.half { background: #1570ef; }
.day .mine.work { background: var(--ok); }

/* ── 日別の詳細 ───────────────────────────────── */

.day-detail { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.day-detail h3 { font-size: 13px; font-weight: 800; margin: 0 0 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: #f2f4f7;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip .x {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
  background: none;
  border: none;
  padding: 0 0 0 2px;
  min-height: 0;
  font-size: 14px;
  line-height: 1;
}
.chip .x:hover { color: var(--danger); }
.chip.t-休み { background: var(--accent-soft); color: var(--accent); }
.chip.t-夜勤不可 { background: rgba(89, 37, 220, .08); color: #5925dc; }
.chip.t-午前だけ, .chip.t-午後だけ { background: rgba(21, 112, 239, .08); color: #1570ef; }
.chip.t-勤務 { background: rgba(6, 118, 71, .08); color: var(--ok); }
.chip.t-備考 { background: #f2f4f7; color: var(--muted); }

/* ── テーブル ───────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
th { font-size: 11.5px; color: var(--muted); font-weight: 700; white-space: nowrap; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.inactive td { color: var(--faint); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.yes { background: var(--ok); }
.status-dot.no { background: #d0d5dd; }

/* ── 名前を選ぶ（看護師モード） ─────────────────── */

.name-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.name-btn {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 13px 12px;
  border-radius: 10px;
  text-align: left;
  font-weight: 700;
  min-height: 52px;
}
.name-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.name-btn small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }

/* ── 種別ピッカー（下からせり出すシート） ─────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .4);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 460px;
  box-shadow: 0 -8px 32px rgba(15, 23, 42, .18);
}
.sheet h3 { margin: 0 0 2px; font-size: 15px; font-weight: 800; }
.sheet .sheet-sub { font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.sheet-options { display: grid; gap: 8px; }
.sheet-options button { width: 100%; text-align: left; }
.sheet-options button small { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.sheet-options button.btn-primary small { color: rgba(255, 255, 255, .85); }

@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 16px; }
}

/* ── ログイン ───────────────────────────────── */

.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-box { max-width: 380px; width: 100%; }
.login-box h1 { font-size: 17px; font-weight: 800; margin: 0 0 4px; }

/* ── スマホ ───────────────────────────────── */

@media (max-width: 600px) {
  main { padding: 12px; }
  .card { padding: 15px 14px; border-radius: 12px; }
  .day { min-height: 66px; padding: 4px 3px; }
  .day .d { font-size: 11.5px; }
  .day .tag { display: none; }
  .day .head { gap: 0 3px; }
  .day .head .n { font-size: 12px; }
  .cal { gap: 3px; }
  .actions button { flex: 1; }
}

.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ── 操作の記録（段 5） ────────────────── */
.audit-note {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  margin-left: 4px;
}
td.audit-at { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.audit-target { font-size: 12px; word-break: break-word; }
td.audit-vals { font-size: 12px; line-height: 1.6; }
td.audit-vals b {
  display: inline-block;
  min-width: 2.2em;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
td.audit-vals button { margin-top: 6px; }
tr.audit-detail td { background: rgba(15, 23, 42, .03); }
tr.audit-detail pre {
  margin: 4px 0 10px;
  padding: 8px 10px;
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
