:root {
  --border: #d8d8d8;
  --bg: #f7f7f5;
  --card: #ffffff;
  --text: #222;
  --muted: #777;
  --accent: #2563eb;
  --accent-bg: #eaf1ff;
  --resolved-bg: #f0f7f0;
}

* { box-sizing: border-box; }

.print-only { display: none; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

.page-header h1 {
  font-size: 1.3rem;
  margin: 0 0 0.6rem;
}
.beta {
  font-size: 0.7rem;
  font-weight: normal;
  color: var(--muted);
  border: 1px solid var(--muted);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  margin-left: 0.4rem;
}

.week-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}
.week-range { font-size: 1.05rem; }

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn:hover { background: #f0f0f0; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #1d4fd8; }
.btn-resolve {
  background: #e8f8ee;
  border-color: #34a853;
  color: #1b6b34;
}
.btn-hide {
  background: #f3f0ff;
  border-color: #7c5cbf;
  color: #4a3480;
}
.btn-danger {
  background: #fdecea;
  border-color: #d93025;
  color: #a50e0e;
}
.btn-danger:hover { background: #fbd7d3; }
.btn-small { font-size: 0.75rem; padding: 0.2rem 0.5rem; }

.jump-form {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}
.jump-form input[type="date"] {
  padding: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.search-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}
.search-form {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}
.search-form input[type="text"] {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 220px;
}

.readonly-banner {
  background: #fff7e6;
  border: 1px solid #f0c36d;
  color: #7a5b00;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
}
.warn-banner {
  background: #fdecea;
  border: 1px solid #f0a29c;
  color: #a50e0e;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
}

.table-scroll {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

table.grid {
  border-collapse: collapse;
  width: 100%;
  min-width: 640px;
}
table.grid th, table.grid td {
  border: 1px solid var(--border);
  padding: 0.6rem;
  vertical-align: top;
  text-align: left;
}
table.grid thead th {
  background: #fafafa;
  position: sticky;
  top: 0;
  font-size: 0.9rem;
  white-space: nowrap;
}
table.grid .topic-col { min-width: 160px; }
table.grid td.topic-cell {
  position: sticky;
  left: 0;
  background: var(--card);
  min-width: 160px;
  font-weight: 600;
}
table.grid td.cell { min-width: 220px; }

tr.hidden-row { background: var(--resolved-bg); opacity: 0.75; }
tr.hidden-row td.topic-cell { background: var(--resolved-bg); }

.topic-title { font-weight: 600; }
.topic-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.badge.hidden-badge {
  display: inline-block;
  font-size: 0.7rem;
  background: #7c5cbf;
  color: #fff;
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.3rem;
}
.topic-controls {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: flex-start;
}
.inline-form { display: inline-block; }
.hide-toggle-block { display: flex; flex-direction: column; gap: 0.15rem; }
.hint-text { font-size: 0.7rem; color: var(--muted); margin: 0; max-width: 220px; }

.memo-item {
  padding: 0.35rem 0;
  border-bottom: 1px dashed var(--border);
}
.memo-item:last-of-type { border-bottom: none; }
.cell-content { white-space: pre-wrap; word-break: break-word; }
.cell-content.empty { color: var(--muted); font-style: italic; }
.cat-icon { font-size: 1rem; }
.cell-meta { font-size: 0.7rem; color: var(--muted); margin-top: 0.2rem; }

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: #f0f0f0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.1rem 0.5rem;
  font-size: 0.75rem;
}
.attachment-chip a { color: var(--text); text-decoration: none; }
.attachment-chip a:hover { text-decoration: underline; }
.attachment-size { color: var(--muted); }
.attachment-delete {
  border: none;
  background: none;
  color: #a50e0e;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 0.1rem;
}
.attachment-image {
  flex-direction: column;
  align-items: flex-start;
  padding: 0.3rem;
  border-radius: 6px;
}
.attachment-image a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}
.attachment-thumb {
  max-width: 120px;
  max-height: 120px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #fff;
}
.attachment-caption {
  font-size: 0.7rem;
  max-width: 120px;
  text-align: center;
  word-break: break-all;
}

.file-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}
.file-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  flex: 1;
  min-width: 140px;
}
.file-label input[type="file"] {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.8rem;
  max-width: 100%;
}

.cell-edit, .memo-edit, .row-edit {
  margin-top: 0.3rem;
}
.cell-edit summary, .memo-edit summary, .row-edit summary {
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--accent);
  user-select: none;
}
.cell-edit form, .memo-edit form, .row-edit form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.4rem;
  background: var(--accent-bg);
  padding: 0.5rem;
  border-radius: 6px;
}
.cell-edit textarea, .cell-edit select, .cell-edit input[type="text"],
.memo-edit textarea, .memo-edit select, .memo-edit input[type="text"],
.row-edit textarea, .row-edit select, .row-edit input[type="text"] {
  width: 100%;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.85rem;
}

