/* =====================================================================
   クライアントポータル — 共通スタイル
   ビルド工程なし。素のCSSで書く。
   ===================================================================== */

:root {
  --primary:        #2563EB;
  --primary-dark:   #1D4ED8;
  --primary-light:  #DBEAFE;

  --bg:             #F8FAFC;
  --surface:        #FFFFFF;
  --border:         #E2E8F0;
  --border-strong:  #CBD5E1;

  --text:           #0F172A;
  --text-muted:     #64748B;
  --text-faint:     #94A3B8;

  --danger:         #DC2626;
  --danger-bg:      #FEF2F2;
  --success:        #16A34A;
  --success-bg:     #F0FDF4;
  --warning:        #D97706;
  --warning-bg:     #FFFBEB;

  --radius:         10px;
  --radius-sm:      6px;
  --shadow:         0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg:      0 10px 25px rgba(15, 23, 42, .10), 0 4px 10px rgba(15, 23, 42, .05);

  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  /* ★16px未満にするとiOSで入力時に自動ズームされる */
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =====================================================================
   認証画面
   ===================================================================== */

.auth-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
  background: linear-gradient(160deg, #EFF6FF 0%, var(--bg) 55%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
}

.auth-card__head { text-align: center; margin-bottom: 24px; }

.auth-logo {
  width: 56px; height: 56px;
  margin: 0 auto 12px;
  display: grid; place-items: center;
  font-size: 26px;
  background: var(--primary-light);
  border-radius: 16px;
}

.auth-card__title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .02em; }

.auth-icon { font-size: 40px; text-align: center; margin-bottom: 12px; }

.auth-lead {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.9;
  color: var(--text-muted);
  text-align: center;
}
.auth-lead__sub { color: var(--text-faint); font-size: 13px; }

.auth-links { margin: 20px 0 0; text-align: center; font-size: 14px; }

.auth-footer { margin-top: 20px; color: var(--text-faint); font-size: 12px; }

/* =====================================================================
   フォーム
   ===================================================================== */

