* {
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
  margin: 10px;
  font-size: 0.9rem;
}

@media (min-width: 640px) {
  body {
    max-width: 700px;
    margin: 10px auto;
    font-size: 1rem;
  }
}

/* neocalc ナビの現在ページ強調 */
.topnav a.current-page {
  background: #fff;
  color: #007BFF;
  font-weight: bold;
  border-color: #007BFF;
}

h1 {
  font-size: 1.3rem;
  margin: 10px 0;
}

h2 {
  font-size: 1.1rem;
  margin: 16px 0 6px;
  padding: 4px 8px;
  background: #e8f0fe;
  border-left: 4px solid #4a6fa5;
}

h3 {
  font-size: 1rem;
  margin: 10px 0 4px;
}

/* ── テーブル共通 ── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0;
}

th, td {
  border: 1px solid #ccc;
  padding: 4px 6px;
}

th {
  background: #f0f0f0;
  text-align: center;
}

td {
  text-align: right;
}

td.label {
  text-align: left;
}

/* ── 入力フィールド ── */
input[type="number"] {
  width: 100%;
  text-align: right;
  padding: 2px 4px;
  border: 1px solid #bbb;
  border-radius: 3px;
}

input[type="number"]:disabled {
  background: #f5f5f5;
  color: #555;
}

/* ── ボタン ── */
button.btn-any-toggle {
  font-size: 0.72rem;
  font-weight: normal;
  padding: 2px 6px;
  background: #fff;
  color: #4a6fa5;
  border: 1px solid #4a6fa5;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
}

button.btn-any-toggle:hover {
  background: #eef2fb;
}

button.btn-calc {
  display: block;
  width: 100%;
  padding: 10px;
  font-size: 1.1rem;
  font-weight: bold;
  background: #4a6fa5;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  margin: 14px 0;
}

button.btn-calc:hover {
  background: #3a5f95;
}

button.btn-small {
  padding: 3px 10px;
  font-size: 0.85rem;
  background: #6c757d;
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

button.btn-small:hover {
  background: #5a6268;
}

button.btn-add {
  padding: 4px 12px;
  font-size: 0.85rem;
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  margin-bottom: 8px;
}

button.btn-add:hover {
  background: #218838;
}

/* ── 患者情報 ── */
.patient-inline-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  margin: 8px 0 4px;
  padding: 5px 10px;
  background: #e8f0fe;
  border-left: 4px solid #4a6fa5;
}

.patient-label {
  font-weight: bold;
  font-size: 1.05rem;
  color: #333;
  white-space: nowrap;
  margin-right: 16px;
}

.patient-inline-row .form-label {
  color: #333;
  white-space: nowrap;
}

.patient-inline-row input[type="number"] {
  flex: 0 0 80px !important;
  width: 80px !important;
}

/* ── 単位セレクタ ── */
.unit-selector {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 4px 0 6px;
  padding: 6px 10px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.85em;
}

.unit-sel-title {
  font-weight: bold;
  font-size: 0.88em;
  color: #444;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid #ccc;
  cursor: pointer;
  list-style: none;
}

.unit-sel-title::-webkit-details-marker { display: none; }

details.unit-selector[open] .unit-sel-title {
  margin-bottom: 6px;
}

.unit-sel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid #e8e8e8;
  flex-wrap: wrap;
}

.unit-sel-item:last-child {
  border-bottom: none;
}

.unit-sel-label {
  font-weight: bold;
  color: #555;
  min-width: 2.5em;
}

.unit-selector label {
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}

/* ── 単位テキスト（小さめ）── */
td.unit {
  font-size: 0.8em;
  color: #666;
  white-space: nowrap;
  text-align: left;
}

/* ── 任意チェックボックス ── */
.any-col {
  width: 1%;
  white-space: nowrap;
  text-align: left;
  padding-left: 4px;
}

.any-col label {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 0.78em;
  color: #888;
  cursor: pointer;
}

/* ── 目標投与量（2列）── */
.target-grid {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  margin: 6px 0;
}

.target-grid .form-table {
  flex: 1;
  min-width: 0;
  margin: 0;
}

/* ── 入力フォームテーブル共通 ── */
.form-table td.label {
  width: 1%;
  white-space: nowrap;
}

.form-table td:nth-child(2) {
  width: 90px;
}

.form-table td:nth-child(3) {
  width: 1%;
  white-space: nowrap;
  text-align: left;
}

/* ── 使用製剤（縦型リスト）── */
.prep-group-section {
  margin: 4px 0 8px;
}

.prep-group-header {
  font-weight: bold;
  font-size: 0.88em;
  color: #333;
  margin-bottom: 3px;
  padding-bottom: 2px;
  border-bottom: 1px solid #ddd;
}

.target-footnote {
  font-size: 0.8em;
  color: #888;
  margin: 2px 0 6px;
}

.calc-disclaimer {
  font-size: 0.82em;
  color: #b05000;
  background: #fff8f0;
  border-left: 3px solid #e08030;
  padding: 5px 10px;
  margin: 8px 0 4px;
}

.prep-group-note {
  font-size: 0.8em;
  color: #777;
  margin: 2px 0 4px;
  padding-left: 2px;
}

.prep-group-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 12px;
  padding: 3px 0 3px 10px;
}

.prep-group-controls label {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.9em;
  cursor: pointer;
  white-space: nowrap;
}

.prep-group-controls label.disabled {
  color: #aaa;
  cursor: not-allowed;
}

/* ── 副袋3〜10 入力行 ── */
.sub-bag-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  flex-wrap: wrap;
}

.sub-bag-row .sub-bag-label {
  min-width: 50px;
  font-weight: bold;
  color: #555;
}

