/* Clarity OS - Stylesheet (base.htmlから移植・統合) */
:root {
  --green: #06c755;
  --green-dark: #05b34c;
  --green-soft: #e6f7ed;
  --surface: #f7f8f9;
  --border: #e5e5e5;
  --text-sub: #666;
  --dynamo: #16a34a;
  --blaze: #dc2626;
  --tempo: #eab308;
  --steel: #2563eb;
}
* { box-sizing: border-box; }
body {
  font-family: SFPro, Arial, "Noto Sans JP", sans-serif;
  background: var(--surface);
  color: #000;
  min-height: 100vh;
  margin: 0;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 220px;
  background: #fff;
  border-right: 1px solid var(--border);
  height: 100vh;          /* 高さを固定し、内容が溢れたら内部スクロール */
  max-height: 100vh;
  overflow-y: auto;       /* ナビ項目が多くてもサインアウトまで到達できる */
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: transform .2s;
}
.main-wrap { margin-left: 220px; min-height: 100vh; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-sub);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border-right: 3px solid transparent;
  transition: all .15s;
}
.nav-item:hover { background: var(--surface); color: #000; }
.nav-item.active {
  background: var(--green-soft);
  color: var(--green);
  border-right-color: var(--green);
}
.nav-section {
  padding: 14px 20px 6px;
  font-size: 11px;
  color: var(--text-sub);
  font-weight: 700;
  letter-spacing: .5px;
}
.logo-mark {
  width: 34px; height: 34px;
  background: var(--green);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 900; font-size: 18px; flex-shrink: 0;
}

/* ===== Card ===== */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: 8px;
  font-weight: 700; font-size: 14px;
  border: none; cursor: pointer;
  text-decoration: none; transition: all .15s;
  font-family: inherit;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-ghost { background: transparent; color: #000; border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}
.badge-green  { background: var(--green-soft); color: var(--green); }
.badge-red    { background: #fee2e2; color: var(--blaze); }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-blue   { background: #dbeafe; color: var(--steel); }
.badge-gray   { background: var(--surface); color: var(--text-sub); }

/* ===== Forms ===== */
.form-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border .15s;
  background: #fff;
}
.form-input:focus { border-color: var(--green); }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 5px;
}
.form-group { margin-bottom: 14px; }

/* ===== Alerts ===== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  font-weight: 600;
}
.alert-success {
  background: var(--green-soft);
  color: var(--dynamo);
  border-left: 3px solid var(--green);
}
.alert-error {
  background: #fee2e2;
  color: var(--blaze);
  border-left: 3px solid var(--blaze);
}

/* ===== WD frequency colors ===== */
.freq-dynamo { color: var(--dynamo); }
.bg-dynamo   { background: #f0fdf4; border-color: var(--dynamo); }
.freq-blaze  { color: var(--blaze); }
.bg-blaze    { background: #fff5f5; border-color: var(--blaze); }
.freq-tempo  { color: #a16207; }
.bg-tempo    { background: #fefce8; border-color: var(--tempo); }
.freq-steel  { color: var(--steel); }
.bg-steel    { background: #eff6ff; border-color: var(--steel); }

/* ===== Progress bar ===== */
.prog-track {
  height: 6px;
  background: #f0f0f0;
  border-radius: 3px;
  overflow: hidden;
}
.prog-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .3s;
}

/* ===== Rate colors ===== */
.rate-high { color: var(--dynamo); font-weight: 700; }
.rate-mid  { color: #a16207; font-weight: 700; }
.rate-low  { color: var(--blaze); font-weight: 700; }

/* ===== Table ===== */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.tbl th {
  background: var(--surface);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  border-bottom: 2px solid var(--border);
  text-align: left;
}
.tbl td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tr:hover td { background: #fafafa; }

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  margin: 16px;
  max-height: 90vh;
  overflow-y: auto;
}

/* ===== Mobile (≤ 768px) ===== */
#menu-toggle { display: none; }
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  #menu-toggle { display: flex; }
  .overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 40;
  }
  .overlay.show { display: block; }
}

/* ===== Utility ===== */
.flex-row { display: flex; align-items: center; gap: 8px; }
.gap-12 { gap: 12px; }
.text-sub { color: var(--text-sub); }
.text-xs { font-size: 12px; }
.text-sm { font-size: 13px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.font-bold { font-weight: 700; }
.font-black { font-weight: 900; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }

/* ============================================================
   📱 モバイル強化 (≤ 768px) — タブレット縦・スマホ
   ============================================================ */
@media (max-width: 768px) {

  /* ── レイアウト / パディング ── */
  body { font-size: 14px; }
  .main-wrap > div { padding: 16px !important; }

  /* ── 2カラム系グリッド → 1カラム ── */
  [style*="grid-template-columns:1.4fr"],
  [style*="grid-template-columns: 1.4fr"],
  [style*="grid-template-columns:1.6fr"],
  [style*="grid-template-columns: 1.6fr"],
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  /* ── 3〜4列固定グリッド → 2x2 ── */
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns:repeat(3, 1fr)"],
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  /* ── auto-fit minmax(420px) → 1カラム (プロミスカード) ── */
  [style*="minmax(420px"] {
    grid-template-columns: 1fr !important;
  }
  [style*="minmax(160px"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  /* ── 見出し縮小 ── */
  h1 { font-size: 18px !important; line-height: 1.3; }
  h2 { font-size: 16px !important; }
  h3 { font-size: 15px !important; }

  /* ── KPIストリップ内の巨大数字を縮小 ── */
  [style*="font-size:32px"] { font-size: 24px !important; }
  [style*="font-size: 32px"] { font-size: 24px !important; }
  [style*="font-size:28px"] { font-size: 22px !important; }
  [style*="font-size: 28px"] { font-size: 22px !important; }
  [style*="font-size:26px"] { font-size: 20px !important; }
  [style*="font-size:22px"] { font-size: 18px !important; }

  /* ── KPIカード自身のパディング縮小 ── */
  .card[style*="padding:18px"],
  .card[style*="padding: 18px"] { padding: 14px !important; }

  /* ── ボタン: 縦並び・フルワイド化 (ヘッダー右側のボタン群) ── */
  .btn { padding: 10px 14px; font-size: 13px; }

  /* ヘッダー右側のボタン群: ラップする */
  h1 + p + div, /* タイトル下の説明 + ボタン群想定外パターン */
  [style*="display:flex"][style*="align-items:flex-start"][style*="justify-content:space-between"] > div:last-child {
    width: 100%;
  }
  [style*="display:flex"][style*="align-items:flex-start"][style*="justify-content:space-between"] > div:last-child > .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* ── テーブル: 横スクロール + 小型化 ── */
  .card[style*="overflow:auto"],
  .card[style*="overflow: auto"] { -webkit-overflow-scrolling: touch; }
  .tbl { font-size: 13px; min-width: max-content; }
  .tbl th, .tbl td { padding: 8px 10px; white-space: nowrap; }
  .tbl td > div { flex-wrap: wrap; gap: 4px; }
  /* テーブル内ボタン: 操作列のボタンが折り返し */
  .tbl td .btn { padding: 6px 10px !important; font-size: 11px !important; }
  .tbl td form { display: inline-block; }

  /* ── フォーム: iOS自動ズーム回避(16px以上) ── */
  .form-input,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  textarea,
  select { font-size: 16px !important; }

  /* ── モーダル ── */
  .modal-box {
    padding: 20px !important;
    max-width: calc(100vw - 24px) !important;
    margin: 12px !important;
  }
  /* モーダル内の2カラムフォーム → 1カラム */
  .modal-box [style*="grid-template-columns:1fr 1fr"],
  .modal-box [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* モーダル内アクションボタン: フルワイド */
  .modal-box [style*="display:flex"][style*="margin-top"] > .btn {
    width: 100%;
  }

  /* ── サイドバー: モバイル時の幅・パディング ── */
  /* 100dvh でアドレスバー分を除いた実表示領域に合わせ、サインアウトが隠れないように */
  .sidebar { width: 260px; height: 100dvh; max-height: 100dvh; }
  .nav-item { padding: 12px 18px; font-size: 14px; }

  /* ── プロミスカード: WD周波数バッジ調整 ── */
  .card[style*="border-left:4px solid"] {
    padding: 16px !important;
  }

  /* ── コンパス: Fun Scoreドットの折り返し ── */
  #fun-dots { gap: 4px !important; }
  #fun-dots > div {
    width: 32px !important;
    height: 32px !important;
    font-size: 12px !important;
  }

  /* ── フライトデック: KPIカード横並び抑止 ── */
  /* (上のrepeat(4,1fr) → 2x2 で対応済) */

  /* ── ボタン群のラップ ── */
  [style*="display:flex"][style*="gap:8px"][style*="flex-wrap:wrap"] > .btn,
  [style*="display:flex"][style*="gap:8px"][style*="flex-wrap:wrap"] > a {
    flex: 0 1 auto;
  }

  /* ── 週ナビゲーション（フライトデック）: 改行回避 ── */
  .btn[style*="padding:7px 12px"] { padding: 8px 10px !important; font-size: 12px !important; }
}

/* ============================================================
   📱 スマホ縦 (≤ 480px) — さらにコンパクト
   ============================================================ */
@media (max-width: 480px) {

  .main-wrap > div { padding: 12px !important; }

  /* ── 3〜4列のKPI: 完全縦並び or 2列継続 ── */
  /* auto-fit minmax(160px)は2列のまま */
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ── 巨大数字さらに縮小 ── */
  [style*="font-size:32px"] { font-size: 22px !important; }
  [style*="font-size:28px"] { font-size: 20px !important; }

  /* ── 見出し縮小 ── */
  h1 { font-size: 17px !important; }

  /* ── ボタン ── */
  .btn { padding: 9px 12px; font-size: 12px; }

  /* ── サイドバーをフルワイドに ── */
  .sidebar { width: 85vw; max-width: 320px; }

  /* ── プロミスカード内のスコアセレクト: 数字とラベルを小さく ── */
  .card select { font-size: 13px !important; padding: 4px 6px !important; }

  /* ── タブボタン (プロミス画面の8プロミス/成功条件タブ) ── */
  [id^="tab-"] { padding: 8px 12px !important; font-size: 12px !important; }

  /* ── テーブルセルパディング縮小 ── */
  .tbl th, .tbl td { padding: 6px 8px; }
  .tbl { font-size: 12px; }

  /* ── KPIカード内のラベル ── */
  .card [style*="font-size:11px"] { font-size: 10px !important; }
  .card [style*="font-size:12px"] { font-size: 11px !important; }

  /* ── プログレスバー薄く ── */
  .prog-track { height: 5px; }
}

/* ============================================================
   📱 横スクロール改善 (テーブル等)
   ============================================================ */
@media (max-width: 1024px) {
  .card[style*="overflow:auto"],
  .card[style*="overflow: auto"] {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  /* スクロール可能を視覚的に示すヒント */
  .card[style*="overflow:auto"]::after,
  .card[style*="overflow: auto"]::after {
    content: '';
    position: sticky;
    right: 0;
    width: 0;
  }
}

/* ============================================================
   📱 タップ領域確保 (アクセシビリティ)
   ============================================================ */
@media (max-width: 768px) {
  /* タップ可能要素は最低44pxの高さ確保 */
  a.btn, button.btn {
    min-height: 40px;
  }
  .nav-item { min-height: 44px; }
}