.form { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field__label { font-size: 13px; font-weight: 600; color: var(--text); }

.field__input {
  width: 100%;
  padding: 11px 13px;
  font-family: inherit;
  font-size: 16px;             /* iOSの自動ズーム対策 */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.field__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.field__input:disabled { background: var(--bg); color: var(--text-faint); }

.field__with-button { position: relative; display: flex; }
.field__with-button .field__input { padding-right: 44px; }

.field__toggle {
  position: absolute;
  right: 4px; top: 50%;
  transform: translateY(-50%);
  width: 36px; height: 36px;
  display: grid; place-items: center;
  font-size: 15px;
  background: none; border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.field__toggle:hover { background: var(--bg); }

.field__hint  { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.field__error { margin: 2px 0 0; font-size: 12px; color: var(--danger); }

.checkbox {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--text-muted);
  cursor: pointer;
}
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* パスワード強度メーター */
.password-meter { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.password-meter__bar {
  flex: 1; height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.password-meter__bar span {
  display: block; height: 100%; width: 0;
  transition: width .25s, background-color .25s;
}
.password-meter__bar .is-weak   { background: var(--danger); }
.password-meter__bar .is-medium { background: var(--warning); }
.password-meter__bar .is-strong { background: var(--success); }
.password-meter__label { font-size: 11px; color: var(--text-muted); min-width: 5em; }

/* =====================================================================
   ボタン
   ===================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 20px;
  font-family: inherit; font-size: 15px; font-weight: 600;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color .15s, opacity .15s;
  /* タップ領域は最低44px確保する */
  min-height: 44px;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-dark); text-decoration: none; }

.btn--ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover:not(:disabled) { background: var(--bg); text-decoration: none; }

.btn--danger { background: var(--danger); color: #fff; }

.btn--block { width: 100%; }

/* =====================================================================
   アラート
   ===================================================================== */

.alert {
  margin: 0 0 18px;
  padding: 11px 14px;
  font-size: 14px;
  line-height: 1.7;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}
.alert--error   { background: var(--danger-bg);  border-color: #FECACA; color: #991B1B; }
.alert--success { background: var(--success-bg); border-color: #BBF7D0; color: #166534; }
.alert--warning { background: var(--warning-bg); border-color: #FDE68A; color: #92400E; }

/* =====================================================================
   デバッグ表示（本番では出ない）
   ===================================================================== */

.debug-trace {
  margin: 16px 0;
  padding: 12px;
  font-size: 12px;
  background: #1E293B;
  color: #E2E8F0;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.debug-trace summary { cursor: pointer; font-weight: 700; color: #FCA5A5; }
.debug-trace pre { margin: 8px 0 0; white-space: pre-wrap; word-break: break-all; font-size: 11px; }
.debug-trace code { color: #FCD34D; }

/* =====================================================================
   ユーティリティ
   ===================================================================== */

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* =====================================================================
   ログイン後のアプリシェル
   PC   : 左ナビ(72px) + メイン
   スマホ: 単一ペイン + 下部タブ(56px)
   ===================================================================== */

.app {
  --rail: 72px;
  --appbar-h: 56px;
  --tabbar-h: 56px;
  background: var(--bg);
}

/* ---------- グローバルヘッダ ---------- */
.appbar {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  height: var(--appbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.appbar__menu { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.appbar__brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.appbar__brand:hover { text-decoration: none; }

.appbar__search { flex: 1; max-width: 420px; margin-left: auto; }
.appbar__search input {
  width: 100%; padding: 7px 12px; font-size: 14px; font-family: inherit;
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
}
.appbar__search input:focus { outline: none; border-color: var(--primary); background: var(--surface); }

.appbar__icon { position: relative; padding: 6px; font-size: 18px; text-decoration: none; }
.appbar__icon:hover { text-decoration: none; }

.appbar__user { position: relative; }
.appbar__user > summary {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: var(--radius-sm); cursor: pointer; list-style: none;
}
.appbar__user > summary::-webkit-details-marker { display: none; }
.appbar__user > summary:hover { background: var(--bg); }
.appbar__username { font-size: 14px; font-weight: 600; }

/* ---------- 左ナビ ---------- */
.railnav {
  position: fixed; top: var(--appbar-h); bottom: 0; left: 0; z-index: 20;
  width: var(--rail);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 0;
  background: var(--surface); border-right: 1px solid var(--border);
}
.railnav__item {
  position: relative;
  width: 56px; padding: 8px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-muted); text-decoration: none;
  border-radius: var(--radius-sm);
}
.railnav__item:hover { background: var(--bg); text-decoration: none; }
.railnav__item.is-active { background: var(--primary-light); color: var(--primary); }
.railnav__icon { font-size: 20px; line-height: 1; }
.railnav__label { font-size: 10px; font-weight: 600; }
.railnav__spacer { flex: 1; }

/* ---------- メイン ---------- */
.appmain {
  padding: calc(var(--appbar-h) + 20px) 24px 40px calc(var(--rail) + 24px);
  min-height: 100vh;
}

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

/* ---------- バッジ ---------- */
.badge {
  position: absolute; top: 2px; right: 8px;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700; line-height: 1;
  color: #fff; background: var(--danger); border-radius: 999px;
}

/* ---------- ドロップダウンメニュー ---------- */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; cursor: pointer; }
.dropdown > summary::-webkit-details-marker { display: none; }

.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.menu--right { right: 0; left: auto; }
.menu__head { padding: 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu__head strong { display: block; font-size: 14px; }
.menu__head small { display: block; font-size: 12px; color: var(--text-muted); }
.menu__item {
  display: block; width: 100%; padding: 9px 12px;
  font-family: inherit; font-size: 14px; text-align: left; color: var(--text);
  background: none; border: none; border-radius: var(--radius-sm); cursor: pointer;
}
.menu__item:hover { background: var(--bg); text-decoration: none; }
.menu__item--danger { color: var(--danger); }
.menu__sep { margin: 6px 0; border: none; border-top: 1px solid var(--border); }

/* ---------- ページ見出し ---------- */
.page { max-width: 1100px; }
.page__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.page__title { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.page__lead { margin: 0; font-size: 14px; color: var(--text-muted); }

/* ---------- 絞り込み ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.filters .field__input { width: auto; min-width: 160px; padding: 8px 12px; font-size: 14px; }

/* ---------- カード（ルーム一覧） ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
  display: flex; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card.is-archived { opacity: .62; }
.card__bar { flex: 0 0 5px; }
.card__body { flex: 1; padding: 14px 16px; min-width: 0; }
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card__title { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.5; }
.card__title a { color: var(--text); }
.card__desc {
  margin: 6px 0 0; font-size: 13px; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card__stats {
  display: flex; gap: 14px; flex-wrap: wrap;
  margin: 12px 0 0; padding: 0; list-style: none;
  font-size: 12px; color: var(--text-muted);
}
.card__stats strong { color: var(--text); }
.card__stats-time { margin-left: auto; }

/* ---------- アバター ---------- */
.avatar {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; flex: 0 0 auto;
  font-size: 13px; font-weight: 700; color: #fff;
  background: var(--text-faint); border-radius: 50%;
}
.avatar--sm { width: 26px; height: 26px; font-size: 11px; }
.avatar.role-admin  { background: var(--primary); }
.avatar.role-staff  { background: #0891B2; }
.avatar.role-client { background: #7B68EE; }

.avatars { display: flex; margin: 12px 0 0; padding: 0; list-style: none; }
.avatars .avatar { margin-right: -7px; border: 2px solid var(--surface); }

/* ---------- テーブル ---------- */
.table-wrap {
  overflow-x: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 12px 14px; text-align: left; vertical-align: middle; }
.table thead th {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  background: var(--bg); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: #FAFCFF; }
.table tbody tr.is-muted { opacity: .55; }
.table__mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.table__actions { width: 44px; text-align: right; }

.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell strong { display: block; font-size: 14px; }
.user-cell small { display: block; font-size: 12px; color: var(--text-muted); }

/* ---------- タグ・チップ ---------- */
.tag {
  display: inline-block; padding: 1px 7px; margin-left: 4px;
  font-size: 11px; font-weight: 600;
  background: var(--primary-light); color: var(--primary); border-radius: 999px;
}
.tag--muted { background: var(--border); color: var(--text-muted); }

.role-tag {
  display: inline-block; padding: 2px 8px;
  font-size: 11px; font-weight: 600; border-radius: 999px; white-space: nowrap;
}
.role-tag--admin  { background: var(--primary-light); color: var(--primary); }
.role-tag--staff  { background: #CFFAFE; color: #0E7490; }
.role-tag--client { background: #EDE9FE; color: #6D28D9; }

.status { display: inline-block; padding: 2px 8px; font-size: 11px; font-weight: 600; border-radius: 999px; }
.status--active    { background: var(--success-bg); color: #166534; }
.status--invited   { background: var(--warning-bg); color: #92400E; }
.status--suspended { background: var(--danger-bg);  color: #991B1B; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.chip {
  padding: 2px 9px; font-size: 11px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, white);
  color: color-mix(in srgb, var(--c) 75%, black);
  border: 1px solid color-mix(in srgb, var(--c) 30%, white);
}
.chip-dot {
  width: 10px; height: 10px; flex: 0 0 auto;
  background: var(--c); border-radius: 3px;
}

.req { font-size: 11px; color: var(--danger); font-weight: 600; }
.text-faint { color: var(--text-faint); }

/* ---------- 色の選択 ---------- */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { cursor: pointer; }
.swatch input { position: absolute; opacity: 0; }
.swatch span {
  display: block; width: 30px; height: 30px;
  background: var(--c); border-radius: 8px;
  border: 3px solid transparent; box-shadow: 0 0 0 1px var(--border);
}
.swatch input:checked + span { border-color: var(--surface); box-shadow: 0 0 0 2px var(--text); }
.swatch input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary); }

/* ---------- チェックボックス（行型） ---------- */
.checkbox--row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin: 0 -10px;
  border-radius: var(--radius-sm);
}
.checkbox--row:hover { background: var(--bg); }
.checkbox__text { flex: 1; min-width: 0; }
.checkbox__text strong { display: block; font-size: 14px; font-weight: 600; }
.checkbox__text small { display: block; font-size: 12px; color: var(--text-muted); }

/* ---------- ダイアログ ---------- */
.dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  padding: 0;
  border: none; border-radius: 14px;
  box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dialog .form { display: flex; flex-direction: column; max-height: inherit; gap: 0; }

.dialog__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.dialog__head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.dialog__close {
  width: 32px; height: 32px; display: grid; place-items: center;
  font-size: 16px; background: none; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
}
.dialog__close:hover { background: var(--bg); }

.dialog__body {
  padding: 20px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}
.dialog__lead { margin: 0; font-size: 14px; color: var(--text-muted); }

.dialog__foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border); background: var(--bg);
}

/* ---------- 空状態 ---------- */
.empty {
  padding: 56px 24px; text-align: center;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty__icon { font-size: 40px; margin-bottom: 12px; }
.empty__title { margin: 0 0 8px; font-size: 17px; font-weight: 700; }
.empty__text { margin: 0 0 20px; font-size: 14px; color: var(--text-muted); line-height: 1.9; }

/* ---------- アイコンボタン ---------- */
.btn--icon {
  width: 32px; min-height: 32px; padding: 0;
  font-size: 16px; color: var(--text-muted);
  background: none; border: none; border-radius: var(--radius-sm);
}
.btn--icon:hover { background: var(--bg); }

/* =====================================================================
   スマホ（767px以下）
   ===================================================================== */
@media (max-width: 767px) {
  .railnav { display: none; }
  .appbar__menu { display: block; }
  .appbar__brand, .appbar__username { display: none; }
  .appbar__search { max-width: none; }

  .appmain {
    padding: calc(var(--appbar-h) + 16px) 16px calc(var(--tabbar-h) + 24px) 16px;
  }

  .tabbar {
    position: fixed; inset: auto 0 0 0; z-index: 30;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabbar__item {
    position: relative; flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--text-muted); text-decoration: none;
  }
  .tabbar__item span { font-size: 19px; line-height: 1; }
  .tabbar__item small { font-size: 10px; font-weight: 600; }
  .tabbar__item.is-active { color: var(--primary); }
  .tabbar__item .badge { top: 4px; right: 50%; margin-right: -20px; }

  .cards { grid-template-columns: 1fr; }
  .page__head { flex-direction: column; align-items: stretch; }
  .page__head .btn { width: 100%; }
  .dialog { width: 100vw; max-width: none; max-height: 92vh; margin: auto 0 0; border-radius: 14px 14px 0 0; }
}

/* color-mix 未対応ブラウザ向けのフォールバック */
@supports not (color: color-mix(in srgb, red 50%, white)) {
  .chip { background: var(--bg); color: var(--text); border-color: var(--border); }
}

/* ---------- ダッシュボード補助 ---------- */
.pill {
  min-width: 22px; padding: 2px 8px;
  font-size: 12px; font-weight: 700; text-align: center;
  border-radius: 999px; background: var(--border); color: var(--text-muted);
}
.pill--danger { background: var(--danger); color: #fff; }

.empty__actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.notice-box {
  margin-top: 28px; padding: 14px 16px;
  font-size: 13px; line-height: 1.9;
  background: var(--warning-bg); border: 1px solid #FDE68A;
  border-radius: var(--radius); color: #92400E;
}
.notice-box strong { display: block; margin-bottom: 4px; }
.notice-box p { margin: 0; }
