/*
 * 業務画面の枠と、Apple 案の組み合わせ（Penpot「02 レイアウト」の共通の帯・土台と対応。design/components.md）。
 * 値はすべて tokens.css の変数だけを使う。
 *   PC（1280 以上）   : macOS 風。灰色のサイドバー＋白い本文、表は外枠なし・行の間に細い線
 *   iPad（768〜1279） : iPadOS 風。サイドバー＋灰色の地に白い角丸の面（行の一覧）
 *   スマホ（768 未満）: iOS 風。サイドバーなし、下のタブ、灰色の地に白い角丸の面
 */

[hidden] { display: none !important; }

/* ---------- 画面の枠 ---------- */
.shell { display: flex; min-height: 100vh; background: var(--color-border-default); gap: var(--space-line); }

.sidebar {
  flex: 0 0 var(--size-sidebar);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: var(--space-3);
  background: var(--color-surface-sunken);
  position: sticky; top: 0; height: 100vh; box-sizing: border-box;
}
.sidebar__top { display: flex; flex-direction: column; gap: var(--space-1); }
.sidebar__nav { display: flex; flex-direction: column; gap: var(--space-1); }
.sidebar__logo { display: block; padding: var(--space-2) var(--space-2) var(--space-4); }
.sidebar__logo img { display: block; height: var(--size-logo); width: auto; }
.sidebar__user { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: 0 var(--space-2); }
.sidebar__name { font-size: var(--font-size-sm); color: var(--color-text-muted); }

.sidebar-item {
  display: flex; align-items: center;
  height: var(--size-control-sm); padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-default); font-size: var(--font-size-md); text-decoration: none;
}
.sidebar-item:hover { background: var(--color-surface-card); }
.sidebar-item.is-current { background: var(--color-brand-primary-strong); color: var(--color-text-inverse); font-weight: var(--font-weight-semibold); }
.sidebar-item.is-disabled { color: var(--color-text-muted); pointer-events: none; }

.content {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: var(--space-5);
  padding: var(--space-6);
  background: var(--color-surface-card);
}

/* 見出しの行（PC: 大きな見出し＋薄い色の地のボタン） */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.large-title { margin: 0; font-size: var(--font-size-3xl); font-weight: var(--font-weight-bold); line-height: 1.2; color: var(--color-text-default); }
.nav-bar { display: none; align-items: center; justify-content: space-between; height: var(--size-navbar); }
.nav-bar__actions { display: flex; gap: var(--space-4); margin-left: auto; }
/* PC でも「‹ 戻る」がある画面は帯を出す（操作は見出しの右に出すので隠す） */
.nav-bar.has-back { display: flex; }
.nav-bar.has-back .nav-bar__actions { display: none; }

/* 下のタブ（スマホ） */
.tabbar { display: none; }

