/*
 * LinDXブランドトークンを継承(DX/portal/index.html基準)。
 * 配色は1アクセント(--green)に固定、影は背景色(warm charcoal)にトーンを合わせる、
 * 角丸は1系統(--radius-sm/--radius/--radius-lg)に統一する(design-taste-frontend §4.2/4.4準拠)。
 */
:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-alt: #f4f1ec;
  --text: #2e2a24;
  /* Codexレビュー2026-08-22指摘対応: 旧値#8a8279は白背景でコントラスト比約3.78:1でWCAG AA(4.5:1)未達。
     #6e6459は同約5.8:1でAA適合(補助テキスト全般に使用するため) */
  --text-dim: #6e6459;
  --border: #e6e0d8;

  --green: #4a7c59;
  --green-light: #e8f0ea;
  --coral: #c56b5a;
  --coral-light: #fdf0ee;
  --brown: #6b5b4e;
  --brown-light: #f0ebe6;
  --danger: #b23b2f;
  --danger-light: #faeae7;

  --accent: var(--green);
  --accent-light: var(--green-light);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  --shadow: 0 2px 12px rgba(46, 42, 36, 0.06);
  --shadow-lift: 0 6px 24px rgba(46, 42, 36, 0.1);

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Noto Sans JP', "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---- 全体レイアウト ---- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.7rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
}
.app-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
}
.app-title a { color: var(--text); text-decoration: none; }
.app-title .dx {
  display: inline-block;
  background: var(--green);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 0.4rem;
  position: relative;
  top: -1px;
}

.app-nav {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  flex: 1;
}
.app-nav a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.app-nav a:hover { background: var(--surface-alt); color: var(--text); }
.app-nav a.active { background: var(--green-light); color: var(--green); font-weight: 700; }

.app-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.app-user .role-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--green-light);
  color: var(--green);
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.6rem 1.2rem 3rem;
}
.page-narrow { max-width: 480px; }

.page-header { margin-bottom: 1.2rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; margin: 0 0 0.35rem; letter-spacing: -0.01em; }
.page-header p.lead { color: var(--text-dim); margin: 0; font-size: 0.9rem; }

/* ---- カード・区切り ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}

/* ---- ボタン(§4.5: hover/active/disabledを全て定義) ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.08s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.btn:hover { background: var(--surface-alt); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: #3e6a4b; box-shadow: var(--shadow-lift); }
.btn-danger { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #f5d9d3; }
.btn-block { width: 100%; }
.btn-small { font-size: 0.78rem; padding: 0.3rem 0.6rem; }

/* ---- フォーム(§4.6: ラベルは上、エラーは下、プレースホルダーをラベル代わりにしない) ---- */
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1rem; }
.field label { font-size: 0.85rem; font-weight: 600; }
.field input, .field select, .field textarea {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-light);
}
.field .help { font-size: 0.75rem; color: var(--text-dim); }
.field .error-text { font-size: 0.8rem; color: var(--danger); }
.field.has-error input { border-color: var(--danger); }
.field.has-error input:focus { box-shadow: 0 0 0 3px var(--danger-light); }

.form-row { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: flex-start; }
.form-row .field { flex: 1; min-width: 160px; margin-bottom: 0; }
.form-row .btn { margin-top: 1.7rem; }

