:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --danger: #f87171;
  --border: #334155;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  padding: env(safe-area-inset-top) 16px 12px;
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.page { padding: 12px 16px 32px; max-width: 720px; margin: 0 auto; }

.tabbar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.tabbar a {
  flex: 1;
  text-align: center;
  padding: 10px 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
}
.tabbar a.active { color: var(--accent); border-bottom-color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.card h3 { margin-top: 0; font-size: 1rem; }

.back-link { color: var(--accent); text-decoration: none; display: inline-block; margin-bottom: 8px; }

input, textarea, button {
  font-size: 1rem;
  font-family: inherit;
}
input[type=text], input[type=number], input[type=datetime-local], textarea, select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
textarea { resize: vertical; }
select { appearance: none; -webkit-appearance: none; }
input[type=datetime-local] { color-scheme: dark; }

.form-actions { display: flex; gap: 10px; align-items: center; }
.form-actions .btn-secondary { margin-bottom: 0; }
.row-actions { display: flex; gap: 8px; white-space: nowrap; }
.btn-edit {
  background: none; border: 1px solid var(--border); color: var(--accent);
  border-radius: 6px; font-size: 0.78rem; padding: 3px 8px; cursor: pointer;
}

.section-sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 16px 0 6px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 720px; }

.vital-field { display: block; margin-bottom: 10px; }
.vital-field > span:first-child { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 3px; }
.vital-input-wrap { display: flex; align-items: center; gap: 6px; }
.vital-input-wrap .unit { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.vital-row-pair { display: flex; gap: 10px; }
.vital-row-pair .vital-field { flex: 1; }

.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input { flex: 1; min-width: 100px; }
.checkbox-inline { display: flex; align-items: center; gap: 4px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

.btn-primary, .btn-secondary {
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #04212f; font-weight: 700; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); margin-bottom: 14px; }
.print-hint { font-size: 0.78rem; color: var(--muted); margin: -10px 0 14px; }
.btn-delete { background: none; border: none; color: var(--danger); font-size: 0.8rem; cursor: pointer; }

.empty { color: var(--muted); font-size: 0.9rem; }

.vitals-table, table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.vitals-table th, .vitals-table td, table th, table td {
  border-bottom: 1px solid var(--border);
  padding: 6px 4px;
  text-align: left;
}

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 10px; }
.photo-thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: pointer; }
.photo-meta { display: flex; justify-content: space-between; align-items: center; font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.lightbox img { max-width: 92vw; max-height: 92vh; }

.patient-list { display: flex; flex-direction: column; gap: 8px; }
.patient-card {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; color: var(--text); text-decoration: none;
}
.patient-bed { color: var(--muted); font-size: 0.85rem; }

.task-list { list-style: none; padding: 0; margin: 8px 0 0; }
.task-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.task-list li.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-list label { display: flex; align-items: center; gap: 6px; flex: 1; }
.task-time { color: var(--accent); font-size: 0.85rem; min-width: 3.2em; }
.task-assignee { color: var(--muted); font-size: 0.8rem; }
.badge { font-size: 0.7rem; background: var(--surface-2); border-radius: 6px; padding: 1px 6px; color: var(--muted); }

.print-only { display: none; }

@media print {
  /* 列数が多く横に長い表なので、A4横向きで印刷する */
  @page { size: A4 landscape; margin: 10mm; }

  /* body自身の背景(ダークテーマの色)が余白として印刷されて黒くなるのを防ぐ。
     body配下の要素は次の行でvisibility:hiddenにするが、body自身の背景は
     この指定がないと残ってしまう。 */
  html, body {
    background: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area {
    display: block;
    position: absolute; top: 0; left: 0; width: 100%;
    color: #000; background: #fff;
  }
  #print-area table { font-size: 10px; width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border: 1px solid #999; color: #000; padding: 3px 4px; }
  #print-area tr { page-break-inside: avoid; }
}