/* ---------- ボタン ---------- */
.text-button {
  display: inline-flex; align-items: center; height: var(--size-control);
  padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--color-brand-primary-strong); font: inherit; font-size: var(--font-size-md); font-weight: var(--font-weight-semibold);
  text-decoration: none;
}
.text-button--sm { font-size: var(--font-size-sm); }
.text-button--lg { font-size: var(--font-size-lg); }
.tinted-button {
  display: inline-flex; align-items: center; height: var(--size-control-sm);
  padding: 0 var(--space-3); border: 0; border-radius: var(--radius-md); cursor: pointer;
  background: var(--color-brand-primary-soft); color: var(--color-brand-primary-strong);
  font: inherit; font-size: var(--font-size-md); font-weight: var(--font-weight-semibold); text-decoration: none;
}
.text-button--danger { color: var(--color-state-danger); }
.button--capsule { border-radius: var(--radius-pill); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
/* 入力の画面のフォーム。中身と決定ボタンを本文の並び（.content の間隔）にそのまま乗せる（Penpot の 土台 / 入力 と同じ） */
.form-flow { display: contents; }
.is-muted { color: var(--color-text-muted); }
.button--block { width: 100%; }

/* ---------- 表（PC・macOS 風） ---------- */
.mac-table { width: 100%; border-collapse: collapse; }
.mac-table th {
  /* Penpot の表: 見出しの行 36・行 44 の下に、1px の区切り線を別に置く。web も線の分だけ高くする */
  height: calc(var(--size-row-header) + var(--border-width-thin));
  text-align: left; padding: 0 var(--space-3) 0 0;
  font-size: var(--font-size-sm); font-weight: var(--font-weight-semibold); color: var(--color-text-muted);
  border-bottom: var(--border-width-thin) solid var(--color-border-default);
}
.mac-table td {
  height: calc(var(--size-row) + var(--border-width-thin)); padding: 0 var(--space-3) 0 0;
  font-size: var(--font-size-md); color: var(--color-text-default);
  border-bottom: var(--border-width-thin) solid var(--color-border-default);
}
.mac-table tr:last-child td { border-bottom: 0; height: var(--size-row); }
.mac-table .is-strong { font-weight: var(--font-weight-semibold); }
.mac-table .is-muted { color: var(--color-text-muted); }
.mac-table a { color: inherit; text-decoration: none; }

/* ---------- 白い角丸の面と行（iPad・スマホ） ---------- */
/* 外枠は Penpot の内側の線と同じく、場所を取らない inset の影で引く（DESIGN_SYNC の約束） */
.inset-group {
  list-style: none; margin: 0; padding: 0;
  background: var(--color-surface-card);
  box-shadow: inset 0 0 0 var(--border-width-thin) var(--color-border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.inset-group__title { margin: 0 0 var(--space-2) var(--space-4); font-size: var(--font-size-sm); font-weight: var(--font-weight-semibold); color: var(--color-text-muted); }
.row {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  color: var(--color-text-default); text-decoration: none;
}
/* 行の間の細い線は、左に余白を空けて引く（li の中に行がある場合と、li 自体が行の場合の両方）。
   Penpot の separator と同じく 1px の場所を取る（透明な上の線の上に、左を空けた線を描く） */
.inset-group > li + li {
  border-top: var(--border-width-thin) solid transparent;
  background-image: linear-gradient(var(--color-border-default), var(--color-border-default));
  background-repeat: no-repeat;
  background-origin: border-box;
  background-position: var(--space-4) 0;
  background-size: calc(100% - var(--space-4)) var(--border-width-thin);
}
.row__text { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.row__title { font-size: var(--font-size-lg); font-weight: var(--font-weight-semibold); }
.row__sub { font-size: var(--font-size-md); color: var(--color-text-muted); }
.row__accessory { display: flex; align-items: center; gap: var(--space-2); flex: 0 0 auto; }
.row__disclosure { font-size: var(--font-size-xl); line-height: 1; color: var(--color-text-muted); }
.row--form { align-items: stretch; flex-direction: column; gap: var(--space-2); }
/* 項目名と値の行。値は右に寄せる。長い値（住所・訪問メモ）は項目名の下に置く（--stack）。
   --stack-sp はスマホだけ下に置く（生年月日。和暦と年齢を添えると1行に入らないため） */
.row__label { font-size: var(--font-size-md); }
.row__value { text-align: right; }
.row--stack { flex-direction: column; align-items: stretch; gap: var(--space-1); }
.row--stack .row__value { text-align: left; }
.is-pre { white-space: pre-wrap; }
.radio-group { display: flex; flex-wrap: wrap; gap: 0 var(--space-5); }
/* 2つの入力欄を1行に（姓・名、せい・めい）。PC は合わせて入力欄1つ分（size.field）の幅、iPad・スマホは行の幅いっぱいを半分ずつ */
.field-pair { display: flex; gap: var(--space-2); }
.field-pair .field__input { width: calc((var(--size-field) - var(--space-2)) / 2); }

/* ---------- 2列（PC）。左に基本情報・契約、右に連絡先・緊急連絡先・訪問メモ（Penpot の 中身 / 利用者の詳しい画面・利用者の入力） ---------- */
/* iPad・スマホは1列にし、data-order の順（基本情報→連絡先→緊急連絡先→契約→訪問メモ）に並べ替える */
.split { display: flex; align-items: flex-start; gap: var(--grid-gutter); }
.split__col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: var(--space-5); }

/* ---------- 一覧の上の検索と切り替え（PC は横並び、iPad・スマホは縦に積んで幅いっぱい） ---------- */
.list-body { display: flex; flex-direction: column; gap: var(--space-4); }
.toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3); }
.toolbar__search { display: flex; align-items: flex-end; gap: var(--space-2); }
.toolbar .segmented__item { text-decoration: none; }

/* 利用者の表の列の幅（Penpot の 中身 / 利用者一覧 PC: 975 の中の 170・190・80・250・140・残り） */
.patient-table { table-layout: fixed; }
.patient-table__name { width: calc(100% * 170 / 975); }
.patient-table__kana { width: calc(100% * 190 / 975); }
.patient-table__age { width: calc(100% * 80 / 975); }
.patient-table__addr { width: calc(100% * 250 / 975); }
.patient-table__staff { width: calc(100% * 140 / 975); }

/* ---------- ログイン・端末の登録（上の帯なし・真ん中） ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 0 var(--space-6); background: var(--color-surface-page); box-sizing: border-box; }
.auth__content { width: 100%; max-width: 360px; display: flex; flex-direction: column; align-items: center; gap: var(--space-5); }
.auth__logo { display: block; height: var(--size-logo); width: auto; }
.auth .large-title { font-size: var(--font-size-4xl); }
.auth__name { margin: 0; font-size: var(--font-size-lg); color: var(--color-text-muted); }

/* ---------- 一覧の出し分け ---------- */
.only-list { display: none; }

/* ---------- iPad（768〜1279） ---------- */
@media (max-width: 1279px) {
  .sidebar { flex-basis: 220px; }
  .sidebar-item { height: var(--size-control-lg); font-size: var(--font-size-lg); }
  .sidebar__user { flex-direction: column; align-items: flex-start; gap: var(--space-1); }
  .sidebar__user .text-button--sm { font-size: var(--font-size-md); }
  .content { background: var(--color-surface-page); padding: var(--space-3) var(--space-5) var(--space-5); gap: var(--space-3); }
  .nav-bar { display: flex; }
  .nav-bar.has-back .nav-bar__actions { display: flex; }
  .page-head .page-head__actions { display: none; }
  .large-title { font-size: var(--font-size-4xl); }
  .only-table { display: none; }
  .only-list { display: block; }
  /* 入力の行の中の入力欄は、行の幅いっぱい（iPad・スマホ。PC は size.field の 280 のまま。2026-12-01 早馬さん） */
  .row--form .field, .row--form .select, .row--form .textarea { align-items: stretch; }
  .row--form .select__control { display: flex; }
  .row--form .field__input, .row--form .select__input, .row--form .textarea__input { width: 100%; box-sizing: border-box; }
  .split { flex-direction: column; align-items: stretch; gap: var(--space-3); }
  .split__col { display: contents; }
  .split [data-order="1"] { order: 1; }
  .split [data-order="2"] { order: 2; }
  .split [data-order="3"] { order: 3; }
  .split [data-order="4"] { order: 4; }
  .split [data-order="5"] { order: 5; }
  .list-body { gap: var(--space-3); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar__search .field { flex: 1; align-items: stretch; }
  .toolbar__search .field__input { width: 100%; }
  .toolbar .segmented { display: flex; }
  .toolbar .segmented__item { flex: 1 1 0; }
  .field-pair .field { flex: 1 1 0; min-width: 0; }
  .field-pair .field__input { width: 100%; }
}

/* ---------- スマホ（768 未満） ---------- */
@media (max-width: 767px) {
  .shell { display: block; background: var(--color-surface-page); }
  .sidebar { display: none; }
  .content { padding: var(--space-2) var(--space-4) calc(var(--size-tabbar) + var(--space-5)); min-height: 100vh; box-sizing: border-box; }
  .auth { padding: 0 var(--space-5); }
  .tabbar {
    display: flex; justify-content: space-around; align-items: center;
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--size-tabbar);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--color-surface-card);
    border-top: var(--border-width-thin) solid var(--color-border-default);
  }
  .tabbar__item { flex: 1; text-align: center; font-size: var(--font-size-xs); color: var(--color-text-muted); text-decoration: none; padding: var(--space-2) 0; }
  .tabbar__item.is-current { color: var(--color-brand-primary-strong); font-weight: var(--font-weight-semibold); }
  .tabbar__item.is-disabled { pointer-events: none; opacity: 0.6; }
  .row--stack-sp { flex-direction: column; align-items: stretch; gap: var(--space-1); }
  .row--stack-sp .row__value { text-align: left; }
}