/* アイコンピッカー(カテゴリ作成/編集) */
.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  background: var(--card);
  padding: 0.4rem;
  border-radius: 6px;
}
.icon-choice {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
  background: #fff;
}
.icon-choice input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.icon-choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-bg);
  box-shadow: 0 0 0 2px var(--accent-bg);
}

.add-topic, .admin-section {
  margin-top: 1rem;
}
.add-topic form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem;
}
.add-topic input[type="text"] {
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  flex: 1;
  min-width: 160px;
}

.admin-section {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.admin-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  min-width: 260px;
  flex: 1;
}
.admin-block > summary {
  cursor: pointer;
  font-weight: 600;
}
.admin-list {
  list-style: none;
  margin: 0.6rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.admin-list > li {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
}
.admin-section > .admin-block > form {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.admin-section input[type="text"] {
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem !important;
}

/* ---- モバイル: グリッド→カード形式 ---- */
@media screen and (max-width: 768px) {
  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-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
  }
  table.grid td {
    border: none;
    border-bottom: 1px dashed var(--border);
    padding: 0.5rem 0.2rem;
  }
  table.grid td:last-child { border-bottom: none; }
  table.grid td.topic-cell {
    position: static;
    border-bottom: 2px solid var(--border);
  }
  table.grid td.cell::before,
  table.grid td.topic-cell::before {
    content: attr(data-label);
    display: block;
    font-weight: bold;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 0.2rem;
  }
  .week-nav { gap: 0.4rem; }
}

/* ==== Client Board 追加スタイル ==== */
.tab-bar { display: flex; gap: 4px; margin: 0.6rem 0; border-bottom: 2px solid var(--border); }
.tab { padding: 0.4rem 0.9rem; text-decoration: none; color: var(--muted); border: 1px solid var(--border);
  border-bottom: none; border-radius: 6px 6px 0 0; background: #eee; }
.tab-active { background: var(--card); color: var(--text); font-weight: bold; border-color: var(--border); }
.pin-badge { display: inline-block; background: #e7f3e7; color: #2a7d2a; border: 1px solid #b6d9b6;
  border-radius: 4px; padding: 1px 8px; font-size: 0.8rem; }
.unlock-box { max-width: 380px; margin: 3rem auto; padding: 1.5rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--card); }
.unlock-box label { display: block; margin: 0.8rem 0; }
.unlock-box input[type=password] { width: 100%; padding: 0.5rem; font-size: 1rem; }
table.mat-table th, table.mat-table td { text-align: left; }
table.mat-table td.num, table.mat-table th.num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.mat-thumb { max-width: 36px; max-height: 36px; vertical-align: middle; margin-right: 6px; border-radius: 4px; }
.neg-row { background: #fdecec; }
.big-balance { font-size: 1.1rem; margin: 0.8rem 0; }
.big-balance.neg strong, .neg { color: #c02626; }
.txn-form { display: flex; flex-direction: column; gap: 0.6rem; max-width: 460px; }
.txn-form label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.9rem; }
.txn-form input, .txn-form select { padding: 0.5rem; font-size: 1rem; }
.badge.status-proposed { background: #fff4d6; color: #8a6d00; }
.badge.status-in_progress { background: #dcecff; color: #1c4e8a; }
.badge.status-done { background: #e2e2e2; color: #555; }
.done-row { opacity: 0.6; }
.topic-materials { margin: 0.3rem 0; font-size: 0.85rem; }
.topic-materials ul { margin: 0.2rem 0 0; padding-left: 1.2rem; }

/* ---- 印刷: 選択中の週のスナップショットをA4横で ---- */
@media print {
  .no-print { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  .page { max-width: none; padding: 0; }
  .print-header { margin-bottom: 8px; }
  .print-header h1 { font-size: 14pt; margin: 0 0 2px; }
  .print-week-range { font-size: 10pt; color: #333; margin: 0; }
  .table-scroll { border: none; overflow: visible; }
  table.grid { min-width: 0; width: 100%; }
  table.grid th, table.grid td { border: 1px solid #333; padding: 4px 6px; font-size: 10pt; }
  table.grid td.topic-cell { position: static; }
  /* 添付画像は印刷にも含める(PDFはファイル名のみ・紙には埋め込めないため) */
  .attachment-thumb { max-width: 70px; max-height: 70px; }
  .attachment-caption { max-width: 70px; font-size: 6.5pt; }
  .attachment-chip { break-inside: avoid; }
  @page { size: landscape; margin: 10mm; }
}