.sub-bag-row select {
  flex: 1;
  min-width: 120px;
  padding: 3px;
  border: 1px solid #bbb;
  border-radius: 3px;
}

.sub-bag-row input[type="number"] {
  width: 70px;
}

.sub-bag-row .unit-label {
  white-space: nowrap;
  color: #555;
}

/* ── 結果エリア ── */
#result {
  margin-top: 10px;
}

.bag-card {
  border: 1px solid #aaa;
  border-radius: 6px;
  padding: 10px;
  margin: 8px 0;
  background: #fafafa;
}

.bag-card.bag-main {
  border-left: 5px solid #4a6fa5;
}

.bag-card.bag-sub1 {
  border-left: 5px solid #e67e22;
}

.bag-card.bag-sub2 {
  border-left: 5px solid #27ae60;
}

.bag-card.bag-sub-other {
  border-left: 5px solid #7f8c8d;
}

.bag-card h3 {
  margin: 0 0 6px;
  color: #333;
}

.bag-card .bag-total {
  font-weight: bold;
  margin-top: 6px;
  color: #333;
}

/* ── サマリー表 ── */
.summary-table td.ok {
  color: #1a7a1a;
}

.summary-table td.warn {
  color: #c0392b;
  font-weight: bold;
}

.summary-table td.info {
  color: #555;
}

/* ── アコーディオン ── */
details {
  border: 1px solid #ccc;
  border-radius: 4px;
  margin: 8px 0;
}

details > summary {
  padding: 6px 10px;
  cursor: pointer;
  background: #f7f7f7;
  font-weight: bold;
  list-style: none;
  user-select: none;
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary::before {
  content: "▶ ";
  font-size: 0.8em;
}

details[open] > summary::before {
  content: "▼ ";
}

details .details-inner {
  padding: 8px 10px;
}

/* ── 調製量入力欄 ── */
input.adj-input {
  width: 80px;
  text-align: right;
  padding: 2px 4px;
  border: 1px solid #4a6fa5;
  border-radius: 3px;
  background: #f0f4ff;
}

input.adj-input:focus {
  outline: none;
  border-color: #2a4f85;
  background: #fff;
}

td.calc-vol {
  color: #888;
  font-size: 0.9em;
}

/* ── 実投与速度入力欄 ── */
input.rate-input {
  width: 70px;
  text-align: right;
  padding: 2px 4px;
  border: 1px solid #27ae60;
  border-radius: 3px;
  background: #f0fff4;
}

input.rate-input:focus {
  outline: none;
  border-color: #1a7a40;
  background: #fff;
}

.bag-rate-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  font-weight: bold;
  color: #333;
}

/* ── 袋カード内 調製設定行 ── */
.bag-adj-settings {
  display: flex;
  align-items: center;
  gap: 4px 6px;
  flex-wrap: wrap;
  margin: 6px 0 2px;
  font-size: 0.85em;
  color: #555;
}

.bag-adj-settings input[type="number"] {
  width: 55px;
}

.bag-hours-display {
  color: #888;
}

/* ── カスタム製剤追加セクション ── */
.custom-prep-section {
  margin: 6px 0 2px;
}

.custom-prep-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 4px 0;
  flex-wrap: wrap;
}

.custom-prep-row select {
  flex: 1;
  min-width: 0;
  font-size: 0.85em;
  padding: 2px 4px;
  border: 1px solid #ccc;
  border-radius: 3px;
}

.custom-prep-row .custom-adj-vol {
  width: 60px;
}

button.btn-add-prep {
  font-size: 0.8em;
  padding: 3px 8px;
  background: #f0f4ff;
  color: #4a6fa5;
  border: 1px dashed #4a6fa5;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 2px;
}

button.btn-add-prep:hover {
  background: #dce8ff;
}

/* ── リセットボタン ── */
button.btn-reset {
  font-weight: normal;
  margin-left: auto;
  flex-shrink: 0;
}

/* ── サマリー注釈 ── */
p.summary-footnote {
  font-size: 0.8em;
  color: #666;
  margin: 4px 0 0;
  text-align: right;
}

/* ── エラー表示 ── */
.error-msg {
  color: #c0392b;
  background: #fdecea;
  border: 1px solid #e57373;
  border-radius: 4px;
  padding: 8px 12px;
  margin: 8px 0;
}

/* ════════════════════════════════════════════
   モバイル専用レイアウト（目標投与量テーブル）
   ════════════════════════════════════════════ */
@media (max-width: 639px) {

  .target-grid {
    display: block;
  }

  .target-grid .form-table {
    width: 100%;
    margin: 0 0 4px;
  }

  .form-table td:nth-child(2) {
    width: auto;
  }

  .form-table,
  .form-table tbody {
    display: block;
    width: 100%;
  }

  .form-table tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    border: none;
    border-bottom: 1px solid #e0e0e0;
    padding: 6px 2px;
  }

  .form-table td {
    border: none !important;
    padding: 2px 3px;
  }

  .form-table td.label {
    order: 1;
    flex: 1 0 65%;
    text-align: left;
    white-space: normal;
    font-size: 0.9em;
  }

  .form-table td.any-col {
    order: 2;
    flex: 0 0 35%;
    text-align: right;
  }

  .form-table td:nth-child(2) {
    order: 3;
    flex: 0 0 auto;
  }

  .form-table td:nth-child(2) input[type="number"] {
    width: 5em;
    font-size: 1rem;
    padding: 5px 8px;
  }

  .form-table td.unit {
    order: 4;
    flex: 0 0 auto;
    font-size: 0.82em;
    color: #555;
    white-space: nowrap;
    align-self: center;
    padding-left: 5px;
  }

  .unit-selector {
    flex-direction: column;
    gap: 4px;
  }
}
