:root {
  --border: #d4d4d4;
  --head-bg: #f3f3f3;
  --head-hl: #e1e8f0;
  --sel-bg: rgba(33, 115, 70, 0.12);
  --accent: #217346;
  --gray: #efefef;
  --red: #f4cccc;
  --green: #d9ead3;
  --edit-head: #dff0e5;
  --ro-tint: rgba(0, 0, 0, 0.045);
  --text: #1f1f1f;
  --muted: #666;
  font: 13px/1.4 "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: #fff; }
main { flex: 1; min-height: 0; position: relative; }
button, input { font: inherit; }

/* ---------------------------------------------------------------- ツールバー */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center;
  padding: 6px 10px; border-bottom: 1px solid var(--border); background: #fafafa;
}
.toolbar .group { display: flex; gap: 4px; align-items: center; }
.toolbar .grow { flex: 1; justify-content: flex-end; }
button {
  padding: 3px 10px; border: 1px solid #c8c8c8; border-radius: 3px; background: #fff; cursor: pointer;
}
button:hover:not(:disabled) { background: #f0f0f0; }
button:disabled { color: #aaa; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #1a5c38; }
button.primary:disabled { background: #9bbfa9; border-color: #9bbfa9; color: #fff; }
button.dirty { box-shadow: 0 0 0 2px #f2b84b; }
#search { width: 220px; padding: 3px 6px; border: 1px solid #c8c8c8; border-radius: 3px; }
.folder-name { color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.message {
  display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.message[hidden] { display: none; }
.message.info { background: #eef6ff; }
.message.error { background: #fdecea; }
.message pre { flex: 1; margin: 0; font: inherit; white-space: pre-wrap; max-height: 30vh; overflow: auto; }
.message button { border: none; background: transparent; font-size: 16px; line-height: 1; padding: 0 4px; }

.statusbar { padding: 3px 10px; border-top: 1px solid var(--border); background: #fafafa; color: var(--muted); }

.empty { max-width: 640px; margin: 48px auto; padding: 0 16px; }
.empty h1 { font-size: 20px; }
.empty .note { color: var(--muted); }

.busy-overlay {
  display: none; position: fixed; inset: 0; background: rgba(255, 255, 255, 0.6);
  align-items: center; justify-content: center; z-index: 50; cursor: progress;
}
.busy-overlay span { padding: 10px 16px; background: #fff; border: 1px solid var(--border); border-radius: 4px; }
body.busy .busy-overlay { display: flex; }

/* ---------------------------------------------------------------- 表 */
.grid { position: absolute; inset: 0; }
.grid[hidden] { display: none; }
.grid-viewport { position: absolute; inset: 0; overflow: auto; outline: none; }
.grid-sheet { position: relative; min-height: 100%; }
.grid-header {
  position: sticky; top: 0; z-index: 3; display: flex; height: 28px; background: var(--head-bg);
  border-bottom: 1px solid #bdbdbd;
}
.grid-corner, .grid-hcell {
  flex: none; height: 28px; border-right: 1px solid var(--border); background: var(--head-bg);
}
.grid-corner { position: sticky; left: 0; z-index: 2; cursor: cell; }
.grid-hcell {
  position: relative; display: flex; align-items: center; padding: 0 2px 0 6px;
  font-weight: 600; user-select: none; cursor: s-resize;
}
.grid-hcell.frozen { position: sticky; z-index: 1; }
.grid-hcell.hl { background: var(--head-hl); }
.grid-hcell.editable { background: var(--edit-head); color: var(--accent); }
.grid-hcell.editable.hl { background: #c9e3d2; }
.grid-hlabel { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.grid-sortmark { color: var(--accent); font-size: 10px; }
.grid-filterbtn {
  flex: none; width: 18px; height: 18px; padding: 0; font-size: 11px; line-height: 16px;
  border-color: #c8c8c8; color: #555;
}
.grid-filterbtn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.grid-resizer { position: absolute; top: 0; right: -3px; width: 6px; height: 100%; cursor: col-resize; z-index: 1; }

.grid-body { position: relative; }
.grid-row { position: absolute; left: 0; right: 0; display: flex; height: 24px; }
.grid-rownum, .grid-cell {
  flex: none; height: 24px; line-height: 23px; border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.grid-rownum {
  position: sticky; left: 0; z-index: 2; background: var(--head-bg); color: var(--muted);
  text-align: center; cursor: e-resize; user-select: none;
}
.grid-rownum.hl { background: var(--head-hl); color: var(--text); }
.grid-cell { padding: 0 5px; background: #fff; cursor: cell; user-select: none; }
.grid-cell.frozen { position: sticky; z-index: 1; }
.grid-cell.center { text-align: center; }
/* 編集できないセルは薄い灰色を重ねて文字も淡くし、編集できるセル（白地）と見分けられるようにする */
.grid-cell.ro { color: #7a7a7a; background-image: linear-gradient(var(--ro-tint), var(--ro-tint)); }
.grid-cell.choice { position: relative; padding-right: 20px; }
.grid-ddbtn {
  position: absolute; top: 3px; right: 3px; width: 16px; height: 16px; line-height: 14px;
  text-align: center; font-size: 10px; color: #555; background: #fff;
  border: 1px solid #c8c8c8; border-radius: 2px; cursor: pointer;
}
.grid-ddbtn:hover { background: #e8f0e9; border-color: var(--accent); color: var(--accent); }
.grid-cell a { color: #1155cc; }
.grid-row.gone .grid-cell { background: var(--gray); color: #888; }
.grid-row.red .grid-cell { background: var(--red); }
.grid-row.green .grid-cell { background: var(--green); }
.grid-cell.sel { background-image: linear-gradient(var(--sel-bg), var(--sel-bg)); }
.grid-cell.ro.sel { background-image: linear-gradient(var(--sel-bg), var(--sel-bg)), linear-gradient(var(--ro-tint), var(--ro-tint)); }
.grid-cell.active { box-shadow: inset 0 0 0 2px var(--accent); }

/* 入力用 textarea: 普段は透明でクリックを通し、編集中だけ表示する */
.grid-input {
  position: absolute; z-index: 4; margin: 0; padding: 2px 5px; border: 2px solid var(--accent);
  font: inherit; line-height: 18px; resize: none; overflow: hidden; background: #fff;
  opacity: 0; pointer-events: none; white-space: pre;
}
.grid-input.editing { opacity: 1; pointer-events: auto; white-space: pre-wrap; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); }
.grid-input.editing.multiline { overflow: auto; }
.grid-input.invalid { border-color: #c62828; }

.grid-dropdown, .grid-menu {
  position: absolute; z-index: 10; background: #fff; border: 1px solid #bdbdbd;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.grid-dropdown[hidden], .grid-menu[hidden] { display: none; }
.grid-dditem { padding: 3px 10px; cursor: pointer; }
.grid-dditem.on, .grid-dditem:hover { background: #e8f0e9; }
.grid-menu { width: 250px; padding: 6px; }
.grid-menu hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
.grid-menuitem { display: block; width: 100%; text-align: left; border: none; padding: 4px 8px; }
.grid-menufind { width: 100%; padding: 3px 6px; margin-bottom: 4px; border: 1px solid #c8c8c8; }
.grid-menulist { max-height: 240px; overflow: auto; border: 1px solid var(--border); padding: 2px 0; }
.grid-menucheck { display: flex; gap: 6px; align-items: center; padding: 1px 6px; white-space: nowrap; }
.grid-menucheck[hidden] { display: none; }
.grid-menubuttons { display: flex; gap: 4px; justify-content: flex-end; margin-top: 6px; }
