/* 修繕・原状回復 進捗管理 - スタイル
   方針: 実務ツールとして読みやすく、地味に。スマホ縦1カラムを基本にPCで横に広げる。
   ダークモード/ライトモードどちらでも崩れないよう、配色はCSS変数で固定する（prefers-color-schemeに依存しない）。 */

:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --text: #1a2129;
  --muted: #667085;
  --border: #dde1e6;
  --primary: #1d5fd6;
  --primary-dark: #16469f;
  --danger: #d92d20;
  --danger-bg: #fdecea;
  --success: #17824e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo,
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

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

h1, h2, h3 { margin: 0 0 .6em; color: var(--text); }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; margin-top: 1.2em; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- レイアウト共通 ---------- */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  flex-wrap: wrap;
}
.app-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}
.app-title:hover { text-decoration: none; }
.app-header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.user-name { color: var(--muted); font-size: .9rem; }
.app-nav {
  display: flex;
  gap: 4px;
  padding: 0 8px 8px;
}
.app-nav a {
  padding: 8px 14px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
  font-size: .95rem;
}
.app-nav a.active {
  background: var(--primary);
  color: #fff;
}
.app-nav a:hover { text-decoration: none; background: var(--bg); }
.app-nav a.active:hover { background: var(--primary-dark); }

#main {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.loading, .empty { color: var(--muted); padding: 16px 0; }
.error, .error-box {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0;
  font-size: .92rem;
}
.text-danger { color: var(--danger); }

/* ---------- ボタン ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  min-height: 44px;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 7px 12px; min-height: 36px; font-size: .88rem; }
.btn-block { width: 100%; }
.btn-action {
  flex: 1 1 auto;
  min-width: 130px;
}

/* ---------- ログイン画面 ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
}
.login-card h1 { text-align: center; margin-bottom: 1.2em; }
#login-form label, .edit-form label, .quick-form label, .modal-box label, .filter-form label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 12px;
}
#login-form input, .edit-form input, .edit-form select, .edit-form textarea,
.quick-form input, .quick-form textarea, .modal-box input, .modal-box select,
.filter-form input, .filter-form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}
#login-form input:focus, .edit-form input:focus, .edit-form select:focus, .edit-form textarea:focus,
.quick-form input:focus, .quick-form textarea:focus, .modal-box input:focus, .modal-box select:focus,
.filter-form input:focus, .filter-form select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ---------- 件数の大表示 ---------- */

.big-count {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  color: var(--primary);
}
.big-count-unit { font-size: 1.4rem; font-weight: 700; margin-left: 4px; }
.big-count-label { color: var(--muted); margin: 6px 0 16px; font-size: .95rem; }

