/* CMS の見た目。明るい青系。毎日使う業務画面なので、読みやすさと一覧性を優先する */
:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --fg: #142033;
  --muted: #5d6b82;
  --line: #e3e8f0;
  --line-strong: #cbd4e1;
  --accent: #1d5bd8;
  --accent-hover: #164bb6;
  --accent-soft: #e9f0fd;
  --accent-ring: rgba(29, 91, 216, 0.22);
  --ok: #157a4a;
  --ok-soft: #e3f5ec;
  --warn: #9a5b06;
  --warn-soft: #fdf2dd;
  --danger: #b42318;
  --danger-soft: #fdebea;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 8px 24px -8px rgba(15, 42, 92, 0.18);
  --font: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", "Meiryo", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 var(--font);
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}
body.bare { display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- サイドバー ---- */
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; letter-spacing: 0.02em; white-space: nowrap; }
.brand-mark {
  flex: none;
  width: 26px; aspect-ratio: 91 / 55; border-radius: 4px;
  background: linear-gradient(135deg, var(--accent) 0%, #4f8cf7 100%);
  box-shadow: 0 2px 6px rgba(29, 91, 216, 0.35);
}
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500;
}
.side nav a:hover { background: var(--surface-2); color: var(--fg); text-decoration: none; }
.side nav a.active { background: var(--accent-soft); color: var(--accent); }
.side nav svg, .icon-button svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
.me { display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none;
}
.me-text { min-width: 0; flex: 1; }
.me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-role { font-size: 12px; color: var(--muted); }
.icon-button {
  display: grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); color: var(--fg); }