/* ---- バナー(状態通知) ---- */
.banner {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.banner-error { background: var(--danger-light); border-color: #e3b2a9; color: var(--danger); }
.banner-warn { background: var(--coral-light); border-color: #e3b6a9; color: var(--coral); }
.banner-success { background: var(--green-light); border-color: #b7d2bf; color: var(--green); }

/* ---- 区画キャンバス(⑨) ---- */
.canvas-frame {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.canvas-surface {
  position: relative;
  min-width: 900px;
  min-height: 600px;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  background-color: var(--surface-alt);
}
.canvas-block {
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  box-shadow: var(--shadow);
  touch-action: none;
}
.canvas-block:active { cursor: grabbing; box-shadow: var(--shadow-lift); }
.canvas-block.assigned { background: var(--green-light); border-color: #b7d2bf; color: var(--green); }
.canvas-block.placeholder { background: var(--surface); border-style: dashed; color: var(--text-dim); }
/* ②フロアマップ(閲覧版)の3色区分(Codexレビュー2026-08-25 I-02対応)。黄=現場例外、橙=拠点ズレ例外。
   後発の.canvas-block.assignedより優先させるためCSS内で後ろに置く。 */
.canvas-block.exception-mismatch { background: var(--coral-light); border-color: #e3b6a9; color: var(--coral); }
.canvas-block.exception-manual { background: #fdf6e0; border-color: #e6d28a; color: #8a6d1a; }
.canvas-block.highlight { box-shadow: 0 0 0 3px var(--coral), var(--shadow-lift); z-index: 5; }

.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.3rem; vertical-align: middle; }
.legend-dot-green { background: var(--green); }
.legend-dot-orange { background: var(--coral); }
.legend-dot-yellow { background: #e6d28a; }
.legend-dot-placeholder { background: var(--surface); border: 1px dashed var(--text-dim); }
.canvas-block-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--danger);
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
}
.canvas-block-confirm {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translate(-50%, -100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
  padding: 0.4rem;
  display: flex;
  gap: 0.3rem;
  align-items: center;
  white-space: nowrap;
  font-weight: 400;
  z-index: 10;
}

/* ---- テーブル ---- */
.table-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
table.grid { border-collapse: collapse; width: 100%; min-width: 560px; }
table.grid th, table.grid td {
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  text-align: left;
  vertical-align: middle;
}
table.grid thead th {
  background: var(--surface-alt);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.grid tbody tr { transition: background 0.1s var(--ease); }
table.grid tbody tr:hover { background: var(--surface-alt); }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid a.row-link { color: var(--text); text-decoration: none; font-weight: 600; }
table.grid a.row-link:hover { color: var(--green); }

/* ---- バッジ ---- */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge-open { background: var(--green-light); border-color: #b7d2bf; color: var(--green); }
.badge-closed { background: var(--surface-alt); border-color: var(--border); color: var(--text-dim); }
.badge-warn { background: var(--coral-light); border-color: #e3b6a9; color: var(--coral); }

/* ---- 空状態 ---- */
.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 2.6rem 1rem;
  font-size: 0.9rem;
}

/* ---- ログイン画面専用 ---- */
.login-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  background: var(--bg);
}
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 1.25rem; font-weight: 700; margin: 0 0 0.25rem; }
.login-card p.lead { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 1.3rem; }

/* ---- データ取り込み: ドロップゾーン・選択済みファイルチップ ---- */
.import-section { margin-bottom: 1.6rem; }
.import-section h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
.import-section .section-desc { color: var(--text-dim); font-size: 0.82rem; margin: 0 0 0.9rem; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), color 0.15s var(--ease);
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover {
  border-color: var(--green);
  background: var(--green-light);
  color: var(--text);
}
.dropzone:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.dropzone input[type='file'] { display: none; }

.file-chip-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.35rem 0.25rem 0.7rem;
  font-size: 0.78rem;
}
.file-chip button {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.15rem 0.4rem;
  border-radius: 50%;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.file-chip button:hover { background: var(--border); color: var(--text); }

/* ---- Phase5閲覧画面: 統計タイル・進捗バー ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-tile .stat-label { font-size: 0.78rem; color: var(--text-dim); margin: 0 0 0.3rem; }
.stat-tile .stat-value { font-size: 1.6rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.stat-tile .stat-value.stat-warn { color: var(--coral); }
.progress-bar { background: var(--surface-alt); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar-fill { background: var(--green); height: 100%; border-radius: 999px; transition: width 0.3s var(--ease); }

/* ---- ③ロードマップ ---- */
.roadmap-track { display: flex; gap: 0; margin: 1.4rem 0; overflow-x: auto; }
.roadmap-stage {
  flex: 1;
  min-width: 200px;
  position: relative;
  padding: 1rem 1.1rem 1.1rem;
  border: 1px solid var(--border);
  border-right: none;
  background: var(--surface);
}
.roadmap-stage:first-child { border-radius: var(--radius-lg) 0 0 var(--radius-lg); }
.roadmap-stage:last-child { border-radius: 0 var(--radius-lg) var(--radius-lg) 0; border-right: 1px solid var(--border); }
.roadmap-stage.is-complete { background: var(--green-light); }
.roadmap-stage.is-current { background: var(--surface); box-shadow: inset 0 0 0 2px var(--green); }
.roadmap-stage .stage-order { font-size: 0.72rem; color: var(--text-dim); font-weight: 600; }
.roadmap-stage .stage-label { font-size: 1rem; font-weight: 700; margin: 0.2rem 0 0.3rem; }
.roadmap-stage .stage-dates { font-size: 0.78rem; color: var(--text-dim); }
.roadmap-stage .stage-marker {
  position: absolute;
  top: -0.6rem;
  left: 1.1rem;
  background: var(--green);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

/* ---- モバイル: 密なテーブルをカード形式に ---- */
@media screen and (max-width: 768px) {
  .app-nav { display: none; }
  table.grid, table.grid thead, table.grid tbody,
  table.grid tr, table.grid th, table.grid td { display: block; width: 100%; }
  table.grid thead { display: none; }
  table.grid { min-width: 0; }
  table.grid tr {
    margin: 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0.3rem 0.6rem;
  }
  table.grid td { border-bottom: 1px dashed var(--border); padding: 0.5rem 0.2rem; }
  table.grid td:last-child { border-bottom: none; }
  table.grid td::before {
    content: attr(data-label);
    display: block;
    font-weight: 700;
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-bottom: 0.15rem;
  }
  .roadmap-track { flex-direction: column; }
  .roadmap-stage, .roadmap-stage:first-child, .roadmap-stage:last-child {
    border-radius: var(--radius-lg);
    border-right: 1px solid var(--border);
    margin-bottom: 0.6rem;
  }
}