/* ---------- バッジ ---------- */

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-kubun { background: #eaf1ff; color: var(--primary-dark); border-color: #cfe0ff; }
.badge-status { background: #f1f1f4; color: var(--text); }
.badge-kind { background: #eef7f0; color: var(--success); border-color: #cdeed6; }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.badge-muted { color: var(--muted); }

/* ---------- 案件カード一覧（自分のボール） ---------- */

.anken-list { list-style: none; margin: 0; padding: 0; }
.anken-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.anken-card.is-stale { border-color: var(--danger); }
.anken-card-link { display: block; padding: 12px 14px; color: var(--text); }
.anken-card-link:hover { background: var(--bg); text-decoration: none; }
.anken-card-top { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; align-items: center; }
.anken-card-title { font-weight: 700; font-size: 1.05rem; margin-bottom: 4px; }
.anken-card-sub {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: .88rem;
}

/* ---------- 全体（フィルタ＋一覧） ---------- */

.filter-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
}
.checkbox-label { display: flex; align-items: center; gap: 8px; }
.checkbox-label input { width: auto; margin: 0; }
.filter-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.all-count { color: var(--muted); margin: 10px 0; font-weight: 700; }

.anken-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.anken-table th, .anken-table td {
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
}
.anken-table thead th { color: var(--muted); font-weight: 700; font-size: .82rem; }
.anken-table tr.is-stale td:first-child { border-left: 3px solid var(--danger); }
.anken-table tr.is-stale { background: var(--danger-bg); }

/* ---------- 案件詳細 ---------- */

.back-link {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  padding: 8px 0;
  cursor: pointer;
  font-size: .95rem;
}
.anken-head-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.anken-id { color: var(--muted); font-size: .85rem; }
.anken-head-title { margin-bottom: 4px; }
.anken-head-titlerow { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; }
.anken-head-naiyo { font-size: 1.1rem; font-weight: 700; color: var(--accent, #1a56db); }
.anken-head-tel { color: var(--text, inherit); font-weight: 600; white-space: nowrap; }
.anken-card-naiyo { margin-left: 10px; font-weight: 600; font-size: .9rem; color: var(--accent, #1a56db); }
.anken-head-sub { color: var(--muted); font-size: .9rem; margin-bottom: 14px; }

.status-ball-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.status-ball-item {
  flex: 1 1 140px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.status-ball-label { font-size: .78rem; color: var(--muted); margin-bottom: 2px; }
.status-ball-value { font-size: 1.2rem; font-weight: 800; }

.action-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }

.quick-form {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
}
.quick-form-title { font-weight: 700; margin-bottom: 8px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item {
  border-left: 2px solid var(--border);
  padding: 4px 0 14px 14px;
  margin-left: 4px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.timeline-at { color: var(--muted); font-size: .85rem; }
.timeline-author { color: var(--muted); font-size: .85rem; font-weight: 600; }
.timeline-body { white-space: pre-wrap; font-size: .95rem; }
.timeline-attachments { margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.timeline-img { max-width: 160px; max-height: 160px; border-radius: 8px; border: 1px solid var(--border); display: block; }

/* ---------- 編集フォーム ---------- */

details.panel summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}
details.panel summary::-webkit-details-marker { display: none; }
details.panel summary::before { content: "▶ "; color: var(--muted); }
details.panel[open] summary::before { content: "▼ "; }

.edit-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 16px;
  margin-top: 10px;
}
.edit-grid-full { grid-column: 1 / -1; }

.gyosha-list { display: flex; flex-direction: column; gap: 10px; }
.gyosha-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

/* ---------- 新規起票モーダル ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 12px;
  z-index: 50;
  overflow-y: auto;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 480px;
}

/* ---------- PC幅での拡張 ---------- */

@media (min-width: 700px) {
  #main { padding: 20px; }
  .edit-grid { grid-template-columns: 1fr 1fr; }
  .anken-table thead th, .anken-table td { font-size: .92rem; }
}

@media (min-width: 640px) {
  .filter-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    align-items: end;
    gap: 10px;
  }
  .filter-form .filter-buttons { grid-column: 1 / -1; }
}

/* 全体一覧: 狭い画面ではテーブルをカード風に積む */
@media (max-width: 640px) {
  .anken-table thead { display: none; }
  .anken-table, .anken-table tbody, .anken-table tr, .anken-table td { display: block; width: 100%; }
  .anken-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 6px 10px;
  }
  .anken-table tr.is-stale td:first-child { border-left: none; }
  .anken-table td {
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 2px;
  }
  .anken-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: .8rem;
    flex: 0 0 auto;
  }
}

/* ---------- 会社（案件の管理元 SPEC §26）---------- */
.badge-company { font-weight: 700; letter-spacing: 0.02em; }
.badge-company-sb { background: #e8f0fe; color: #1a4fb3; border-color: #b9cdf5; }
.badge-company-re { background: #fff1e0; color: #a35400; border-color: #f3cf9f; }
.company-count { color: var(--muted); font-size: .9rem; font-weight: 700; margin: -10px 0 16px; }
.field-static { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 4px 0; }
.field-static-label { font-size: 0.85rem; color: var(--muted); }
.field-static-note { font-size: 0.8rem; color: var(--muted); }

/* ---------- §31-5 スマホのヘッダーを1段に詰める（700px未満） ----------
   PC幅は従来どおり（2段・名前とボタンを並べる）。スマホ幅では「修繕｜自分のボール 全体 集計｜☰」の1段にし、
   名前・新規起票・ログアウトは ☰ の中（下に開くメニュー）へ畳む。 */
.hdr-menu-btn { display: none; }
.app-title-short { display: none; }
.hdr-menu-name { display: none; }

@media (max-width: 699.98px) {
  .app-header { display: flex; align-items: center; gap: 4px; padding: 4px 6px; }
  .app-header-top { display: contents; }
  .app-title { order: 0; flex: 0 0 auto; padding: 0 4px; font-size: 1rem; }
  .app-title-full { display: none; }
  .app-title-short { display: inline; }
  .app-nav { order: 1; flex: 1 1 auto; min-width: 0; padding: 0; gap: 2px; overflow-x: auto; scrollbar-width: none; }
  .app-nav::-webkit-scrollbar { display: none; }
  .app-nav a { padding: 7px 10px; font-size: .9rem; white-space: nowrap; }
  .hdr-menu-btn {
    order: 2; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
    min-width: 40px; min-height: 40px; padding: 0 8px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
    font-size: 1.15rem; line-height: 1; cursor: pointer;
  }
  .app-header.menu-open .hdr-menu-btn { background: var(--bg); }
  .app-header-user {
    display: none; position: absolute; right: 6px; top: calc(100% + 4px); z-index: 30;
    flex-direction: column; align-items: stretch; gap: 8px; min-width: 210px; padding: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 6px 20px rgba(16, 24, 40, .18);
  }
  .app-header.menu-open .app-header-user { display: flex; }
  .app-header-user .user-name { padding: 2px 2px 6px; border-bottom: 1px solid var(--border); }
  .app-header-user .btn { width: 100%; min-height: 44px; }
}
