/* ============================================================
   SPACEDRIVE - File Explorer Styles
   ============================================================ */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --danger-light: #fef2f2;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.16);
  --grid-line: rgba(15, 23, 42, 0.045);
  --transition: 0.15s ease;
  --font: 'Inter', 'Hiragino Sans', 'Yu Gothic UI', 'Meiryo', system-ui, sans-serif;
}

/* ============================================================
   ダークテーマ（<html data-theme="dark">）
   ============================================================ */
[data-theme="dark"] {
  --primary: #818cf8;
  --primary-dark: #a5b4fc;
  --primary-light: #312e81;
  --danger: #f87171;
  --danger-dark: #fca5a5;
  --danger-light: #450a0a;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --border: #1e293b;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
  --grid-line: rgba(148, 163, 184, 0.07);
}

/* ダークテーマ向けのハードコード配色の上書き */
[data-theme="dark"] .auth-body,
[data-theme="dark"] .public-body {
  background: linear-gradient(135deg, #1e1b4b 0%, #0f172a 50%, #0b1e33 100%);
}
[data-theme="dark"] .input-wrap input:focus,
[data-theme="dark"] .search-box input:focus,
[data-theme="dark"] .share-emails textarea:focus {
  background: var(--surface);
}
[data-theme="dark"] .mini-btn:hover { background: var(--surface-hover); }
[data-theme="dark"] .share-link-url,
[data-theme="dark"] .share-link-qr img { background: var(--surface); }
[data-theme="dark"] .share-note { color: #c7d2fe; }
[data-theme="dark"] .alert-info { color: #a5b4fc; border-color: #3730a3; }
[data-theme="dark"] .alert-error { border-color: #7f1d1d; }
[data-theme="dark"] .file-icon.generic { background: #334155; color: #94a3b8; }

/* テーマ切替ボタン（サイドバー） */
button.theme-toggle {
  width: 100%;
  border: none;
  background: transparent;
  font-family: inherit;
}
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

* { box-sizing: border-box; margin: 0; padding: 0; }

/* hidden 属性を確実に尊重する（display を上書きする規則より優先） */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }
svg { width: 18px; height: 18px; }

/* ============================================================
   アイコン共通
   ============================================================ */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ============================================================
   ボタン
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-hover); }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-dark); }
.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 14.5px; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon-only { padding: 9px; }
.btn-icon-only.active { background: var(--primary-light); color: var(--primary); }

/* ============================================================
   ログイン画面
   ============================================================ */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 50%, #ecfeff 100%);
}
.auth-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(99,102,241,0.12), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(14,165,233,0.12), transparent 40%);
}
.auth-card {
  position: relative;
  width: 400px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border-radius: 20px;
  padding: 40px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}
