/* houday-haichi tool styles (loaded after base.css). No inline styles (CSP). Mobile first. */

[hidden] { display: none !important; }
.h1-sub { display: block; font-size: 1rem; font-weight: 600; color: var(--text-muted); margin-top: var(--space-1); }
#tool-form > fieldset, #tool-form > details, #tool-form > .field, #facility-inputs > fieldset, #facility-inputs > .field,
#day-extra > fieldset, #slots-inputs > fieldset, #months-inputs > fieldset { margin-bottom: var(--space-3); }
.sub-fieldset { margin-top: var(--space-2); }
.verified { font-size: 0.875rem; color: var(--text-muted); margin: 0 0 var(--space-2); }
.verified .badge { border-color: var(--ok); color: var(--ok); }
.quick-result { font-weight: 700; color: var(--accent); margin: 0; min-height: 1.5em; }
.save-line { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.btn-link { font: inherit; background: none; border: 0; padding: 0.5rem 0; min-height: 2.75rem; color: var(--accent); text-decoration: underline; cursor: pointer; }
.choice { display: flex; align-items: center; gap: var(--space-2); font-weight: 400 !important; min-height: 2.75rem; }
.choice input { width: 1.2rem; height: 1.2rem; flex: none; }
.sub-choice { margin-left: 1.6rem; }
.view-switch .choice { font-weight: 600 !important; }
details.options { margin-top: var(--space-2); }
details.options summary, .notes-more summary { cursor: pointer; font-weight: 600; min-height: 2.75rem; display: flex; align-items: center; }
select { max-width: 100%; }

/* Two (or more) small fields per row on phones. */
.pair-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 0 var(--space-2); }
.pair-grid .field { margin-bottom: var(--space-2); min-width: 0; }
.pair-grid input, .plan-grid input { max-width: 9rem; text-align: right; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0 var(--space-2); }
.plan-grid .field { min-width: 0; }
.print-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 0 var(--space-2); margin: var(--space-2) 0; }
fieldset.unit { margin-bottom: var(--space-2); }