/* ---- 本文 ---- */
main { padding: 28px 32px 64px; max-width: 1720px; width: 100%; }
h1 { font-size: 22px; line-height: 1.35; margin: 0 0 6px; font-weight: 700; letter-spacing: 0.01em; }
h1 + p.muted { margin-top: 0; }
h2 { font-size: 15px; margin: 28px 0 10px; font-weight: 700; }
.muted { color: var(--muted); }
p { margin: 0 0 12px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
form.card, div.card { margin-bottom: 16px; }

/* ---- 表 ---- */
table.list {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
table.list th, table.list td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; letter-spacing: 0.03em; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover td { background: #f8fbff; }
table.list td a { font-weight: 600; }
table.list td.empty { text-align: center; color: var(--muted); padding: 32px 14px; }
.period { display: flex; align-items: center; gap: 6px; }
.period input { width: 140px; }
.table-scroll { overflow-x: auto; border-radius: var(--radius); }
table.nowrap td { white-space: nowrap; }
table.list th.check, table.list td.check { width: 40px; padding-right: 0; }

/* ---- ツールバー（まとめての操作） ---- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 12px 16px; }
.toolbar .group { display: flex; align-items: center; gap: 8px; }
.toolbar select { width: auto; min-width: 200px; }

/* ---- 状態のバッジ ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---- ボタン・入力欄 ---- */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; height: 36px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
button.secondary, .button.secondary { background: var(--surface); color: var(--accent); border-color: var(--line-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--accent-soft); border-color: var(--accent); }
button.link { height: auto; padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; }
button.link:hover { text-decoration: underline; background: none; }
button:focus-visible, .button:focus-visible, a:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

input, select, textarea {
  font: inherit; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 7px 10px; min-height: 36px; width: 100%;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--accent); margin: 0 4px 0 0; vertical-align: -2px; }
/* 単独のチェックボックス（一覧の行の選択など）も標準の見た目を使わない */
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 18px; height: 18px; padding: 0; margin: 0;
  border: 1.5px solid var(--line-strong); border-radius: 5px; background: var(--surface) center / 12px 12px no-repeat;
  cursor: pointer; vertical-align: middle; transition: background-color 0.12s, border-color 0.12s;
}
input[type="checkbox"]:hover { border-color: var(--accent); }
input[type="checkbox"]:checked {
  border-color: var(--accent); background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E");
}
input[type="checkbox"]:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
table.list label:has(> input[type="checkbox"]) { margin: 0; }
input[type="file"] { padding: 5px; background: var(--surface-2); color: var(--muted); }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; height: 28px; padding: 0 12px; margin-right: 10px; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--accent);
}
input[type="file"]::file-selector-button:hover { border-color: var(--accent); background: var(--accent-soft); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
textarea { resize: vertical; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
/* チェックボックスはボタン型のトグルで表す（小さな四角だけが先頭に並ぶと読み取りにくいため） */
label:has(> input[type="checkbox"]) {
  position: relative; display: inline-flex; align-items: center; gap: 7px;
  min-height: 34px; padding: 5px 14px 5px 10px; margin: 0 8px 8px 0;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface);
  font-size: 14px; font-weight: 500; color: var(--fg); white-space: nowrap; cursor: pointer; user-select: none;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
label:has(> input[type="checkbox"]):hover { border-color: var(--accent); }
label:has(> input[type="checkbox"]) > input[type="checkbox"] {
  position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none;
}
label:has(> input[type="checkbox"])::before {
  content: ""; flex: none; width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid var(--line-strong); background: var(--surface) center / 10px 10px no-repeat;
  transition: background-color 0.12s, border-color 0.12s;
}
label:has(> input[type="checkbox"]:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
label:has(> input[type="checkbox"]:checked)::before {
  border-color: var(--accent); background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E");
}
label:has(> input[type="checkbox"]:focus-visible) { box-shadow: 0 0 0 3px var(--accent-ring); }
label:has(> input[type="radio"]) { display: inline-flex; align-items: center; font-size: 14px; font-weight: 500; color: var(--fg); margin: 0 14px 6px 0; white-space: nowrap; }
.toggles { display: flex; flex-wrap: wrap; margin-bottom: 6px; }

/* 主担当（担当者のトグルの中の星） */
input[type="radio"].star {
  appearance: none; -webkit-appearance: none; width: 18px; height: 18px; margin: 0 0 0 2px; padding: 0; border: 0; min-height: 0;
  background: center / 16px 16px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%2394a3b8' stroke-width='1.2' d='M8 1.8l1.9 3.9 4.3.6-3.1 3 .7 4.3L8 11.6l-3.8 2 .7-4.3-3.1-3 4.3-.6z'/%3E%3C/svg%3E");
  cursor: pointer; border-radius: 4px;
}
input[type="radio"].star:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23f59e0b' stroke='%23d97706' stroke-width='1' d='M8 1.8l1.9 3.9 4.3.6-3.1 3 .7 4.3L8 11.6l-3.8 2 .7-4.3-3.1-3 4.3-.6z'/%3E%3C/svg%3E");
}
input[type="radio"].star:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.form-row { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 14px; align-items: end; }
.form-row > label:has(> input[type="checkbox"]) { align-self: center; }
table.list input, table.list select { min-height: 32px; padding: 4px 8px; }
table.list select { width: auto; min-width: 110px; }
table.list input[type="checkbox"] { min-height: 0; padding: 0; }

/* ---- お知らせ ---- */
.notice { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: #18407f; margin-bottom: 16px; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.field-warn { margin: 4px 0 0; color: var(--warn); font-size: 12px; }
option.invalid { color: var(--danger); }
label.invalid, label.invalid:has(> input[type="checkbox"]:checked) { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.toast {
  position: fixed; top: 20px; right: 24px; z-index: 10; max-width: 420px;
  padding: 12px 16px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid #f5c2bd; border-left: 0; color: var(--danger); box-shadow: var(--shadow-lg); font-weight: 600;
}

/* ---- ホームの件数 ---- */
.tasks { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-top: 16px; }
.tasks a { display: block; color: var(--fg); transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s; }
.tasks a:hover { text-decoration: none; border-color: #b9cdf5; box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.tasks .count { font-size: 32px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.tasks .count.zero { color: var(--line-strong); }

/* ---- ログイン ---- */
body.bare main { display: grid; place-items: center; min-height: 100vh; max-width: none; padding: 24px; }
.login { width: min(100%, 400px); padding: 28px; }
.login .brand { padding: 0 0 16px; }
.login .hint { font-size: 0.85em; color: var(--muted); }
.login .qr { display: flex; justify-content: center; margin: 12px 0; }
.login .qr svg { width: 200px; height: 200px; background: #fff; padding: 8px; }
.login input { width: 100%; }

/* ---- 狭い画面 ---- */
@media (max-width: 900px) {
  body { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 10px 12px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .side nav { flex-direction: row; }
  .side nav a span { white-space: nowrap; }
  .me { border-top: 0; padding: 0; }
  .me-text { display: none; }
  main { padding: 20px 16px 48px; }
}

/* ---- 人を選ぶ ---- */
.picker { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); padding: 10px 12px; margin-bottom: 14px; }
.picker-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.picker-tools select, .picker-tools input { width: auto; min-width: 180px; }
.picker-list { display: flex; flex-wrap: wrap; max-height: 260px; overflow-y: auto; padding: 2px; }

/* ---- ヘルプ（? のボタンと吹き出し） ---- */
button.help {
  position: relative; display: inline-grid; place-items: center; vertical-align: 2px;
  width: 20px; height: 20px; min-height: 0; padding: 0; margin-left: 8px;
  border: 1px solid var(--line-strong); border-radius: 50%; background: var(--surface);
  color: var(--muted); font: 700 12px/1 var(--font); cursor: help;
}
button.help:hover, button.help:focus-visible { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
button.help::after {
  content: attr(data-help); position: absolute; top: calc(100% + 8px); left: -10px;
  width: max-content; max-width: 340px; white-space: normal; text-align: left;
  padding: 10px 12px; border-radius: var(--radius-sm); background: #12305f; color: #fff;
  font: 500 13px/1.65 var(--font); letter-spacing: 0; box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden; transition: opacity 0.12s, visibility 0.12s; z-index: 30; pointer-events: none;
}
button.help:hover::after, button.help:focus::after { opacity: 1; visibility: visible; }
button.help.right::after { left: auto; right: -10px; }

/* ---- 保存の行（入力済みのトグルと保存ボタン） ---- */
.save-bar {
  position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 16px; padding: 12px 16px; background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(4px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.save-bar > label:has(> input[type="checkbox"]) { margin: 0; }
.save-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.dirty-note { color: var(--warn); font-weight: 600; font-size: 13px; }
.dirty-note::before { content: "● "; }

/* ---- 名刺の詳細：左に名刺画像とメモ（画面に固定）、右に入力 ---- */
.card-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 24px; align-items: start; }
.card-side {
  position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px; padding: 2px 6px 2px 2px;
}
.card-side #remarks { margin-top: 4px; }
.viewer-tabs { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.viewer-tabs button {
  height: 28px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-weight: 600;
}
.viewer-tabs button:hover { background: var(--surface-2); color: var(--fg); }
.viewer-tabs button.active { background: var(--accent); color: #fff; }
.viewer-face img { display: block; width: 100%; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--surface); }
.viewer-face a:hover img { border-color: #b9cdf5; }
.viewer-note { font-size: 12px; margin: 6px 0 0; }
.pdf-link { display: block; padding: 24px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); font-weight: 600; }
.back-row { display: flex; gap: 8px; align-items: center; }
.back-row input { flex: 1; }
@media (max-width: 1100px) {
  .card-layout { grid-template-columns: minmax(0, 1fr); }
  .card-side { position: static; max-height: none; overflow: visible; }
}
.form-row.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 700px) { .form-row.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* 名刺画像の回転・切り出し */
.image-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.image-editor canvas { display: block; max-width: 100%; touch-action: none; cursor: crosshair; background: #222; }