.auth-logo h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.auth-logo p { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.logo-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}
.logo-badge svg { width: 22px; height: 22px; }

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 7px;
}
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-wrap svg {
  position: absolute;
  left: 13px;
  width: 17px;
  height: 17px;
  color: var(--text-faint);
  pointer-events: none;
}
.input-wrap input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: var(--transition);
}
.input-wrap input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 18px;
}
.alert-error { background: var(--danger-light); color: var(--danger-dark); border: 1px solid #fecaca; }
.alert-info { background: rgba(99, 102, 241, 0.1); color: #4338ca; border: 1px solid #c7d2fe; }
.auth-hint { text-align: center; color: var(--text-faint); font-size: 12px; margin-top: 20px; }
.auth-switch { text-align: center; color: var(--text-muted); font-size: 12.5px; margin-top: 16px; }
.auth-switch a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* ============================================================
   レイアウト（サイドバー付き）
   ============================================================ */
body { display: flex; flex-direction: column; }

/* ============================================================
   サイドバー
   ============================================================ */
:root {
  --sidebar-w: 240px;   /* 展開時 */
  --sidebar-w-min: 64px; /* 折りたたみ時（最小幅） */
}
.app-body {
  flex-direction: row;
  /* モバイル下部UI（Androidナビゲーション等）で最下部が隠れないよう動的ビューポート高さを使う */
  height: 100vh;   /* フォールバック（dvh 非対応ブラウザ用） */
  height: 100dvh;  /* 動的ビューポート高さ */
  overflow: hidden;
}
.sidebar {
  position: relative;
  width: var(--sidebar-w);
  min-width: var(--sidebar-w-min);
  flex-shrink: 0;
  background: #0f172a;
  color: #cbd5e1;
  border-right: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  /* モバイル下部UIに最下部のアカウントタブが隠れないようセーフエリア分の余白を確保 */
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  gap: 4px;
  /* ease-in-out で開閉の対称性を確保（ease は閉じるときと開くときで動きが非対称になる） */
  transition: width 0.22s ease-in-out;
}
/* ダークテーマ: サイドバーとメイン背景（#0f172a）が同色になり境界が消えるため、明るめの線で境界を出す */
[data-theme="dark"] .sidebar {
  border-right: 1px solid #334155;
}
/* ダークテーマ: --border が --surface と同色（#1e293b）のため、ヘッダー帯の下線が見えなくなる */
[data-theme="dark"] .topbar,
[data-theme="dark"] .toolbar {
  border-bottom-color: #334155;
}
/* 折りたたみ（アイコンのみ表示） */
.sidebar.collapsed { width: var(--sidebar-w-min); }

/* サイドバーの中身。開閉の幅アニメーション中は「幅に合わせて中身を潰す」のではなく、
   展開時のレイアウトのまま外側の幅でクリップする（ゲージや文字がぐしゃっと潰れるのを防ぐ）。 */
.sidebar-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

/* サイドバー展開時のバックドロップ（コンパクト幅でオーバーレイ表示するときのみ有効） */
.sidebar-backdrop { display: none; }

/* ページロード直後はトランジションを無効化（再読み込み時の開閉アニメーションを防止） */
body.no-transition .sidebar,
body.no-transition .sidebar-toggle { transition: none; }

/* 開閉トグルボタン（サイドバー右端中央に配置） */
.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -13px;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 50%;
  background: #1e293b;
  color: #94a3b8;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  /* right は折りたたみ時に変化する。幅と同じ時間で動かして位置が飛ばないようにする */
  transition: background 0.15s ease, color 0.15s ease, right 0.22s ease-in-out;
}
.sidebar-toggle:hover { background: #334155; color: #e2e8f0; }
.sidebar-toggle svg { width: 13px; height: 13px; }
/* 折りたたみ時は展開アイコン、展開時は閉じるアイコンを表示 */
.sidebar .icon-expand { display: none; }
.sidebar.collapsed .icon-collapse { display: none; }
.sidebar.collapsed .icon-expand { display: block; }
/* 折りたたみ時はトグルをサイドバー内側に収める */
.sidebar.collapsed .sidebar-toggle { right: 8px; }
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  overflow: hidden;
  white-space: nowrap;
  /* 折りたたみ時の左寄せ補正を滑らかに動かす */
  transition: padding 0.22s ease-in-out;
}
.sidebar-brand .logo-badge { width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0; }
.sidebar-brand .logo-badge svg { width: 17px; height: 17px; }
.sidebar-brand .brand-name { font-weight: 800; font-size: 16px; color: #f1f5f9; letter-spacing: -0.02em; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  color: #94a3b8;
  font-weight: 500;
  font-size: 13.5px;
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
}
.side-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.side-link:hover { background: rgba(148, 163, 184, 0.1); color: #e2e8f0; }
.side-link.active {
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
}
.side-link.active svg { color: #818cf8; }
.side-link .side-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ===== ピン止め（エクスプローラーのショートカット） =====
   エクスプローラータブのサブリストとして、小さめ・幅を狭くして表示する */
.side-pins {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 6px 8px 2px 34px;   /* 左をインデントして幅を狭く＝サブリスト感 */
  padding: 6px 0 2px;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}
.side-pins-head {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #64748b;
  text-transform: uppercase;
  padding: 0 2px 3px;
}
.side-pins-list { display: flex; flex-direction: column; gap: 1px; }
.side-pin {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 5px 6px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
}
.side-pin:hover { background: rgba(148, 163, 184, 0.12); color: #e2e8f0; }
.side-pin svg { width: 14px; height: 14px; flex-shrink: 0; color: #818cf8; }
.side-pin-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.sidebar.collapsed .side-pins { display: none; }

/* 折りたたみ時の表示調整
   中身は展開時のレイアウトのまま（外側の幅でクリップ）にして、ラベル類は「透明にする」だけ。
   幅を変えないので開閉中に文字やゲージが潰れず、フェードの遅延で「途中で切れた文字」も見えない。 */
.sidebar .brand-name,
.sidebar .side-link > span:not(.side-badge),
.sidebar .sidebar-user .user-meta,
.sidebar .usage-full {
  opacity: 1;
  /* 展開時: 幅が伸びきる少し前に見え始める */
  transition: opacity 0.12s ease 0.16s;
}
.sidebar.collapsed .brand-name,
.sidebar.collapsed .side-link > span:not(.side-badge),
.sidebar.collapsed .sidebar-user .user-meta,
.sidebar.collapsed .usage-full {
  opacity: 0;
  pointer-events: none;
  /* 折りたたみ時: 先に消してから縮める */
  transition: opacity 0.1s ease;
}
/* 折りたたみ時に不要な要素（レールでは幅がはみ出すため非表示） */
.sidebar.collapsed .side-badge { display: none; }
.sidebar.collapsed .sidebar-user .logout-btn { display: none; }
.sidebar.collapsed .sidebar-user .account-switch-btn { display: none; }
.sidebar.collapsed .account-switch { display: contents; }
.sidebar.collapsed .sidebar-user-info { flex: 0 0 auto; width: 34px; padding: 0; }
/* 折りたたみ時: レール中央にアバター/ロゴが来るよう左パディングを詰める。
   中身は「展開時のレイアウトのままクリップ」する方式のため、左寄せ分（アバターで 7px、
   ロゴで 5px）だけ補正する。サイドバーの左右パディングは 12px（デスクトップ）と
   8px（≤720px）の 2 種類しかないので、それぞれ 3px / 7px で中央に一致する。 */
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .sidebar-user { padding-left: 3px; padding-right: 0; }

/* 容量ゲージ: 展開時はフル表示（.usage-full）、折りたたみ時は同じ位置に
   ラジアルゲージを重ねてフェードで切り替える（パネル自体の大きさはアニメーションする） */
.sidebar.collapsed .sidebar-usage {
  width: 32px;
  max-height: 32px;
  padding: 0;
}

.sidebar-spacer { flex: 1; }

/* 容量ステータス */
.sidebar-usage {
  position: relative;
  /* 幅・高さを固定して、開閉の幅アニメーションで中身が潰れないようにする
     （折りたたみ時は 32px 角に縮めてラジアルのみ表示） */
  width: calc(var(--sidebar-w) - 32px);
  max-height: 90px;
  overflow: hidden;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 12px;
  padding: 12px;
  margin: 8px 4px;
  transition: width 0.22s ease-in-out, max-height 0.22s ease-in-out, padding 0.22s ease-in-out;
}
/* フル表示のみ overflow で保護（ラジアルゲージははみ出しを許容） */
.usage-full { overflow: hidden; }
.usage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.usage-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  white-space: nowrap;
}
.usage-title svg { width: 14px; height: 14px; color: #94a3b8; }
.usage-percent { font-size: 12px; font-weight: 700; color: #a5b4fc; }
.usage-bar {
  height: 6px;
  background: rgba(148, 163, 184, 0.2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 7px;
}
.usage-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 99px;
  transition: width 0.4s ease;
}
.usage-bar-fill.danger { background: linear-gradient(90deg, #f59e0b, var(--danger)); }
.usage-text { font-size: 11px; color: #94a3b8; white-space: nowrap; }

/* ラジアルゲージ（折りたたみ時のみ表示・パネルの左下に重ねる） */
.usage-radial {
  position: absolute;
  left: 1px;
  bottom: 1px;
  width: 30px;
  height: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}
.sidebar.collapsed .usage-radial { opacity: 1; transition: opacity 0.12s ease 0.14s; }
.radial-svg {
  width: 100%;
  height: 100%;
  flex-shrink: 0;
  transform: rotate(-90deg);
}
.radial-bg {
  fill: none;
  stroke: rgba(148, 163, 184, 0.2);
  stroke-width: 4;
}
.radial-fill {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset 0.4s ease, stroke 0.4s ease;
}
.radial-fill.danger { stroke: var(--danger); }
.radial-percent {
  position: absolute;
  font-size: 8px;
  font-weight: 700;
  color: #cbd5e1;
  pointer-events: none;
}
.radial-percent.infinity { font-size: 12px; }

/* ============================================================
   アカウント設定
   ============================================================ */
.account-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  padding: 16px 28px 28px;
  max-width: 920px;
}
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  min-width: 0;               /* グリッド項目が中身の min-content 幅で広がらないように */
}
.account-card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--text);
}
.account-email {
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
}
.account-role {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 600;
}
.account-card .btn { margin-top: 4px; }

/* WebDAV（ネットワークドライブ）設定 */
.account-note {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.7;
  margin: 0 0 12px;
}
.webdav-value {
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
}
#webdav-token, #webdav-url {
  font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
  font-size: 12px;
}
.account-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.account-actions .danger { color: var(--danger-dark); border-color: #fecaca; }
.account-actions .danger:hover { background: var(--danger-light); }

/* ============================================================
   管理者ページ
   ============================================================ */
.admin-tabs {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.admin-tab {
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 9px 9px 0 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.admin-tab:hover { background: var(--surface-hover); color: var(--text); }
.admin-tab.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--primary-dark);
  border-bottom-color: transparent;
}
.admin-tab-panel { display: flex; flex-direction: column; gap: 16px; }
.admin-wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px 28px 28px;
  max-width: 1200px;
}
/* グリッド項目（カード）は中身の最小幅に引きずられず縮小可能にする。
   これで admin-wrap 全体が画面内に収まり、広いテーブルはカード内で横スクロールする。 */
.admin-wrap > * { min-width: 0; }
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.admin-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.admin-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.admin-table-wrap { overflow-x: auto; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.admin-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
/* 狭い幅でもテーブル内テキストを折り返さない（長い場合は表ごと横スクロールで対応） */
.admin-table td, .links-table td { white-space: nowrap; }
.admin-empty { text-align: center; color: var(--text-faint); padding: 24px !important; }
.admin-user-cell { display: flex; align-items: center; gap: 10px; }
.admin-user-cell > div { min-width: 0; flex: 1; }
.admin-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.admin-user-name { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-user-email { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-hover);
  color: var(--text-muted);
}
.admin-badge.is-admin { background: var(--primary-light); color: var(--primary-dark); }
.admin-actions { display: flex; gap: 4px; justify-content: flex-end; }
.admin-actions .mini-btn.danger { color: var(--text-faint); }
.admin-actions .mini-btn.danger:hover { color: var(--danger); }
.admin-sys-list { display: flex; flex-direction: column; gap: 10px; }
.admin-sys-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.admin-sys-item span:first-child { color: var(--text-muted); }
.admin-sys-val { font-weight: 600; color: var(--text); }
.admin-role-select { display: flex; gap: 18px; }
.admin-radio { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.admin-reset-target { color: var(--text-muted); font-size: 13px; margin-bottom: 14px; word-break: break-all; }

/* R2 設定・コスト計算 */
.admin-section-note { color: var(--text-muted); font-size: 12.5px; margin-bottom: 16px; }
.admin-card-r2 .form-group { margin-bottom: 14px; }
.admin-card-r2 .form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.cost-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 4px;
}
.cost-result { margin-top: 18px; }
.cost-table { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.cost-table th { font-size: 11.5px; }
.cost-table td { font-size: 13px; }
.cost-total { font-weight: 700; color: var(--primary-dark); font-size: 15px; }

/* プランカード・オプション */
.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.plan-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.plan-card-name { font-weight: 700; font-size: 14px; color: var(--text); }
.plan-card-price { font-size: 22px; font-weight: 800; color: var(--primary-dark); margin: 6px 0 2px; }
.plan-card-price span { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.plan-card-desc { color: var(--text-muted); font-size: 12px; margin-bottom: 10px; }
.plan-card-meta { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--text); }
.admin-sub-title { font-size: 14px; font-weight: 700; color: var(--text); margin: 18px 0 10px; }
.org-option-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.org-option-row label { flex: 1; font-size: 12.5px; color: var(--text); }
.org-option-row input { width: 90px; }
.org-cost-preview { margin-top: 12px; padding: 10px 14px; background: var(--primary-light); border-radius: var(--radius-sm); font-size: 13px; color: var(--primary-dark); }
.modal-lg { width: 560px; }
.org-detail-summary { margin-bottom: 8px; }

/* モーダル（追加・リセット用） */
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ユーザー */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 2px;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  margin-top: 6px;
  /* 折りたたみ時の左寄せ補正を滑らかに動かす */
  transition: padding 0.22s ease-in-out;
}
.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  border-radius: 8px;
  padding: 2px;
  text-decoration: none;
  transition: var(--transition);
}
.sidebar-user-info:hover { background: rgba(148, 163, 184, 0.1); }
.sidebar-user .avatar { width: 34px; height: 34px; font-size: 14px; flex-shrink: 0; pointer-events: none; }
.sidebar-user .avatar:hover { filter: brightness(1.1); }
.sidebar-user .user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar-user .user-meta span { display: block; }
.sidebar-user .user-name { color: #e2e8f0; font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .user-email { color: #64748b; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .user-org {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #a5b4fc;
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user .user-org svg { width: 11px; height: 11px; flex-shrink: 0; }
.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #94a3b8;
  flex-shrink: 0;
  transition: var(--transition);
}
.logout-btn:hover { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.logout-btn svg { width: 16px; height: 16px; }

/* アカウント切り替え（個人⇔法人） */
.account-switch { flex-shrink: 0; }
.account-switch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: var(--transition);
}
.account-switch-btn:hover { background: rgba(148, 163, 184, 0.12); color: #a5b4fc; }
.account-switch-btn svg { width: 15px; height: 15px; }
.sidebar.collapsed .sidebar-user .account-switch-btn { display: none; }
/* 折りたたみ時: 0幅ラッパーがアバターのセンタリングをずらさないようにする */
.sidebar.collapsed .account-switch { display: contents; }
.account-switch-menu {
  /* サイドバー中身は開閉時にクリップされるため、fixed でクリップの外に出して位置を JS で指定する */
  position: fixed;
  left: 0;   /* JS（openMenu）がサイドバー右端の座標を入れる */
  right: auto;
  bottom: 12px;
  width: 248px;
  background: #1e293b;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  padding: 8px;
  /* アカウント切替メニューは開いたら必ず最前面に表示する（トースト・アップロード進捗・モーダル等より上） */
  z-index: 700;
}
.account-switch-head {
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 8px 8px;
}
.account-switch-list { display: flex; flex-direction: column; gap: 2px; max-height: 280px; overflow-y: auto; }
.account-switch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: #e2e8f0;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.account-switch-item:hover { background: rgba(148, 163, 184, 0.12); }
.account-switch-item.active { background: rgba(99, 102, 241, 0.16); }
.account-switch-item .as-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.account-switch-item .as-meta { flex: 1; min-width: 0; }
.account-switch-item .as-name { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-switch-item .as-sub { font-size: 11px; color: #64748b; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-switch-item .as-type {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
  white-space: nowrap;
}
.account-switch-item .as-type.personal { background: rgba(99, 102, 241, 0.18); color: #a5b4fc; }
.account-switch-item .as-type.organization { background: rgba(16, 185, 129, 0.18); color: #34d399; }
.account-switch-item .as-check { width: 16px; height: 16px; color: var(--primary); flex-shrink: 0; }
.account-switch-empty { padding: 12px 8px; color: #64748b; font-size: 12px; }
.account-switch-foot {
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  margin-top: 6px;
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.account-switch-foot a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 12px;
  text-decoration: none;
}
.account-switch-foot a:hover { background: rgba(148, 163, 184, 0.12); color: #fff; }
.account-switch-foot a svg { width: 14px; height: 14px; color: #64748b; flex-shrink: 0; }
.account-switch-sep { height: 1px; background: rgba(148, 163, 184, 0.15); margin: 6px 4px; }
.account-switch-foot .account-switch-logout { color: #f87171; }
.account-switch-foot .account-switch-logout:hover { background: rgba(239, 68, 68, 0.12); color: #f87171; }
.account-switch-foot .account-switch-logout svg { color: #f87171; }

/* メインコンテンツ */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
}
/* エクスプローラーページのみ淡いグリッド背景（テーマ対応の --grid-line） */
.explorer-page .app-main {
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 24px 24px;
}
.app-main .main { flex: 1; overflow: auto; }

/* ============================================================
   ページヘッダー（ダッシュボード）
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 28px 6px;
  flex-shrink: 0;
}
.page-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.page-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.page-sub .trash-storage-note { color: var(--danger); font-weight: 500; }
.page-actions { display: flex; gap: 8px; }

.dash-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  padding: 16px 28px 4px;
}
.dash-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  min-width: 0;               /* グリッド項目が中身の min-content 幅で広がらないように */
}
.dash-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dash-card-icon svg { width: 22px; height: 22px; }
.dash-card-icon.storage { background: var(--primary-light); color: var(--primary); }
.dash-card-icon.objects { background: #dcfce7; color: #16a34a; }
.dash-card-icon.links { background: #fef3c7; color: #d97706; }
.dash-card-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.dash-card-value { font-size: 20px; font-weight: 800; margin-top: 2px; }
.dash-card-body { flex: 1; min-width: 0; }
.dash-card-icon.members { background: #ede9fe; color: #7c3aed; }
.dash-card-icon.plan { background: #fef3c7; color: #d97706; }

/* 組織管理ページ */
.org-add-member { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 0 4px; }
.org-add-member .modal-input { width: 150px; }
.org-add-member .modal-input:first-child { width: 170px; }
.org-add-member .modal-input[type="password"] { width: 150px; }
.org-member-head { flex-wrap: wrap; gap: 10px; }
.org-act-col { width: 200px; white-space: nowrap; }
.org-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}
.org-actions .mini-btn { margin: 0; }
.org-name-val, .org-id-val, .org-quota-val { display: inline-flex; align-items: center; gap: 6px; }
.org-name-val .mini-btn, .org-id-val .mini-btn, .org-quota-val .mini-btn { padding: 4px; }
.org-created-pw { display: flex; align-items: center; gap: 8px; }
.org-created-pw .modal-input { flex: 1; }
.org-usage-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
  width: 100%;
  max-width: 150px;          /* 幅広では従来どおり最大 150px・狭画面では縮小 */
}
.org-usage-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.org-usage-fill.danger { background: linear-gradient(90deg, #f59e0b, var(--danger)); }

/* 組織管理ページ 微調整（文字・要素サイズ） */
.page-sub #org-name-sub { white-space: nowrap; font-weight: 600; color: var(--text); }
.org-me { color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.org-member-name { white-space: nowrap; }
.org-members-email { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.org-members-id { white-space: nowrap; }
.org-member-role { white-space: nowrap; }
.org-member-usage { white-space: nowrap; }
.org-member-last { white-space: nowrap; font-variant-numeric: tabular-nums; }
.org-member-quota { white-space: nowrap; }
.org-member-quota .quota-val { margin-right: 6px; }
.org-member-quota .mini-btn { width: 26px; height: 26px; display: inline-flex; vertical-align: middle; }

/* メンバー管理: 検索・ソート・ページネーション・ステータス */
.org-member-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.member-search { width: 220px; }
@media (max-width: 720px) { .member-search { width: 150px; } }
#org-members-table th[data-sort] { cursor: pointer; user-select: none; }
#org-members-table th.sort-asc::after { content: ' ▲'; font-size: 9px; }
#org-members-table th.sort-desc::after { content: ' ▼'; font-size: 9px; }
.org-member-status { white-space: nowrap; }
.badge-ok { background: #dcfce7; color: #15803d; }
.badge-danger { background: var(--danger-light); color: var(--danger-dark); }
tr.member-disabled td { opacity: 0.55; }
.mini-btn.active-stop { color: var(--danger); border-color: var(--danger); }
.member-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 12.5px;
  flex-wrap: wrap;
}
.member-pagination .mp-info { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.member-pagination .btn:disabled { opacity: 0.4; cursor: default; }

/* メンバー詳細モーダル（一括編集） */
.member-detail-modal { max-width: 640px; width: 100%; }
.member-detail-body { max-height: calc(100dvh - 160px); overflow-y: auto; }
.md-section { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.md-section h4 { font-size: 13px; font-weight: 700; margin: 0 0 12px; color: var(--text); }
.md-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.md-row label { width: 150px; flex-shrink: 0; color: var(--text-muted); font-size: 12.5px; }
.md-row .modal-input { flex: 1; }
.md-row select.modal-input { flex: 1; }
.md-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.md-usage { margin-bottom: 12px; }
.md-usage-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 2px 0; }
.md-usage-row span { color: var(--text-muted); }
.md-usage-row b { font-variant-numeric: tabular-nums; }
.md-meta { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px 10px; margin-bottom: 12px; }
.md-meta-item { font-size: 12px; color: var(--text); padding: 8px 10px; background: var(--bg); border-radius: 7px; }
.md-meta-item span { display: block; color: var(--text-muted); font-size: 11px; margin-bottom: 2px; }
.md-meta-item b { font-weight: 600; font-variant-numeric: tabular-nums; }
.md-recent-ops { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); }
.md-ops-empty { padding: 14px; text-align: center; color: var(--text-faint); font-size: 12.5px; }
.md-op-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 12px; }
.md-op-row:last-child { border-bottom: none; }
.md-op-icon { width: 18px; text-align: center; flex-shrink: 0; }
.md-op-label { flex-shrink: 0; color: var(--text-muted); width: 64px; }
.md-op-path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.md-op-ts { flex-shrink: 0; color: var(--text-faint); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ストレージの管理（共有ディレクトリ） */
.admin-card-sub { color: var(--text-muted); font-size: 12.5px; margin: -6px 0 12px; }
.sd-name { white-space: nowrap; font-weight: 600; }
.sd-name .sd-icon { margin-right: 4px; }
.sd-quota { white-space: nowrap; font-variant-numeric: tabular-nums; }
.sd-usage-bytes { white-space: nowrap; font-variant-numeric: tabular-nums; }
.sd-usage-col { min-width: 140px; }
.sd-usage { display: flex; align-items: center; gap: 8px; }
.sd-usage-bar { flex: 1; height: 5px; background: var(--border); border-radius: 999px; overflow: hidden; min-width: 60px; }
.sd-usage-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #818cf8); border-radius: 999px; transition: width 0.3s ease; }
.sd-usage.danger .sd-usage-fill { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.sd-usage-pct { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sd-act-col { width: 100px; white-space: nowrap; }

/* 共有ディレクトリのアクセス権限 */
.badge-admin-only { background: var(--danger-light); color: var(--danger-dark); }
.sd-access-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 7px; margin-bottom: 10px; }
.sd-access-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px; }
.sd-access-item:last-child { border-bottom: none; }
.sd-access-item.locked { background: var(--bg); cursor: default; opacity: 0.75; }
.sd-access-item input { flex-shrink: 0; }
.sd-access-name { font-weight: 600; }
.sd-access-id { color: var(--text-muted); font-size: 12px; }

/* セクション */
.dash-section {
  padding: 20px 28px 30px;
  flex: 1;
  overflow: auto;
  min-height: 0;
}
.dash-section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.dash-section-title { font-size: 16px; font-weight: 700; }
.dash-section-hint { color: var(--text-faint); font-size: 12px; }

/* リンク一覧テーブル */
.links-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-sm);
}
.links-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.links-table th {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.links-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.links-table tbody tr:last-child td { border-bottom: none; }
.links-table tbody tr:hover { background: var(--surface-hover); }
.col-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-muted { color: var(--text-muted); white-space: nowrap; }
.col-actions { text-align: right; width: 140px; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.link-type-icon { display: inline-flex; vertical-align: middle; margin-right: 8px; color: var(--text-muted); }
.link-type-icon svg { width: 16px; height: 16px; }
.text-danger { color: var(--danger-dark); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-file { background: var(--primary-light); color: var(--primary-dark); }
.badge-folder { background: #fef3c7; color: #b45309; }
.badge-active { background: #dcfce7; color: #15803d; }
/* 組織のカスタムロールを示すバッジ */
.badge-role { background: #e0e7ff; color: #4338ca; }
.muted { color: var(--text-muted); font-weight: 400; }
.badge-expired { background: var(--danger-light); color: var(--danger-dark); }

/* リンク詳細モーダル */
.link-detail-row { margin-bottom: 12px; }
.link-modal-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  margin: 12px 0 16px;
}
.link-modal-meta .meta-item {
  font-size: 12.5px;
  color: var(--text);
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 7px;
}
.link-modal-meta .meta-item span { color: var(--text-muted); font-weight: 500; }
.link-modal-actions { margin-top: 18px; }
.link-modal-spacer { flex: 1; }
#link-modal-rotate { color: var(--primary-dark); border-color: #c7d2fe; }
#link-modal-rotate:hover { background: var(--primary-light); }

/* 公開リンクページ */
.public-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 50%, #ecfeff 100%);
  position: relative;
  overflow: hidden;
}
.public-card {
  position: relative;
  width: 460px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border-radius: 20px;
  padding: 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.public-file {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 8px 0 20px;
}
.public-file .file-icon { width: 52px; height: 52px; }
.public-file-meta { min-width: 0; }
.public-file-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.public-file-detail { color: var(--text-muted); font-size: 12.5px; margin-top: 4px; }
.public-actions { margin: 0 0 16px; }
.public-note { color: var(--text-faint); font-size: 12px; }

/* ============================================================
   共有リンクの簡易エクスプローラー（フォルダ / 複数選択）
   ============================================================ */
.public-explorer-card {
  width: 640px;
  max-width: calc(100vw - 32px);
  text-align: left;
}
.public-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.public-explorer-card .public-file { margin: 0; }
.public-head-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.public-crumb {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  font-size: 13px; color: var(--text-muted); margin: 0 0 8px;
}
.public-crumb a { color: var(--primary); text-decoration: none; font-weight: 600; }
.public-crumb a:hover { text-decoration: underline; }
.public-crumb .sep { color: var(--text-faint); }
.public-list {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg); margin-bottom: 16px;
}
.public-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.public-row:last-child { border-bottom: none; }
.public-row:hover { background: var(--surface-hover); }
.pub-row-icon { flex: 0 0 auto; width: 22px; height: 22px; color: var(--text-faint); display: flex; align-items: center; }
.pub-row-icon svg { width: 22px; height: 22px; }
.pub-row-name {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 13.5px;
}
.public-folder .pub-row-name { cursor: pointer; color: var(--primary); font-weight: 600; }
.public-folder .pub-row-name:hover { text-decoration: underline; }
.pub-row-meta { flex: 0 0 auto; color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.pub-row-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.pub-mini {
  font-size: 12px; padding: 4px 10px; border-radius: 8px; background: var(--surface-hover);
  color: var(--text); border: 1px solid var(--border); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.pub-mini:hover { border-color: var(--primary); color: var(--primary); }
.public-empty { padding: 28px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* 簡易プレビュー オーバーレイ */
.pub-preview-modal { max-width: 860px; width: min(860px, calc(100vw - 32px)); }
.pub-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.pub-preview-head span { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pub-preview-body {
  max-height: 70vh; overflow: auto; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.pub-preview-body img, .pub-preview-body video { max-width: 100%; display: block; margin: 0 auto; }
.pub-preview-body iframe { width: 100%; height: 70vh; border: 0; display: block; }
.pub-preview-body audio { width: 100%; display: block; padding: 16px; }
.pub-preview-body pre { white-space: pre-wrap; word-break: break-word; padding: 14px; font-size: 13px; margin: 0; }
.pub-preview-actions { margin-top: 12px; text-align: right; }

/* 自分の SPACEDRIVE に追加（コピー）結果メッセージ */
.public-copy-msg {
  margin-top: 10px; padding: 10px 14px; border-radius: 10px;
  background: #dcfce7; color: #15803d;
  font-size: 13px; text-align: center;
}
[data-theme="dark"] .public-copy-msg { background: #14532d; color: #86efac; }
.public-copy-msg.error { background: #fef2f2; color: #b91c1c; }
[data-theme="dark"] .public-copy-msg.error { background: #7f1d1d; color: #fecaca; }

/* 追加先フォルダ選択（ピッカー） */
.pub-picker-modal { max-width: 560px; width: min(560px, calc(100vw - 32px)); }
.pub-picker-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pub-picker-head h2 { margin: 0; font-size: 16px; }
.pub-picker-note { color: var(--text-muted); font-size: 12.5px; margin: 6px 0 12px; }
.pub-picker-crumb {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  font-size: 13px; color: var(--text-muted); margin-bottom: 8px; min-height: 20px;
}
.pub-picker-crumb a { color: var(--primary); text-decoration: none; font-weight: 600; }
.pub-picker-crumb a:hover { text-decoration: underline; }
.pub-picker-crumb .sep { color: var(--text-faint); }
.pub-picker-list {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg); max-height: 280px; overflow-y: auto;
  margin-bottom: 12px;
}
.pub-picker-new { display: flex; gap: 8px; margin-bottom: 12px; }
.pub-picker-new input {
  flex: 1; min-width: 0; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.pub-picker-actions { display: flex; gap: 8px; justify-content: space-between; margin-bottom: 4px; }


.public-expired-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--danger-light);
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}
.public-expired-icon svg { width: 34px; height: 34px; }
.public-expired-title { font-size: 18px; font-weight: 700; margin-bottom: 10px; }
.public-expired-text { color: var(--text-muted); font-size: 13.5px; line-height: 1.7; }

/* ============================================================
   レスポンシブ
   ============================================================ */

/* コンパクト（ノートPC〜タブレット横）: 補助的な列を非表示 */
@media (max-width: 1024px) {
  /* ユーザー管理: 権限 */
  #admin-users-table th:nth-child(4),
  #admin-users-table td:nth-child(4) { display: none; }
  /* 組織一覧: 個人容量枠（組織ID列追加後の列番号） */
  #admin-orgs-table th:nth-child(5),
  #admin-orgs-table td:nth-child(5) { display: none; }
  /* 組織メンバー: メールアドレス・最終操作日時（10列化後の列番号） */
  #org-members-table th:nth-child(3),
  #org-members-table td:nth-child(3),
  #org-members-table th:nth-child(9),
  #org-members-table td:nth-child(9) { display: none; }
  /* 共有リンク: 作成日時・アクセス数 */
  #links-table th:nth-child(4),
  #links-table td:nth-child(4),
  #links-table th:nth-child(6),
  #links-table td:nth-child(6) { display: none; }
}

/* タブレット〜小画面・モバイル（≤1024px）: サイドバー展開時は幅を取らず、
   背景を暗くしてオーバーレイ表示する（バックドロップクリックで閉じる） */
@media (max-width: 1024px) {
  /* サイドバーは常に固定（レールもドロワーも）。
     開閉で本文の幅が変わらないため、閉じた瞬間に本文が押し戻されるガタつきが出ない。 */
  .sidebar,
  .sidebar.collapsed {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100dvh;
    max-width: 85vw;
  }
  /* レール分の余白は本文側で確保する（サイドバーがフローから外れるため） */
  .app-main { margin-left: var(--sidebar-w-min); }
  /* 展開時（ドロワー）: バックドロップより前面。折りたたみ時は z-index を付けない
     （モーダルやトーストより前面に出すと本文に重なって見えるため） */
  .sidebar:not(.collapsed) {
    z-index: 900;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.35);
  }
  /* バックドロップ: 展開時のみ表示 */
  .sidebar:not(.collapsed) ~ .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 890;
    animation: fade-in 0.18s ease;
  }
}

@media (max-width: 720px) {
  /* モバイル: ボディスクロールに切替（内部スクロールだと URL バーが畳まれず表示領域が狭く感じる） */
  .app-body { height: auto; min-height: 100dvh; overflow: visible; }
  .app-main, .app-main .main, .dash-section { overflow: visible; }
  /* モバイル: サイドバーは固定レール（展開時はオーバーレイ）。padding のみモバイル用に調整 */
  .sidebar { padding: 12px 8px calc(12px + env(safe-area-inset-bottom, 0px)); }
  /* モバイル: 切替メニューは固定パネルとしてメイン側に表示（アバタータップで開く）。
     display:contents で 0幅ラッパーがセンタリングをずらさないようにする */
  .account-switch { display: contents; }
  .account-switch-menu {
    position: fixed;
    left: 72px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    width: auto;
  }
  .sidebar.collapsed .sidebar-usage { padding: 0; }
  .dash-cards { grid-template-columns: 1fr; padding: 12px 14px 4px; }
  .dash-section { padding: 14px 14px 24px; }
  .page-header { padding: 16px 14px 4px; flex-wrap: wrap; gap: 10px; }
  /* ページヘッダーの操作ボタン群（ゴミ箱の「すべて復元/空にする/更新」など）は
     横に並べると画面からはみ出すため折り返す */
  .page-actions { flex-wrap: wrap; }
  /* ゴミ箱の説明バッジは長文のため折り返しを許可（nowrap のままでははみ出す） */
  #trash-note { white-space: normal; line-height: 1.5; }
  .account-wrap { grid-template-columns: 1fr; padding: 12px 14px 24px; }
  .admin-wrap { padding: 12px 14px 24px; }
  .admin-card { padding: 16px; }
  .topbar { gap: 10px; padding: 0 12px; }
  /* 検索ボックスの縮小ルールはファイル末尾の追補メディアクエリで定義
     （この位置では後方のベース定義 .topbar-actions/.search-box input に負けるため） */
  .brand-name { display: none; }
  .toolbar { flex-wrap: wrap; padding: 12px; }
  /* ツールバー左側（アップロード/新規フォルダ/パス）も折り返して 320px 級画面でのはみ出しを防ぐ */
  .toolbar-left { flex-wrap: wrap; min-width: 0; }
  #file-list.grid-view { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  /* モバイルはホバーが無いため操作ボタン（opacity:0）が常に不可視で行幅を圧迫するだけ。
     非表示にしてファイル名・詳細に幅を割り当てる。操作は選択バー（ダウンロード/共有/削除）で行う。 */
  #file-list .file-item .file-actions { display: none; }
  .upload-progress { width: auto; left: 12px; right: 12px; }

  /* ---- テーブルの列を段階的に非表示（画面に収まるよう縮小） ---- */
  /* ユーザー管理: タイプ・プラン（権限は1024px以下で非表示） */
  #admin-users-table th:nth-child(2),
  #admin-users-table td:nth-child(2),
  #admin-users-table th:nth-child(3),
  #admin-users-table td:nth-child(3) { display: none; }
  /* 組織一覧: プラン・全体容量・個人容量枠・メンバー数（組織ID列追加後の列番号） */
  #admin-orgs-table th:nth-child(3),
  #admin-orgs-table td:nth-child(3),
  #admin-orgs-table th:nth-child(4),
  #admin-orgs-table td:nth-child(4),
  #admin-orgs-table th:nth-child(5),
  #admin-orgs-table td:nth-child(5),
  #admin-orgs-table th:nth-child(6),
  #admin-orgs-table td:nth-child(6) { display: none; }
  /* 権限: 許可組織 */
  #admin-perms-table th:nth-child(3),
  #admin-perms-table td:nth-child(3) { display: none; }
  /* 共有リンク: 種別・共有範囲・期限 */
  #links-table th:nth-child(2),
  #links-table td:nth-child(2),
  #links-table th:nth-child(3),
  #links-table td:nth-child(3),
  #links-table th:nth-child(5),
  #links-table td:nth-child(5) { display: none; }
  /* 組織メンバー: モバイルは重要列のみ（表示名・権限・ステータス・操作）。
     ユーザーID・利用容量・容量上限・最終ログインは非表示（詳細モーダルで確認可） */
  #org-members-table th:nth-child(2),
  #org-members-table td:nth-child(2),
  #org-members-table th:nth-child(6),
  #org-members-table td:nth-child(6),
  #org-members-table th:nth-child(7),
  #org-members-table td:nth-child(7),
  #org-members-table th:nth-child(8),
  #org-members-table td:nth-child(8) { display: none; }
  /* 共有ディレクトリ: モバイルは名前・使用率・操作のみ（最大容量・使用量は非表示） */
  #org-sd-table th:nth-child(2),
  #org-sd-table td:nth-child(2),
  #org-sd-table th:nth-child(3),
  #org-sd-table td:nth-child(3) { display: none; }
  /* ロール管理: 説明はモバイルで非表示（編集モーダルで確認可） */
  #org-roles-table th:nth-child(2),
  #org-roles-table td:nth-child(2) { display: none; }
  /* ゴミ箱: 種別・サイズ・削除日時（操作列を画面内に収めるため） */
  #trash-table th:nth-child(2),
  #trash-table td:nth-child(2),
  #trash-table th:nth-child(3),
  #trash-table td:nth-child(3),
  #trash-table th:nth-child(4),
  #trash-table td:nth-child(4) { display: none; }

  /* 列非表示で画面に収まるよう min-width 固定を撤廃 */
  .admin-table, .links-table { min-width: 0; }
  /* 文字・余白を縮小してフィットさせる */
  .admin-table th, .admin-table td,
  .links-table th, .links-table td { padding: 8px; }
  .admin-table, .links-table { font-size: 12.5px; }
  /* 操作ボタン・操作列をコンパクトに */
  .mini-btn { width: 26px; height: 26px; }
  .mini-btn svg { width: 12px; height: 12px; }
  .org-actions, .row-actions { gap: 2px; }
  .org-act-col { width: 150px; }
  /* ---- 組織管理テーブル（モバイル）: 操作列を常時表示 ---- */
  /* カード内で横スクロールしても操作ボタンが画面外に消えないよう sticky にする */
  #org-members-table .org-act-col,
  #org-sd-table .sd-act-col,
  #org-roles-table .sd-act-col {
    position: sticky;
    right: 0;
    background: var(--surface);
    z-index: 1;
    box-shadow: -6px 0 10px rgba(15, 23, 42, 0.08);
  }
  /* メンバー行: 細かい操作ボタンは非表示（詳細モーダルで実施可）。詳細・パスワード初期化・無効化・削除のみ残す */
  #org-members-table .org-actions .mini-btn.org-rename-member,
  #org-members-table .org-actions .mini-btn.org-role-member,
  #org-members-table .org-actions .mini-btn.org-logout-member { display: none; }
  /* メンバー名は省略表示にして列幅を圧迫しない */
  #org-members-table .org-member-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
  /* 操作列のボタン群は折り返さない（横一列に収める） */
  #org-members-table .org-actions,
  #org-roles-table .org-actions,
  #org-sd-table .org-actions { flex-wrap: nowrap; }
  /* カード見出しは折り返してボタンが重ならないように */
  .admin-card-head, .dash-section-head { flex-wrap: wrap; gap: 8px; }
  /* モーダルの操作ボタンは折り返し */
  .modal-actions { flex-wrap: wrap; }
  /* 共有リンクの QR は幅に収める */
  .share-link-qr img { width: 120px; height: 120px; }
}
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.topbar-brand .logo-badge { width: 34px; height: 34px; border-radius: 9px; }
.topbar-brand .logo-badge svg { width: 17px; height: 17px; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.breadcrumb::-webkit-scrollbar { display: none; }
.crumb {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  border: none;
  background: transparent;
  transition: var(--transition);
}
.crumb:hover { background: var(--surface-hover); color: var(--text); }
.crumb.current { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--text-faint); }
.crumb svg { width: 14px; height: 14px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box svg {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--text-faint);
  pointer-events: none;
}
.search-box input {
  width: 200px;
  padding: 8px 12px 8px 34px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg);
  outline: none;
  transition: var(--transition);
}
.search-box input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
  width: 240px;
}

/* ============================================================
   ファイル名検索オーバーレイ（画面中央）
   ============================================================ */
.search-overlay-panel {
  width: 560px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modal-in 0.18s ease;
}
.search-overlay-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.search-overlay-input-wrap > svg { width: 18px; height: 18px; color: var(--text-faint); flex-shrink: 0; }
#search-overlay-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 17px;
  color: var(--text);
  font-family: inherit;
}
.search-overlay-clear {
  border: none;
  background: var(--surface-hover);
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}
.search-overlay-clear:hover { background: var(--border); color: var(--text); }
.search-overlay-results {
  max-height: 60dvh;
  overflow-y: auto;
  padding: 8px;
}
.search-overlay-empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}
.sor-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.sor-row.active, .sor-row:hover { background: var(--surface-hover); }
.sor-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sor-icon svg { width: 18px; height: 18px; }
.sor-icon.folder { background: #e0e7ff; color: #4f46e5; }
.sor-icon.pdf { background: #fee2e2; color: #dc2626; }
.sor-icon.image { background: #dcfce7; color: #16a34a; }
.sor-icon.audio { background: #fae8ff; color: #c026d3; }
.sor-icon.video { background: #fce7f3; color: #db2777; }
.sor-icon.code { background: #e0f2fe; color: #0284c7; }
.sor-icon.archive { background: #fef3c7; color: #b45309; }
.sor-icon.doc { background: #e0f2fe; color: #2563eb; }
.sor-icon.sheet { background: #dcfce7; color: #15803d; }
.sor-icon.generic { background: #f1f5f9; color: #64748b; }
.sor-main { flex: 1; min-width: 0; }
.sor-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sor-dir { display: block; font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sor-type { flex-shrink: 0; font-size: 11.5px; color: var(--text-faint); }
.search-overlay-foot {
  padding: 10px 18px 14px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.user-menu-wrap { position: relative; }
.user-menu {
  position: absolute;
  top: 46px;
  right: 0;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 200;
}
.user-menu-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.user-name { font-weight: 600; font-size: 13.5px; }
.user-email { color: var(--text-muted); font-size: 12px; word-break: break-all; }
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  color: var(--danger-dark);
  font-weight: 500;
  font-size: 13px;
}
.user-menu-item:hover { background: var(--danger-light); }
.user-menu-item svg { width: 16px; height: 16px; }

/* ============================================================
   ツールバー
   ============================================================ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  flex-shrink: 0;
  background: var(--surface);          /* ヘッダー帯（一覧の背景グリッドと分ける） */
  border-bottom: 1px solid var(--border);   /* explorer-body との区切り */
}
.toolbar-left { display: flex; align-items: center; gap: 10px; }
.toolbar-right { display: flex; align-items: center; gap: 4px; }
/* パス欄（クリックでコピー＋入力欄に切替）。ラベルと入力欄を同じ枠に重ね、
   幅は動かさず opacity / transform だけで滑らかに入れ替える。 */
.toolbar-path-wrap {
  position: relative;
  height: 30px;
  width: clamp(150px, 24vw, 320px);
  flex-shrink: 1;
  min-width: 0;
}
.toolbar-path {
  position: absolute;
  inset: 0;
  display: block;
  line-height: 28px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-faint);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity 0.16s ease, transform 0.16s ease, background 0.16s ease, color 0.16s ease;
}
.toolbar-path:hover { background: var(--surface-hover); color: var(--text); }
.toolbar-path.editing {
  opacity: 0;
  transform: translateY(-7px) scale(0.98);
  pointer-events: none;
}
.toolbar-path-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0 9px;
  border: 1px solid var(--primary);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: 0 0 0 3px var(--primary-light);
  /* visibility を切り替えるとフォーカスできない時間帯が生じるため、
     opacity と pointer-events だけで出し入れする（tabindex=-1 でタブ移動対象外） */
  opacity: 0;
  transform: translateY(7px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.toolbar-path-wrap.editing .toolbar-path-input {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
/* パス入力の補完候補 */
.toolbar-path-suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 450;                  /* context-menu(400) より上・modal(500) より下 */
  display: none;
  min-width: 250px;
  max-width: min(460px, 92vw);
  max-height: 264px;
  overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
}
.toolbar-path-suggest.open { display: block; animation: detail-loading-in 0.12s ease; }
.tps-item {
  display: flex;
  align-items: center;
  padding: 7px 9px;
  border-radius: 6px;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}
.tps-item .tps-parent { color: var(--text-faint); }
.tps-item .tps-name {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tps-item.active, .tps-item:hover { background: var(--primary-light); }
.tps-empty {
  padding: 9px;
  color: var(--text-faint);
  font-size: 12px;
  white-space: normal;
}

/* R2 未設定の警告 */
.setup-warning {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 20px 4px;
  padding: 13px 16px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  color: #92400e;
  font-size: 13px;
  flex-shrink: 0;
}
.setup-warning svg { width: 20px; height: 20px; color: #f59e0b; flex-shrink: 0; margin-top: 1px; }
.setup-warning strong { display: block; margin-bottom: 2px; }
.setup-warning span { color: #a16207; }

/* ============================================================
   メイン / ファイル一覧
   ============================================================ */
.main {
  flex: 1;
  overflow: auto;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;               /* 子コンテンツの min-content 幅で押し広げられないように */
}
.file-area {
  position: relative;
  flex: 1;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  min-width: 0;               /* 同上（横方向の縮小を許可） */
}
#file-list.grid-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  align-content: start;
  flex: 1;
  min-width: 0;               /* 同上 */
}
#file-list.list-view {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;               /* 同上 */
}

/* 一覧の最下部・中央に表示するサマリーラベル（場所 / フォルダ数・ファイル数・サイズ） */
.file-summary {
  margin-top: auto;
  padding: 14px 0 6px;
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.6;
  flex-shrink: 0;
}
.file-summary .fs-path { color: var(--text-muted); font-weight: 600; }
.file-summary .fs-counts { font-size: 11.5px; }

/* ============================================================
   選択中アイテムの操作バー（オーバーレイ）
   ============================================================ */
.selection-bar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 320;   /* upload-progress(300) より上・context-menu(400)/modal(500) より下 */
  white-space: nowrap;
  max-width: calc(100% - 24px);
}
.selection-count {
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  margin-right: 6px;
  white-space: nowrap;
}
@media (max-width: 720px) {
  .selection-bar {
    position: fixed;                 /* モバイルは画面下部に固定して常時表示 */
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
  }
}

/* ============================================================
   右サイドバー: ファイル詳細
   ============================================================ */
.explorer-body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  position: relative;               /* 選択バーの絶対配置基準 */
}
.detail-panel {
  /* 右端からスライドインするオーバーレイ。
     margin で押し出す方式はアニメーション中に毎フレーム全再レイアウトが走り
     ファイル一覧が多いフォルダでカクつくため、transform（コンポジットのみ）で動かす。 */
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  max-width: 85vw;
  z-index: 340;                        /* 選択バー(320)より上・コンテキストメニュー(400)より下 */
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  transform: translateX(100%);
  box-shadow: -14px 0 36px rgba(0, 0, 0, 0);
  /* 閉じている間はフォーカス対象外にする。画面外の要素に TAB でフォーカスが入ると、
     ブラウザが見せようと .explorer-body（overflow:hidden）を横スクロールさせ、
     一覧が 300px ずれて見た目が崩れる。visibility は transform と同じ時間で切り替え
     （閉じるときはアニメーション終了後に hidden になる）。 */
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.26s cubic-bezier(0.22, 0.8, 0.2, 1), box-shadow 0.26s ease, visibility 0.26s ease;
  will-change: transform;
}
.detail-panel.open {
  transform: none;
  box-shadow: -14px 0 36px rgba(0, 0, 0, 0.22);
  visibility: visible;
  pointer-events: auto;
}
/* 中身は少し遅れてフェードインさせ、開閉を上品に見せる */
.detail-head,
.detail-body {
  opacity: 0;
  transition: opacity 0.14s ease;
}
.detail-panel.open .detail-head,
.detail-panel.open .detail-body {
  opacity: 1;
  transition: opacity 0.2s ease 0.06s;
}
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.detail-head h3 { font-size: 14px; font-weight: 700; }
.detail-body { padding: 16px; }
.detail-preview {
  position: relative;                    /* 読み込み中スピナーの重ね位置基準 */
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  border-radius: 10px;
  padding: 22px;
  margin-bottom: 16px;
  min-height: 140px;
}
.detail-preview img.detail-thumb {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 6px;
}
.detail-preview.clickable { cursor: pointer; }
.detail-preview.clickable:hover {
  box-shadow: 0 0 0 2px var(--primary);
  transition: box-shadow 0.15s ease;
}
/* プレビュー（画像 / PDF・Office サムネイル）の読み込み中表示 */
.detail-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.6);     /* 背面のアイコンを薄く見せつつスピナーを強調 */
  animation: detail-loading-in 0.15s ease;
}
.detail-loading .spinner {
  width: 26px;
  height: 26px;
  border-width: 2.5px;
  border-color: rgba(148, 163, 184, 0.28);
  border-top-color: var(--primary);
}
.detail-preview.loading > .file-icon { opacity: 0.25; }
@keyframes detail-loading-in { from { opacity: 0; } to { opacity: 1; } }
.detail-preview .file-icon.detail-big svg { width: 56px; height: 56px; }
.detail-name {
  font-weight: 600;
  font-size: 14px;
  word-break: break-all;
  margin-bottom: 16px;
}
.detail-rows { display: flex; flex-direction: column; gap: 12px; }
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.detail-row span:first-child { color: var(--text-muted); flex-shrink: 0; }
.detail-row span:last-child { text-align: right; word-break: break-all; }
.detail-empty {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.7;
  padding: 20px 4px;
}
@media (max-width: 720px) {
  .explorer-body { overflow: visible; }
  /* モバイルは画面いっぱい（上部バーも覆う）の固定パネル。
     スライド／影／フェードは共通ルールをそのまま使う。 */
  .detail-panel {
    position: fixed;
    z-index: 850;
  }
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  border: 1.5px solid transparent;
  user-select: none;
  min-width: 0;               /* nowrap テキストで min-content 幅に張らず縮小を許可 */
}
.grid-view .file-item { flex-direction: column; text-align: center; gap: 8px; }
.file-item:hover { background: var(--surface-hover); }
.file-item.selected {
  background: var(--primary-light);
  border-color: var(--primary);
}
.file-item.draggable { cursor: grab; }
.file-item.draggable:active { cursor: grabbing; }
.file-item.dragging { opacity: 0.4; }
.file-item.drop-target {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.2);
}
/* ラバーバンド選択（空白領域のドラッグで範囲指定） */
.rubber-band {
  position: fixed;
  z-index: 450; /* context-menu(400) の上・modal(500) の下 */
  background: rgba(99, 102, 241, 0.16);
  border: 1px solid var(--primary);
  border-radius: 3px;
  pointer-events: none;
}
.file-icon {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.file-icon svg { width: 26px; height: 26px; }
.file-icon.folder { background: #fef3c7; color: #d97706; }
.file-icon.folder.empty { opacity: 0.55; }
.file-icon { position: relative; }
.perm-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 11px;
  line-height: 1;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  pointer-events: none;
}
.share-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 11px;
  line-height: 1;
  background: #ecfeff;
  border: 1px solid #22d3ee;
  color: #0e7490;
  border-radius: 50%;
  padding: 1px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  pointer-events: none;
}
.org-share-badge {
  position: absolute;
  bottom: -4px;
  left: -4px;
  font-size: 11px;
  line-height: 1;
  background: #eef2ff;
  border: 1px solid #818cf8;
  color: #4338ca;
  border-radius: 50%;
  padding: 1px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  pointer-events: none;
}
.file-icon.folder.org-shared { background: #e0e7ff; color: #4f46e5; }
.file-icon.folder.org-shared.empty { opacity: 0.55; }
.folder-usage {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  max-width: 220px;
}
.folder-usage-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  min-width: 40px;
}
.folder-usage-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #818cf8);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.folder-usage.danger .folder-usage-fill { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.folder-usage-pct { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.file-icon.image { background: #dcfce7; color: #16a34a; }
.file-icon.audio { background: #fae8ff; color: #c026d3; }
.file-icon.video { background: #fce7f3; color: #db2777; }
.file-icon.code { background: #e0f2fe; color: #0284c7; }
.file-icon.pdf { background: #fee2e2; color: #dc2626; }
.file-icon.archive { background: #fef3c7; color: #b45309; }
.file-icon.doc { background: #e0f2fe; color: #2563eb; }
.file-icon.sheet { background: #dcfce7; color: #15803d; }
.file-icon.generic { background: #f1f5f9; color: #64748b; }

/* ============================================================
   プレビュー表示モード（アイコンを実サムネイルに置き換え）
   ============================================================ */
.file-thumb {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0f172a;
  border-radius: 10px;
}
.file-thumb .file-icon { box-shadow: none; }
/* プレビュー無し要素のメディア枠（アイコンは中央に少し大きめ表示） */
.file-thumb.file-thumb-icon .file-icon { width: 56px; height: 56px; }
.file-thumb.file-thumb-icon .file-icon svg { width: 32px; height: 32px; }
.item-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 10px;
}
.list-view .file-thumb { width: 46px; height: 46px; }
.grid-view .file-thumb {
  width: 100%;
  height: 118px;
}
.grid-view .item-thumb { border-radius: 8px; }

.file-meta { min-width: 0; flex: 1; }
.grid-view .file-meta { width: 100%; }
.file-name {
  font-weight: 500;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
}
.file-details {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-details .added-by { color: var(--text-faint); }
.file-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  /* 非表示（opacity:0）のときはクリックを受け付けない（選択中はボタン操作不可） */
  pointer-events: none;
  transition: var(--transition);
  flex-shrink: 0;
}
.grid-view .file-actions { position: absolute; top: 8px; right: 8px; }
.grid-view .file-item { position: relative; }
/* 操作ボタンは「未選択のアイテムにマウスを近づけたとき」だけ表示する
   （選択中のアイテムには出さない＝複数選択時の見づらさを防ぐ） */
.file-item:not(.selected):hover .file-actions {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   フルテキスト検索の結果表示
   ============================================================ */
#file-list.search-results .search-item { cursor: pointer; }
#file-list.search-results .search-item:hover { background: var(--surface-hover); }
#file-list.search-results .search-item .file-actions { opacity: 1; position: static; pointer-events: auto; }
.search-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.search-badge.name { background: var(--primary-light); color: var(--primary); }
.search-badge.content { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.search-badge.both { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.search-snippet {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.search-snippet::before { content: '“'; }
.search-snippet::after { content: '”'; }

/* ============================================================
   ファイル権限（閲覧可能者）
   ============================================================ */
.perm-detail-row .perm-summary-wrap { min-width: 0; }
.perm-summary {
  border: none;
  background: none;
  color: var(--primary);
  font-size: 12px;
  padding: 0;
  text-align: right;
  cursor: pointer;
  max-width: 100%;
  word-break: break-all;
}
.perm-summary:hover { text-decoration: underline; }
.perm-modal { max-width: 640px; }
.perm-count {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-muted);
}
.perm-empty {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.7;
  padding: 8px 0 12px;
}
.perm-actions { display: flex; gap: 8px; margin: 10px 0 4px; flex-wrap: wrap; }
.perm-clear-btn { color: var(--danger); }
.perm-inherit-note {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  margin: 4px 0 8px;
  line-height: 1.6;
}
.perm-add {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 12px;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  flex-wrap: wrap;
}
.perm-add select {
  flex: 1;
  min-width: 120px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
}
.perm-columns {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.perm-col {
  flex: 1 1 0;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}
.perm-col-head { margin-bottom: 6px; }
.perm-col-list { display: flex; flex-direction: column; gap: 6px; }
.perm-item.editable { cursor: pointer; }
.perm-item.editable:hover { outline: 1px solid var(--primary); }
.perm-level-select {
  padding: 3px 6px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  max-width: 110px;
  flex-shrink: 0;
}
.perm-remove {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.perm-remove:hover { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.perm-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  overflow-y: auto;
  padding: 4px 0;
}
.perm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--surface-hover);
}
.perm-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.perm-item-main { min-width: 0; flex: 1; }
.perm-item-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perm-item-type { font-size: 11px; color: var(--text-faint); }
.perm-badge-lv {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.perm-badge-lv.manage { background: var(--primary-light); color: var(--primary); }
.perm-badge-lv.read { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.perm-badge-lv.share { background: rgba(99, 102, 241, 0.15); color: #6366f1; }
.perm-badge-lv.write { background: rgba(245, 158, 11, 0.15); color: #d97706; }
.perm-badge-lv.delete { background: rgba(239, 68, 68, 0.15); color: #dc2626; }
.perm-levels-head {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 16px 0 6px;
}
.perm-levels { display: flex; flex-direction: column; gap: 6px; }
.perm-level-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.perm-level-desc { color: var(--text-muted); }
.mini-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.mini-btn:hover { color: var(--primary); background: #fff; }
.mini-btn.danger:hover { color: var(--danger); }
.mini-btn svg { width: 14px; height: 14px; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  color: var(--text-muted);
  flex: 1;
}
.empty-state svg { width: 64px; height: 64px; color: var(--text-faint); margin-bottom: 16px; }
.empty-state h3 { font-size: 17px; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; margin-bottom: 18px; }

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px;
  color: var(--text-muted);
  gap: 14px;
  flex: 1;
}
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ドロップゾーン（ドラッグ中のオーバーレイ） */
.drop-zone {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  /* 半透明の背景色オーバーレイ：下のコンテンツが透けて見え、
     浮いたパネルではなく「上からティントがかかった」ように見せる */
  background: rgba(99, 102, 241, 0.13);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  border: 2.5px dashed var(--primary);
  border-radius: var(--radius);
  color: var(--primary);
  font-weight: 600;
}
.drop-zone svg { width: 44px; height: 44px; }
.drop-zone p {
  margin: 0;
  padding: 10px 22px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   ステータスバー
   ============================================================ */
.statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 20px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  flex-shrink: 0;
}
.status-right { margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%; }
.statusbar .status-selection { color: var(--primary); font-weight: 600; }

/* ============================================================
   非同期の進捗表示（操作キュー / ジョブ）
   操作は画面に即時反映し、時間のかかる処理は裏で流す。その間だけ
   「同期中…」を出して、操作が消えていないことを示す。
   ============================================================ */
.status-jobs {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #b45309;
  font-weight: 600;
}
.status-jobs::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
  animation: gb-job-pulse 1.1s ease-in-out infinite;
}
@keyframes gb-job-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}
/* ステータスバーが無いページ（ゴミ箱など）ではフローティングで出す */
.gb-job-chip {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  font-size: 12.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.gb-job-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fbbf24;
  animation: gb-job-pulse 1.1s ease-in-out infinite;
}

/* ============================================================
   アップロード進行
   ============================================================ */
.upload-progress {
  position: fixed;
  right: 20px;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 14px 16px;
  z-index: 300;
}
.up-head {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 9px;
}
.up-head span:last-child { color: var(--text-muted); font-weight: 500; }
.up-bar {
  height: 6px;
  background: var(--surface-hover);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 8px;
}
.up-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 99px;
  transition: width 0.2s ease;
}
.up-overall {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.up-file {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.up-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.up-file-size { flex-shrink: 0; }
.up-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.up-meta-item { white-space: nowrap; }
.up-cancel {
  color: var(--danger-dark);
  border-color: #fecaca;
  margin-top: 2px;
}
.up-cancel:hover { background: var(--danger-light); }
.up-cancel.disabled { opacity: 0.6; pointer-events: none; }

/* ============================================================
   コンテキストメニュー
   ============================================================ */
.context-menu {
  position: fixed;
  z-index: 400;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  animation: menu-in 0.1s ease;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.cm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  transition: var(--transition);
}
.cm-item svg { width: 15px; height: 15px; color: var(--text-muted); }
.cm-item:hover { background: var(--surface-hover); }
.cm-item.danger { color: var(--danger-dark); }
.cm-item.danger svg { color: var(--danger); }
.cm-item.danger:hover { background: var(--danger-light); }
.cm-sep { height: 1px; background: var(--border); margin: 5px 6px; }

/* ============================================================
   モーダル
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  animation: fade-in 0.15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 440px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal h2 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.modal-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; word-break: break-all; }
.modal-input {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}
.modal-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.modal-danger { border-top: 4px solid var(--danger); }

/* アップロード時のファイル名重複一覧 */
.dupe-list {
  margin: 6px 0 0;
  padding: 0 0 0 20px;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text);
  font-size: 13px;
}
.dupe-list li { padding: 3px 0; word-break: break-all; }
.dupe-list li.dupe-more { color: var(--text-faint); font-size: 12.5px; }

/* ============================================================
   プレビュー
   ============================================================ */
.preview-overlay { padding: 24px; }
.preview-modal {
  position: relative;
  width: min(1100px, 100%);
  max-height: calc(100dvh - 48px);
  max-height: calc(100vh - 48px);
  background: var(--surface);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.preview-title {
  font-weight: 600;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.preview-size {
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
}
/* 画像プレビューの前後移動（同じディレクトリの画像を ← → / スワイプで切り替え）
   移動できるとき（画像が 2 枚以上）だけ、ヘッダーの枚数表示と左右の矢印を出す。 */
.preview-counter {
  display: none;
  align-items: center;
  color: var(--text-muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.preview-modal.nav-enabled .preview-counter { display: inline-flex; }
.preview-nav-btn {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.62);
  color: #fff;
  cursor: pointer;
  z-index: 5;
  transition: var(--transition);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.preview-modal.nav-enabled .preview-nav-btn { display: flex; }
.preview-nav-btn:hover { background: rgba(15, 23, 42, 0.88); }
.preview-nav-btn svg { width: 22px; height: 22px; }
.preview-nav-btn.prev { left: 10px; }
.preview-nav-btn.next { right: 10px; }
/* 端の画像では押しても動かないため、薄く表示して無効化する */
.preview-nav-btn.at-end { opacity: 0.25; cursor: default; pointer-events: none; }

/* 画像・動画の切り替え中は半透明にして「準備中」を伝える（待たされている感じを消す） */
.preview-body img.preview-image {
  transition: opacity 0.22s ease, filter 0.22s ease;
}
.preview-body img.preview-image.is-loading {
  opacity: 0.45;
  filter: blur(1.5px);
}
.preview-body video.is-loading { opacity: 0.45; }
.preview-preparing {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  color: #fff;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  pointer-events: none;
  z-index: 6;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.preview-note {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 40px));
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  color: #fff;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  pointer-events: none;
  z-index: 6;
}
.preview-body {
  position: relative;
  flex: 1;
  overflow: auto;
  background: #0f172a;
  min-height: 300px;
}
.preview-body img,
.preview-body video {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 160px);
  max-height: calc(100vh - 160px);
  margin: 0 auto;
  object-fit: contain;
}
/* 画像・動画は上下左右とも中央に置く（従来は上寄せだったため、小さい画像が上に偏って見えた）。
   width/height: auto + max-*: 100% で「表示領域に収まる範囲で最大サイズ」を保つ
   （max-height を画面高基準にすると flex 内で縮みすぎるため、親の高さ基準にする）。
   margin: auto は収まるとき中央、大きいときは 0 になりスクロールで全体を確認できる。 */
.preview-body:has(> img.preview-image),
.preview-body:has(> video) {
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-body > img.preview-image,
.preview-body > video {
  margin: auto;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}
.preview-body audio { width: 100%; padding: 30px 20px; }

/* ===== 端末側デコードの動画プレイヤー（MJPEG/MOV 等） =====
   サーバーで変換せず、ブラウザが JPEG フレームを直接デコードして canvas に描画する。 */
.mjpeg-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: calc(100dvh - 160px);
  height: calc(100vh - 160px);
  min-height: 300px;
  padding-bottom: 6px;
}
.mjpeg-canvas {
  max-width: 100%;
  max-height: calc(100% - 58px);
  object-fit: contain;
  border-radius: 6px;
  background: #000;
  cursor: pointer;
  /* バッファリング中は半透明にして「待たされていない」印象にする */
  transition: opacity 0.18s ease, filter 0.18s ease;
}
.mjpeg-canvas.is-buffering { opacity: 0.45; filter: blur(1.2px); }
.mjpeg-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 880px);
  padding: 0 18px;
}
.mjpeg-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(148, 163, 184, 0.18);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.mjpeg-btn:hover { background: rgba(148, 163, 184, 0.32); }
.mjpeg-btn:active { transform: scale(0.94); }
.mjpeg-btn svg { width: 20px; height: 20px; }
.mjpeg-seek {
  flex: 1 1 auto;
  height: 20px;
  cursor: pointer;
  accent-color: #38bdf8;
}
.mjpeg-time {
  flex: 0 0 auto;
  min-width: 96px;
  text-align: right;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.78);
}
/* プレイヤー内のメモは操作バーを邪魔しないよう通常フローで表示する */
.mjpeg-player .mjpeg-note {
  position: static;
  transform: none;
  margin: 0 18px;
  max-width: min(560px, calc(100% - 36px));
}
.preview-body iframe {
  width: 100%;
  height: calc(100dvh - 160px);
  height: calc(100vh - 160px);
  border: none;
  background: #fff;
}
.preview-body .monaco-wrap {
  height: calc(100dvh - 160px);
  height: calc(100vh - 160px);
  min-height: 300px;
}
.preview-body .monaco-wrap .monaco-editor,
.preview-body .monaco-wrap .overflow-guard {
  border-radius: 0;
}
.preview-body .monaco-loading,
.preview-body .pdf-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* プレビュー: PDF（pdf.js キャンバス描画） */
.pdf-preview { padding: 10px 16px 28px; }
.pdf-zoombar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: #0f172a;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pdf-zoom-btn {
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.pdf-zoom-btn:hover { border-color: var(--primary); color: var(--primary); }
.pdf-zoom-pct {
  min-width: 46px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
}
.pdf-preview .pdf-page-info {
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 6px 0 12px;
}
.pdf-preview .pdf-page {
  margin: 0 auto 16px;
}
.pdf-preview .pdf-page-inner {
  transform-origin: top left;
}
.pdf-preview .pdf-page canvas {
  display: block;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  border-radius: 4px;
}
/* ズーム時のドラッグパン（グラブカーソル） */
.pdf-pages.zoomable { cursor: grab; }
.preview-body.panning { cursor: grabbing !important; user-select: none; }
.preview-body .text-preview {
  background: #0f172a;
  color: #e2e8f0;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  padding: 20px 24px;
  white-space: pre-wrap;
  word-break: break-all;
}
.text-preview .truncated-note {
  color: #fbbf24;
  font-family: var(--font);
  padding: 10px 0 0;
  border-top: 1px solid #334155;
  margin-top: 14px;
}
.preview-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 300px;
  color: var(--text-muted);
  background: var(--surface);
}
.preview-error svg { width: 44px; height: 44px; color: var(--text-faint); }

/* プレビュー: CSV テーブル */
.csv-preview-wrap { overflow: auto; background: var(--surface); }
.csv-preview-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
  min-width: max-content;
}
.csv-preview-table th,
.csv-preview-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.csv-preview-table th {
  background: var(--surface-hover);
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}
.csv-preview-table tbody tr:nth-child(even) td { background: rgba(148, 163, 184, 0.06); }
.preview-body .truncated-note { padding: 10px 16px 16px; margin: 0; border-top: 1px solid #334155; }

/* プレビュー: PPTX スライド */
.pptx-preview { display: flex; flex-direction: column; gap: 14px; padding: 16px; background: #0f172a; }
.pptx-slide {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.pptx-slide-head {
  padding: 8px 14px;
  font-weight: 700;
  font-size: 12px;
  color: var(--primary);
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
}
.pptx-slide-text {
  margin: 0;
  padding: 14px;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e2e8f0;
}

/* ============================================================
   共有リンクモーダル
   ============================================================ */
.share-modal { width: 560px; max-width: calc(100vw - 32px); }
.share-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.seg-control {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 16px;
}
.seg {
  padding: 7px 14px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: var(--transition);
}
.seg:hover { color: var(--text); }
.seg.active {
  background: var(--primary-light);
  color: var(--primary);
}
.share-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px 0;
}
.share-loading .spinner { width: 20px; height: 20px; border-width: 2px; }
.share-links { margin-top: 4px; }
.share-links-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.share-count { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.share-links-list {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.share-link-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg);
}
.share-link-name {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-link-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.share-link-url {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  font-size: 11.5px;
  font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
  color: var(--text);
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-link-url:focus { border-color: var(--primary); }
.share-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  color: #4338ca;
  font-size: 12px;
  line-height: 1.5;
}
.share-note svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 1px; }

/* 共有範囲セレクタ・メール入力 */
.share-scope { margin-bottom: 2px; }
.share-scope .seg-control { margin-bottom: 14px; }
.share-emails { margin-bottom: 14px; }
.share-emails textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  resize: vertical;
  font-family: inherit;
  transition: var(--transition);
}
.share-emails textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

/* 共有リンク管理行 */
.share-manage-row { display: flex; flex-direction: column; gap: 6px; }
.share-link-title { overflow: hidden; text-overflow: ellipsis; }
.share-scope-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  vertical-align: middle;
}
.share-scope-badge.scope-anyone { background: #dcfce7; color: #15803d; }
.share-scope-badge.scope-login { background: #e0e7ff; color: #4338ca; }
.share-scope-badge.scope-emails { background: #fef3c7; color: #b45309; }
.share-link-expiry {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}
.share-link-emails {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 500;
  color: #b45309;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   モバイル追補（この位置＝ベース定義より後なので確実に上書きされる）
   ============================================================ */
@media (max-width: 720px) {
  /* トップバー: 検索ボックスとアクション群を残り幅に合わせて縮小。
     幅固定だと 320px 級の画面でトップバーからはみ出して横スクロールが発生する。 */
  .topbar-actions { flex-shrink: 1; min-width: 0; }
  .search-box { flex: 1; min-width: 0; }
  .search-box input { width: 100%; min-width: 0; }
  .search-box input:focus { width: 100%; }
}
.share-link-emails svg { width: 12px; height: 12px; flex-shrink: 0; }
.share-link-manage {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.share-link-manage .mini-btn {
  font-size: 11.5px;
  /* テキストラベル付きボタン: 正方形固定を解除し、内容に合わせて折り返しなしで表示 */
  width: auto;
  height: auto;
  min-height: 30px;
  padding: 6px 10px;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.4;
}

/* 共有「特定メール」の組織メンバーピッカー */
.share-org-picker {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.share-org-picker .share-label { display: block; margin-bottom: 6px; }
.share-org-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.share-org-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  transition: var(--transition);
}
.share-org-chip:hover { border-color: var(--primary); color: var(--primary); }
.share-org-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.share-org-chip .chip-sub { opacity: 0.7; font-size: 11px; }
.share-org-chip.active .chip-sub { opacity: 0.85; }
.share-org-chip .chip-off { color: var(--danger); font-size: 10px; font-weight: 700; }
.share-org-chip.active .chip-off { color: #fff; opacity: 0.9; }

/* 共有成功バナー */
.share-success {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #dcfce7;
  color: #15803d;
  font-size: 13px;
  font-weight: 700;
}
.share-success svg { width: 16px; height: 16px; flex-shrink: 0; }

/* 共有リンクの QR コード */
.share-link-qr {
  display: flex;
  justify-content: center;
  padding: 8px 0 2px;
}
.share-link-qr img {
  width: 140px;
  height: 140px;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

/* ゴミ箱: 完全削除までの残り時間 */
.trash-remaining { color: var(--primary); font-weight: 600; }

/* ============================================================
   トースト
   ============================================================ */
.toast-container {
  position: fixed;
  top: calc(110px + env(safe-area-inset-top, 0px));
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 600;
}
.toast {
  min-width: 260px;
  max-width: 380px;
  padding: 13px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 500;
  animation: toast-in 0.2s ease;
  border: 1px solid var(--border);
  cursor: pointer;
}
.toast:hover { border-color: var(--primary); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast.success { border-left: 4px solid #22c55e; }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }
.toast-icon { flex-shrink: 0; }
.toast.success .toast-icon { color: #22c55e; }
.toast.error .toast-icon { color: var(--danger); }
.toast.info .toast-icon { color: var(--primary); }

/* ============================================================
   スクロールバー
   ============================================================ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 99px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================================
   モバイル: 親フォルダへ移動ボタン + 長押しコンテキストメニュー
   ============================================================ */
/* 「↑」ボタンは PC（パンくずクリックで十分）では非表示、スマホでのみ表示 */
#up-btn { display: none; flex-shrink: 0; }
@media (max-width: 720px) {
  #up-btn { display: inline-flex; }
  #up-btn.disabled, #up-btn[disabled] { opacity: 0.4; pointer-events: none; }

  /* 長押しで PC の右クリックと同じ操作を行う。iOS の長押しコールアウトを抑止 */
  .file-item { -webkit-touch-callout: none; }

  /* コンテキストメニューをタッチしやすいサイズに調整 */
  .context-menu { min-width: 200px; max-height: 70vh; overflow-y: auto; }
  .cm-item { padding: 12px 14px; font-size: 14px; }
}

/* ============================================================
   モバイル: 検索オーバーレイを画面上部に固定表示
   ============================================================ */
/* スマホではソフトウェアキーボードが画面下部を占有するため、
   中央配置だと結果一覧が隠れてしまう。モバイルでは上揃えにして
   キーボードの上に収まるようにする（dvh = キーボードを除いた高さ）。 */
@media (max-width: 720px) {
  #search-overlay {
    align-items: flex-start;          /* 中央 → 上揃え */
    justify-content: center;
    padding: 8px 10px 0;
    background: rgba(15, 23, 42, 0.35);
  }
  #search-overlay .search-overlay-panel {
    width: 100%;
    max-width: 100%;
    border-radius: 14px;
    max-height: min(72dvh, calc(100dvh - 12px));
    display: flex;
    flex-direction: column;
  }
  #search-overlay .search-overlay-input-wrap {
    padding: 14px 16px;
    flex-shrink: 0;
  }
  #search-overlay .search-overlay-results {
    max-height: none;                 /* パネルの高さに合わせて伸縮 */
    flex: 1 1 auto;
    min-height: 48px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #search-overlay .search-overlay-foot {
    flex-shrink: 0;
    padding: 8px 16px 12px;
  }
}

/* ============================================================
   モバイル: 組織管理ページは閲覧専用（簡易版）
   ============================================================ */
/* スマホでは管理操作を行わない設計のため、概要（統計・メンバー一覧）のみ表示し、
   管理セクション・操作ボタンは隠す。PC では従来どおり全機能を表示する。 */
.org-mobile-note {
  display: none;
  align-items: center;
  gap: 12px;
  margin: 14px 14px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  color: #3730a3;
  font-size: 13px;
  line-height: 1.6;
}
.org-mobile-note svg { width: 22px; height: 22px; flex-shrink: 0; color: #4f46e5; }
.org-mobile-note strong { display: block; }
@media (max-width: 720px) {
  /* hidden 属性（UA の display:none）に負けないよう !important で表示 */
  #org-mobile-note { display: flex !important; }
  /* 管理専用セクション（ロール/ストレージ/料金/高度設定）を非表示 */
  .org-manage-only { display: none !important; }
  /* メンバー追加フォーム・検索/CSV ツール・操作ボタン・操作列を非表示（読み取り専用化） */
  .org-add-member { display: none !important; }
  .org-member-tools { display: none !important; }
  .org-actions { display: none !important; }
  #org-members-table .org-act-col { display: none !important; }
  /* 組織情報の編集ボタンを非表示 */
  #org-name-edit, #org-peruser-edit { display: none !important; }
}

/* ============================================================
   誤選択防止: アプリ全体でテキスト選択を無効化
   （スマホの長押しや PC のドラッグで文字が誤選択されるのを防ぐ。
    フォーム入力・テキスト/CSV/PPTX プレビュー等は選択を許可する）
   ============================================================ */
* {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
input, textarea, select, [contenteditable="true"] {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}
/* コンテンツを読む・コピーする箇所は選択を許可 */
.text-preview,
.text-preview *,
.csv-preview-wrap,
.csv-preview-wrap *,
.csv-preview-table,
.pptx-slide-text {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

/* ============================================================
   バックエンド情報（ストレージ設定・コスト等）はシステム管理者のみ表示
   （法人/組織管理者など一般ユーザーに Cloudflare R2 等の情報が漏れないように）
   ============================================================ */
body.non-sys-admin .sys-admin-only { display: none !important; }

/* ============================================================
   折りたたみサイドバー: アバター/ロゴをレール中央に置く（モバイル上書き）
   ≤720px はサイドバーの左右パディングが 8px になるため補正量を 7px にする
   （8 + 7 = 15 = (64 - 34) / 2 でレール中央に一致）。このブロックは
   ファイル末尾に置く（途中の 720px ブロックは後方の基本定義に負けるため）。
   ============================================================ */
@media (max-width: 720px) {
  .sidebar.collapsed .sidebar-brand,
  .sidebar.collapsed .sidebar-user { padding-left: 7px; }
}

/* ============================================================
   操作性（タッチ・小さい画面）
   ・指で押しやすい当たり判定（目安 40〜44px）
   ・iOS の入力欄の自動ズームを防ぐ（16px 未満だと勝手に拡大される）
   ・スマホ縦（≤480px）でツールバーが縦に伸びて本文を押し下げるのを防ぐ
   ※ spacedrive-desktop/src/web.css はこのファイルの転用。同じ内容を保つこと
   ============================================================ */

/* ダブルタップでの拡大を防ぎ、タップの反応を速くする（見た目は変わらない） */
button, a, label, summary,
.side-link, .crumb, .file-item, .cm-item, .tab { touch-action: manipulation; }

/* タッチ環境（スマホ・タブレット・タッチ対応ノート PC）での当たり判定 */
@media (pointer: coarse) {
  /* iOS Safari はフォーカス時に 16px 未満の入力欄を勝手に拡大する。
     入力するたびに画面が拡大して戻す操作が必要になるため 16px に揃える。 */
  .search-box input,
  .toolbar-path-input,
  .modal-input,
  .form-group input,
  .form-group select,
  .form-group textarea { font-size: 16px; }

  .sidebar-toggle { width: 40px; height: 40px; right: -20px; }
  .sidebar.collapsed .sidebar-toggle { right: 8px; }
  .sidebar-toggle svg { width: 15px; height: 15px; }
  .icon-btn { width: 40px; height: 40px; }
  .crumb { min-height: 40px; padding: 0 10px; }
  /* すべてのボタンは 40px 以上（アカウント画面などの小さいボタンも含む） */
  .btn { min-height: 40px; }
  .sidebar .side-link { min-height: 44px; }
  .sidebar .side-link svg { width: 20px; height: 20px; }
  .sidebar-user-info { min-height: 44px; }
  .sidebar-user .avatar { width: 38px; height: 38px; }
  .file-item { min-height: 52px; }
  .cm-item { min-height: 44px; }
}

/* スマホ縦（≤480px）: 重なる UI を全幅にして、ツールバーを 1 行に詰める */
@media (max-width: 480px) {
  /* ツールバー: 左右を縦に並べ、余白と間隔を詰める。
     アップロード/新規フォルダが同じ行に収まり、表示領域を約 100px 節約できる。 */
  .toolbar { padding: 8px 10px; gap: 8px; }
  .toolbar-left { flex: 1 1 100%; gap: 8px; }
  .toolbar-right { flex: 1 1 100%; justify-content: flex-start; }
  /* サイドバーのレール（64px）ぶん本文が狭いため、ボタンを詰めて 1 行に収める。
     縦パディング（9px）は残すこと（0 にすると文字だけの高さに潰れる） */
  .toolbar .btn { padding: 9px 10px; font-size: 12.5px; gap: 5px; }
  .toolbar .btn svg { width: 15px; height: 15px; }
  /* 移動先パス入力は狭い画面では使わない（breadcrumb と長押しメニューで代用できる） */
  .toolbar-path-wrap { display: none; }

  /* 詳細パネルは本文と重なるため全幅で出し、閉じやすくする */
  .detail-panel { width: 100vw; max-width: 100vw; }

  /* 選択バーは折り返して 320px 級でもボタンが切れないようにする */
  .selection-bar {
    flex-wrap: wrap;
    justify-content: center;
    white-space: normal;
    max-width: calc(100vw - 24px);
    gap: 8px;
  }
  .selection-count { width: 100%; text-align: center; margin: 0 0 2px; }

  /* ステータスバーは 2 段でも収まるように折り返す */
  .statusbar { flex-wrap: wrap; gap: 6px 12px; }
  .status-right { max-width: 100%; }

  /* カード表示は高さが揃わなくなるので 1 行のまま省略する。
     リスト表示は情報が収まらないため折り返して読めるようにする */
  #file-list:not(.grid-view) .file-item .file-details { white-space: normal; line-height: 1.4; }
}