.time-range { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.time-range select { width: 8rem; }

.example-label { display: inline-block; font-size: 0.875rem; font-weight: 600; background: var(--mark-bg); color: var(--mark-text); padding: 0 var(--space-2); border-radius: 4px; margin-bottom: var(--space-2); }
.top-summary { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: baseline; border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
.top-summary .quick-result { flex: 1 1 14rem; min-width: 0; }
.top-summary .quick-result::before { content: "いまの結果: "; }
.top-summary #prefill-status { flex: 1 1 100%; margin: 0; }
.top-summary.is-example .quick-result::before { content: "計算例: "; }
/* The summary text starts with its conditions "(定員10人・利用児12人): …" → 「計算例(定員10人・利用児12人): …」. */
.top-summary.has-cond .quick-result::before { content: "いまの結果"; }
.top-summary.has-cond.is-example .quick-result::before { content: "計算例"; }
.result-main .cond { font-weight: 600; }
.top-summary.is-example .quick-result::after { content: "(下の人数を自分の事業所の人数に書き換えてください)"; display: block; font-size: 0.85rem; font-weight: 400; color: var(--text-muted); }

/* ---------- Month cards (3か月判定) ---------- */
.month-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: var(--space-2); }
.month-card { margin: 0; padding: var(--space-2); border: 1px solid var(--border); border-left-width: 6px; border-radius: var(--radius); min-width: 0; }
.month-card legend { font-weight: 700; padding: 0 var(--space-1); }
.month-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 var(--space-2); }
.month-grid .field { margin-bottom: var(--space-1); min-width: 0; }
.month-grid label { font-size: 0.8rem; font-weight: 600; }
.month-grid input { width: 100%; text-align: right; padding-left: 0.3rem; padding-right: 0.3rem; }
.month-status { margin: 0 0 var(--space-1); font-size: 0.85rem; min-height: 1.2em; }
.month-badge { font-weight: 700; }
.month-badge:empty { display: none; }
.month-pre { font-weight: 400; color: var(--text-muted); }
.month-carry { margin: 0 0 var(--space-1); font-size: 0.85rem; font-weight: 700; color: var(--accent); }
.month-carry:empty { display: none; }
.month-card.is-gensan { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.month-card.is-gensan .month-badge { color: var(--accent-contrast); background: var(--danger); padding: 0 0.4rem; border-radius: 4px; }
.month-card.is-ok { border-left-color: var(--ok); }
.month-card.is-ok .month-badge { color: var(--ok); }
.month-card.is-na { border-left-color: var(--text-muted); }
.month-card.is-na .month-badge { color: var(--text-muted); }
.month-card.has-day-gensan .month-why { color: var(--danger); }

/* ---------- Slot input table ---------- */
.slot-fieldset[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; position: relative; }
.slot-input-wrap { max-height: 70vh; overflow: auto; }
table.slot-input th.time { position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.slot-input thead th.time { z-index: 3; }
table.slot-input { border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 0; }
table.slot-input th, table.slot-input td { padding: 2px 4px; border-bottom: 1px solid var(--border); text-align: center; white-space: nowrap; }
table.slot-input thead th { font-size: 0.8rem; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.th-sub { display: block; font-weight: 400; font-size: 0.7rem; }
table.slot-input input.cell { width: 4.5rem; min-height: 2.5rem; padding: 0.25rem 0.35rem; text-align: right; }
.btn-mini { min-height: 2.5rem; padding: 0.25rem 0.6rem; font-size: 0.9rem; }
th.time { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Results ---------- */
.result-main.is-bad { color: var(--danger); }
.result-plain { margin-bottom: var(--space-2); }
.result-block { margin: var(--space-3) 0; }
.result-block h3 { margin-bottom: var(--space-1); }
.unit-result.is-gensan h3 { color: var(--danger); }
.key-list { padding-left: 1.2em; }
.key-list li { margin-bottom: var(--space-1); }
.is-bad { color: var(--danger); }
.is-warn { color: var(--danger); }
.result-table caption { text-align: left; font-weight: 700; padding: var(--space-2) 0; }
.result-table th.num, .result-table td.num { text-align: right; white-space: nowrap; }
.result-table .strong, .strong { font-weight: 700; }
.quick tr.is-current th, .quick tr.is-current td { font-weight: 700; background: var(--accent-soft); }
.plan-line { font-weight: 700; }
.plan-line.is-short { color: var(--danger); }
.plan-line.is-ok { color: var(--ok); }

.slots { min-width: 26rem; }
.slots th, .slots td { white-space: nowrap; }
.slots tr.is-short th, .slots tr.is-short td, .months tr.is-short th, .months tr.is-short td { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); }
.slots tr.is-short td.diff { color: var(--danger); font-weight: 700; }
.months { min-width: 44rem; font-variant-numeric: tabular-nums; }
.months th, .months td { white-space: nowrap; font-size: 0.9rem; }
.months td.verdict.is-gensan { color: var(--danger); font-weight: 700; }
.months td.verdict.is-ok { color: var(--ok); }

.result-notes { margin-top: var(--space-3); }
.result-notes ul { padding-left: 1.2em; }
.result-notes li { margin-bottom: var(--space-1); }
.note-info, .note-warn, .note-error {
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  padding: var(--space-2) var(--space-3); border-radius: 4px; font-size: 0.9rem;
}
.note-warn { border-left-color: var(--mark-text); }
.note-error { border-left-color: var(--danger); }
.rule-table { min-width: 30rem; margin-bottom: var(--space-3); }
.hayami-table { min-width: 0; }
.sources li { margin-bottom: var(--space-1); overflow-wrap: anywhere; }

@media (max-width: 30rem) {
  /* First screen on phones: the mode switch and 定員・利用児数 (UX review H1). */
  .h1-sub { font-size: 0.875rem; }
  .verified { font-size: 0.75rem; margin-bottom: var(--space-1); }
  .intro { font-size: 0.875rem; margin-bottom: var(--space-2); }
  .form-heading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .view-switch .choice { min-height: 2.5rem; font-size: 0.95rem; }
  .unit.is-single > legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .unit.is-single { padding-top: var(--space-2); }
  .slot-input-wrap { max-height: none; }
  .month-cards { grid-template-columns: minmax(0, 1fr); }
  .rule-table { min-width: 26rem; }
  .hayami-table { min-width: 0; }
}

@media print {
  .no-print { display: none !important; }
  .slot-input-wrap { max-height: none; overflow: visible; }
  thead { display: table-header-group; }
  .print-header { margin-bottom: 6pt; }
  .print-title { font-size: 14pt; font-weight: 700; margin: 0 0 4pt; }
  .print-meta { display: grid; grid-template-columns: repeat(3, max-content 1fr); gap: 2pt 6pt; margin: 0; font-size: 10pt; }
  .print-meta dt { font-weight: 700; }
  .print-meta dd { margin: 0; border-bottom: 1px solid #000; min-width: 6em; }
  .print-meta dd.sign { min-height: 2.2em; }
  .notes-more summary { display: none; }
  .table-scroll { overflow: visible; }
  .slots, .months, .rule-table { min-width: 0; font-size: 9pt; }
  .slots th, .slots td, .months th, .months td { padding: 1px 4px; }
  .slots tr.is-short th, .slots tr.is-short td, .months tr.is-short th, .months tr.is-short td { background: #eee; }
  .slots tr, .months tr { break-inside: avoid; }
}
