:root {
  --green: #1f9d55;
  --green-dark: #178048;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #232b33;
  --muted: #6b7684;
  --danger: #d64545;
  --accent: #2b6cb0;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
/* hidden 属性は常に非表示（.topnav 等の display 指定に打ち消されないように） */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Yu Gothic UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* topbar */
#topbar { background: var(--panel); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.topbar-inner { display: flex; align-items: center; gap: 16px; padding: 10px 18px; max-width: 1400px; margin: 0 auto; }
.brand { font-weight: 700; font-size: 17px; color: var(--green-dark); background: none; border: none; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; padding: 0; }
.brand-icon { display: block; flex: 0 0 auto; }
.login-logo { display: block; width: 44px; height: 44px; margin: 0 auto 8px; }
.topnav { display: flex; gap: 6px; align-items: center; }
.topnav button, .topnav-link {
  background: none; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  color: var(--text); font-size: 14px; text-decoration: none; display: inline-block;
}
.topnav button:hover, .topnav button.active, .topnav-link:hover { background: #eef6f0; color: var(--green-dark); }
.menu-dropdown a.menu-item { text-decoration: none; box-sizing: border-box; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-size: 13px; }

/* アカウント/ハンバーガー メニュー */
.menu-wrap { position: relative; }
.menu-btn { display: flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; cursor: pointer; color: var(--text); font-size: 14px; }
.menu-btn:hover { background: #f0f2f4; }
.menu-btn .menu-caret { color: var(--muted); }
.menu-btn .ham-icon { display: none; font-size: 18px; line-height: 1; }
.menu-dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12); padding: 6px; z-index: 50; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text); }
.menu-item:hover { background: #f0f2f4; }
.menu-divider { height: 1px; background: var(--border); margin: 6px 4px; }
.menu-mobile-only { display: none; }
@media (max-width: 720px) {
  .topnav { display: none; }
  .menu-btn .who, .menu-btn .menu-caret { display: none; }
  .menu-btn .ham-icon { display: inline; }
  .menu-mobile-only { display: block; }
}

main { max-width: 1400px; margin: 0 auto; padding: 18px; }

/* buttons */
button { font-family: inherit; }
.btn { background: var(--green); color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.btn:hover { background: var(--green-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-plain { background: none; border: 1px solid var(--border); color: var(--text); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.btn-plain:hover { background: #f0f2f4; }
.btn-danger { background: var(--danger); color: #fff; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.btn-danger:hover { filter: brightness(.92); }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 2px 4px; }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number],
select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfe3cc; border-color: var(--green); }
/* 参照モード（disabled）でも文字が読みやすいように */
input:disabled, select:disabled, textarea:disabled { background: #f6f7f8; color: var(--text); opacity: 1; -webkit-text-fill-color: var(--text); cursor: default; }

/* panels / cards */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #eef2f5; color: var(--muted); }

/* login */
.login-wrap { max-width: 400px; margin: 8vh auto; }
.login-wrap .card { padding: 28px; }
.login-title { text-align: center; font-size: 20px; color: var(--green); font-weight: 700; margin-bottom: 6px; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.login-help { text-align: center; margin: 14px 0 0; font-size: 13px; }
.login-help a { color: var(--accent); text-decoration: none; }
.login-help a:hover { text-decoration: underline; }

/* project list */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); gap: 14px; }
.proj-card { cursor: pointer; transition: box-shadow .15s; }
.proj-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,.12); }
.proj-card h3 { margin: 0 0 6px; font-size: 15px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: none; padding: 10px 16px; cursor: pointer; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabs button.active { color: var(--green-dark); border-bottom-color: var(--green); font-weight: 600; }
.tab-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); margin-left: 6px; vertical-align: middle; }

/* messages（グループチャット） */
.msg-search { margin-bottom: 10px; }
.chat-scroll { height: 56vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.chat-msg { max-width: 78%; display: flex; flex-direction: column; align-items: flex-start; }
.chat-msg.me { align-self: flex-end; align-items: flex-end; }
.chat-name { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.chat-bubble { background: #eef1f4; padding: 8px 12px; border-radius: 12px; }
.chat-msg.me .chat-bubble { background: #d9f0e3; }
.chat-text { white-space: pre-wrap; word-break: break-word; }
.chat-meta { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; }
.chat-read { color: var(--green-dark); }
.chat-img { max-width: 220px; max-height: 220px; border-radius: 8px; margin-top: 4px; cursor: pointer; display: block; }
.chat-file { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.chat-file-name { word-break: break-all; }
.chat-composer { margin-top: 10px; }
.chat-composer-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input { flex: 1; min-height: 42px; resize: vertical; }
.chat-attach-btn { display: inline-flex; align-items: center; gap: 4px; }
.chat-file-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 8px; background: #eef6f0; border: 1px solid #bfe3cc; border-radius: 8px; }
.chip-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; }
.chip-icon { font-size: 24px; flex: 0 0 auto; line-height: 1; }
.chip-name { font-weight: 600; word-break: break-all; flex: 1; }
.chip-size { color: var(--muted); font-size: 12px; flex: 0 0 auto; white-space: nowrap; }
.chip-remove { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--muted); line-height: 1; padding: 0 4px; flex: 0 0 auto; }
.chip-remove:hover { color: var(--danger); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; }

/* notes layout (karte-like) */
.notes-layout { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
.notes-list { max-height: 72vh; overflow-y: auto; }
.note-item { border-left: 4px solid var(--green); background: #fff; border: 1px solid var(--border); border-left-width: 4px; border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.note-item:hover { background: #f8fbf9; }
.note-item.active { background: #eef6f0; }
.note-item .meta { font-size: 12px; color: var(--muted); }
.note-item .ttl { font-size: 13px; margin-top: 2px; }
.kind-tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; color: #fff; }

/* gantt */
.gantt-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.gantt-scroll { overflow: auto; max-height: 62vh; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.gantt { position: relative; font-size: 12px; }
.gantt-row { display: flex; align-items: stretch; border-bottom: 1px solid #eef1f4; }
.gantt-row:hover { background: #fafbfc; }
.gantt-label { flex: 0 0 220px; padding: 6px 10px; border-right: 1px solid var(--border); position: sticky; left: 0; background: #fff; z-index: 2; display: flex; align-items: center; gap: 4px; }
.gantt-reorder-handle { cursor: grab; color: var(--muted); user-select: none; font-size: 14px; flex: 0 0 auto; }
.gantt-row[draggable="true"] .gantt-label { cursor: grab; }
.gantt-row.row-dragging { opacity: .4; }
.gantt-label .assignee { font-size: 11px; color: var(--muted); }
.gantt-track { position: relative; flex: 1; min-height: 34px; }
.gantt-bar { position: absolute; top: 6px; height: 20px; border-radius: 4px; background: var(--green); color: #fff; font-size: 11px; padding: 0 6px; line-height: 20px; white-space: nowrap; overflow: hidden; cursor: pointer; }
.gantt-bar .prog { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(0,0,0,.18); border-radius: 4px 0 0 4px; }
.gantt-bar.draggable { cursor: grab; touch-action: none; user-select: none; }
.gantt-handle { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; z-index: 3; border-radius: 4px; }
.gantt-handle-l { left: 0; }
.gantt-handle-r { right: 0; }
.gantt-bar.draggable:hover .gantt-handle { background: rgba(255,255,255,.4); }
.gantt-today { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(214,69,69,.8); z-index: 4; pointer-events: none; }
.gantt-today-flag { position: absolute; top: 0; left: -7px; font-size: 15px; line-height: 1; pointer-events: none; z-index: 5; }
.gantt-head { display: block; border-bottom: 2px solid var(--border); position: sticky; top: 0; background: #fff; z-index: 3; }
.gantt-head .gantt-label { font-weight: 600; color: var(--muted); }
.gantt-head-row { display: flex; }
.gantt-head-spacer { position: sticky; left: 0; z-index: 2; background: #fff; border-right: 1px solid var(--border); padding: 2px 8px; font-size: 11px; color: var(--muted); display: flex; align-items: flex-end; }
.gantt-hseg { border-right: 1px solid var(--border); font-size: 11px; color: var(--muted); padding: 2px 0; white-space: nowrap; }
.gantt-hseg-label { position: sticky; display: inline-block; padding: 0 8px; background: #fff; font-weight: 600; }
.gantt-hday { display: flex; flex-direction: column; align-items: center; line-height: 1.15; padding: 2px 0; }
.gantt-hday .d-n { font-size: 11px; }
.gantt-hday .d-w { font-size: 10px; opacity: .85; }
.gantt-head-cells { display: flex; flex: 1; }
.gantt-hcell { border-right: 1px solid #eef1f4; text-align: center; padding: 4px 2px; color: var(--muted); }

/* toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #232b33; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); }

/* modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 4vh 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; max-width: 640px; width: 100%; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal.wide { max-width: 900px; }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* stakeholder cards */
.stk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr)); gap: 12px; }
.stk-card .name { font-weight: 600; }
.stk-card .contact a { color: var(--accent); text-decoration: none; }
.stk-card .contact a:hover { text-decoration: underline; }
.stk-note { color: var(--muted); font-size: 13px; margin-top: 6px; white-space: pre-wrap; }

/* preview */
.preview-frame { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.preview-table-wrap { max-height: 70vh; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.preview-table-wrap table td, .preview-table-wrap table th { white-space: nowrap; }
.docx-wrap { max-height: 70vh; overflow: auto; padding: 20px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* 工程表：関所ロードマップ */
.road { display: flex; align-items: flex-start; overflow-x: auto; padding: 6px 4px 0; position: relative; }
.road::before { content: ''; position: absolute; left: 24px; right: 24px; top: 30px; height: 2px; background: var(--border); }
.road-node { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; min-width: 100px; flex: 0 0 auto; text-align: center; cursor: pointer; }
.road-node.faded { opacity: .5; }
.road-hub { height: 48px; display: flex; align-items: center; justify-content: center; }
.road-c { border-radius: 50%; display: flex; align-items: center; justify-content: center; background: #fff; font-size: 12px; }
.road-c-phase { width: 30px; height: 30px; border: 2px solid var(--green); color: var(--green-dark); font-weight: 600; }
.road-node:hover .road-c-phase { background: #eef6f0; }
.road-c-gate-near { width: 46px; height: 46px; border: 2px solid var(--danger); background: #fdeaea; color: var(--danger); font-size: 20px; }
.road-c-gate-far { width: 24px; height: 24px; border: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.road-lbl { font-size: 12px; color: var(--text); margin-top: 4px; line-height: 1.3; max-width: 116px; }
.road-lbl.gate { color: var(--muted); }
.road-lbl.gate.near { color: var(--danger); font-weight: 600; }
.road-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.road-sub.red { color: var(--danger); }
.gate-callout { margin-top: 14px; background: #fdeaea; border: 1.5px solid var(--danger); border-radius: 10px; padding: 12px 14px; }
.gc-title { font-size: 14px; font-weight: 600; color: var(--danger); }
.gc-desc { font-size: 12px; color: #a33; line-height: 1.6; margin-top: 4px; }

/* drag & drop 並び替え */
.draggable-item { cursor: grab; }
.draggable-item.dragging { opacity: .45; }
.drag-handle { cursor: grab; color: var(--muted); margin-right: 2px; user-select: none; font-size: 14px; }
.stk-card.draggable-item, .checklist-item.draggable-item { position: relative; }
.drag-hint { color: var(--muted); font-size: 12px; margin-bottom: 8px; }

/* checklist */
.checklist-section { font-weight: 700; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 8px; }
.checklist-item { display: flex; align-items: center; gap: 8px; padding: 6px 2px; border-bottom: 1px solid #f0f2f4; }
.checklist-item:last-child { border-bottom: none; }
.checklist-item input[type=checkbox] { width: 18px; height: 18px; flex: 0 0 auto; cursor: pointer; }
.checklist-text { flex: 0 1 auto; }
.checklist-text.done { text-decoration: line-through; color: var(--muted); }

/* wiki */
.wiki-content { line-height: 1.8; margin-top: 12px; word-break: break-word; }
.wiki-content h1, .wiki-content h2, .wiki-content h3 { margin: 18px 0 8px; line-height: 1.4; }
.wiki-content .wiki-h1 { font-size: 20px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.wiki-content .wiki-h2 { font-size: 17px; }
.wiki-content .wiki-h3 { font-size: 15px; }
.wiki-content p { margin: 8px 0; }
.wiki-content ul, .wiki-content ol { margin: 8px 0; padding-left: 24px; }
.wiki-content code { background: #eef1f4; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.wiki-content pre.wiki-code { background: #1e2733; color: #e6edf3; padding: 12px 14px; border-radius: 6px; overflow-x: auto; }
.wiki-content pre.wiki-code code { background: none; color: inherit; padding: 0; }
.wiki-content blockquote { border-left: 3px solid var(--green); margin: 8px 0; padding: 2px 12px; color: var(--muted); background: #f7faf8; }
.wiki-content hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.wiki-content a { color: var(--accent); }
.wiki-content a.wikilink { color: var(--green-dark); font-weight: 600; text-decoration: none; border-bottom: 1px dashed var(--green); }
.wiki-content a.wikilink:hover { background: #eef6f0; }
.wiki-content .md-table-wrap { overflow-x: auto; margin: 10px 0; }
.wiki-content .md-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.wiki-content .md-table th, .wiki-content .md-table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.wiki-content .md-table th { background: #f4f6f8; font-weight: 600; white-space: nowrap; }

@media (max-width: 820px) {
  .notes-layout { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .gantt-label { flex-basis: 140px; }
}

/* スマホ向け：メッセージの見やすさ・操作性 */
@media (max-width: 600px) {
  main { padding: 12px; }
  /* タブは折り返さず横スクロールで全タブに届くように */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs button { white-space: nowrap; padding: 10px 12px; }
  .chat-scroll { height: 62vh; padding: 8px; }
  .chat-msg { max-width: 88%; }
  .chat-bubble { padding: 8px 11px; }
  .chat-img { max-width: 68vw; max-height: 260px; }
  /* 入力欄：テキストは1行占有、下に［添付］［送信］を大きく並べる */
  .chat-composer-row { flex-wrap: wrap; }
  .chat-input { flex: 1 1 100%; min-height: 48px; font-size: 16px; } /* iOSズーム防止に16px */
  .chat-attach-btn { flex: 1 1 40%; justify-content: center; min-height: 44px; }
  .chat-composer-row .btn { flex: 1 1 40%; min-height: 44px; }
  .msg-search { flex-wrap: wrap; }
  .msg-search input { flex: 1 1 100%; min-height: 44px; font-size: 16px; }
  .msg-search button { flex: 1 1 auto; min-height: 40px; }
  .chip-thumb { width: 44px; height: 44px; }
  /* プレビュー：スマホでは余白を詰めて画面いっぱいに */
  .modal-overlay { padding: 8px; }
  .modal, .modal.wide { padding: 12px; border-radius: 8px; max-width: 100%; }
  .preview-frame { height: 62vh; }
  .docx-wrap, .preview-table-wrap { max-height: 66vh; }
}
