:root {
  --ink: #1f2328;
  --ink2: #57606a;
  --ink3: #6b7178;
  --brand: #0f766e;
  --brand2: #115e59;
  --brand-bg: #e6f4f1;
  --surface: #faf9f6;
  --card: #ffffff;
  --line: #e8e6e1;
  --line2: #d0cdc6;
  --won: #1f6b52;
  --won-bg: #e3f3ea;
  --lost: #6b7280;
  --alert: #b93a30;
  --alert-bg: #fbeceb;
  --warn: #8f5a12;
  --warn-bg: #fdf3e2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(31, 35, 40, .05), 0 2px 8px rgba(31, 35, 40, .04);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.7;
}
body { min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.4; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h1:focus { outline: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { top: 8px; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--ink2); }
.small { font-size: 12px; }

/* 体験版の帯 */
.demo-bar {
  background: #123c38; color: #f2fbf9;
  font-size: 12px; line-height: 1.5;
  padding: 5px 16px;
  display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap;
}
.demo-bar p { margin: 0; }
.demo-bar a { color: #fff; font-weight: 700; white-space: nowrap; }

/* 上部メニュー */
.top { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); }
.top-inner { max-width: 1400px; margin: 0 auto; padding: 0 24px; min-height: 56px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; }
.brand-name { font-weight: 800; letter-spacing: .06em; font-size: 15px; display: flex; align-items: baseline; gap: 6px; }
.brand-name small { font-size: 11px; font-weight: 500; color: var(--ink2); letter-spacing: .1em; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; color: var(--ink2); padding: 6px 14px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.nav a:hover { background: var(--brand-bg); color: var(--brand2); }
.nav a[aria-current="page"] { background: var(--brand); color: #fff; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search-btn {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line2); background: var(--surface); border-radius: 999px;
  padding: 6px 8px 6px 12px; min-width: 200px; color: var(--ink2);
}
.search-btn:hover { border-color: var(--brand); }
.search-label { flex: 1; text-align: left; }
kbd { font-family: inherit; font-size: 11px; background: #fff; border: 1px solid var(--line2); border-radius: 6px; padding: 0 6px; color: var(--ink2); }

/* ボタン・入力 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  border-radius: 999px; padding: 6px 14px; font-weight: 600;
  border: 1px solid var(--line2); background: var(--card); color: var(--ink);
  white-space: nowrap; text-decoration: none; line-height: 1.5;
}
.btn:hover { background: var(--brand-bg); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand2); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink2); }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.input {
  width: 100%; border: 1px solid var(--line2); border-radius: 10px; background: var(--card);
  padding: 7px 10px; min-height: 36px;
}
.input:focus { border-color: var(--brand); }
textarea.input { resize: vertical; min-height: 72px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink2); }
label > .input { font-weight: 400; color: var(--ink); font-size: 14px; }

/* 本体 */
.main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 24px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 2px 0 0; color: var(--ink2); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head a { font-size: 12px; font-weight: 600; }
.grid-home { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-home .wide { grid-column: 1 / -1; }
.grid-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }

.tips { background: var(--brand-bg); border: 1px solid #c4e4dd; border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; position: relative; }
.tips h2 { color: var(--brand2); margin-bottom: 6px; }
.tips ul { margin: 0; padding-left: 1.2em; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 2px 20px; }
.tips .close { position: absolute; top: 10px; right: 10px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.empty { color: var(--ink2); padding: 12px 0; margin: 0; }
.time { font-weight: 700; color: var(--brand2); min-width: 48px; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: #f0eeea; color: var(--ink2); white-space: nowrap; }
.badge.alert { background: var(--alert-bg); color: var(--alert); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.won { background: var(--won-bg); color: var(--won); }
.badge.brand { background: var(--brand-bg); color: var(--brand2); }
.av { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 700; flex-shrink: 0; vertical-align: middle; }

/* 数字とグラフ */
.big { font-size: 30px; font-weight: 800; letter-spacing: .01em; }
.big small { font-size: 14px; font-weight: 600; color: var(--ink2); margin-left: 4px; }
.meter { height: 14px; background: #efede8; border-radius: 999px; overflow: hidden; display: flex; margin: 10px 0 8px; }
.meter span { display: block; height: 100%; }
.meter .m-won { background: var(--brand); }
.meter .m-wt { background: repeating-linear-gradient(45deg, #7cc7bb, #7cc7bb 6px, #9dd6cc 6px, #9dd6cc 12px); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 48px minmax(0, 1fr) 120px; gap: 10px; align-items: center; }
.bar-track { height: 18px; background: #f3f1ed; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--brand); min-width: 2px; }
.bar-fill.won { background: var(--won); }
.bar-fill.lost { background: #b8bcc2; }
.bar-val { text-align: right; font-size: 12px; color: var(--ink2); }
.bar-val b { color: var(--ink); font-size: 14px; }

/* 一覧の道具 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.toolbar .q { flex: 1 1 240px; }
.toolbar label { min-width: 120px; }
.count { color: var(--ink2); margin: 0 0 8px; font-size: 13px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: #efede8; padding: 3px; border-radius: 999px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-weight: 600; color: var(--ink2); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--brand2); box-shadow: var(--shadow); }

/* 表 */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--ink2); font-weight: 700; background: #fbfaf8; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfbf9; }
th button { border: 0; background: none; font-weight: 700; color: inherit; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
th button:hover { color: var(--brand); }
.cell-input { border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 4px 6px; width: 100%; min-width: 90px; }
.cell-input:hover { border-color: var(--line2); background: #fff; }
.cell-input:focus { border-color: var(--brand); background: #fff; }
select.cell-input { cursor: pointer; }
.co-link { font-weight: 700; text-decoration: none; color: var(--ink); }
.co-link:hover { color: var(--brand); text-decoration: underline; }
.edit-hint { font-size: 12px; color: var(--ink2); margin: 0 0 8px; }

/* 詳細 */
.dl { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dl .full { grid-column: 1 / -1; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 26px; }
.timeline li::before { content: ""; position: absolute; left: 8px; top: 22px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.tl-dot { position: absolute; left: 0; top: 4px; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; color: #fff; font-weight: 700; }
.tl-dot.t-call { background: #2563eb; }
.tl-dot.t-visit { background: var(--brand); }
.tl-dot.t-memo { background: #8f5a12; }
.tl-meta { font-size: 12px; color: var(--ink2); }
.tl-body { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.act-form { display: grid; grid-template-columns: 120px 150px minmax(0, 1fr); gap: 8px; align-items: end; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.act-form .full { grid-column: 1 / -1; }
.act-form .end { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.deal-row { width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.deal-row:hover { border-color: var(--brand); }
.deal-rows { display: grid; gap: 6px; }

/* カンバン */
.board-wrap { overflow-x: auto; padding-bottom: 6px; }
.board { display: grid; grid-template-columns: repeat(6, minmax(210px, 1fr)); gap: 12px; min-width: 1320px; }
.col { background: #f2f0ec; border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; min-width: 0; }
.col-head { padding: 2px 4px 8px; }
.col-head h2 { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.col-total { font-size: 12px; color: var(--ink2); }
.col-total b { color: var(--ink); font-size: 15px; }
.col-body { flex: 1; display: grid; gap: 8px; align-content: start; min-height: 80px; border-radius: 12px; padding: 2px; transition: background-color 80ms; }
.col-body.over { background: var(--brand-bg); outline: 2px dashed var(--brand); }
.col[data-stage="won"] { background: #e7f2ec; }
.col[data-stage="lost"] { background: #eeeff1; }
.deal-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; box-shadow: var(--shadow); cursor: grab; }
.deal-card.dragging { opacity: .45; }
.deal-card .open { all: unset; display: block; cursor: pointer; width: 100%; border-radius: 6px; }
.deal-card .open:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.dc-title { font-weight: 700; line-height: 1.45; overflow-wrap: anywhere; }
.dc-co { font-size: 12px; color: var(--ink2); }
.dc-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 6px; }
.dc-amt { font-weight: 800; }
.dc-move { display: flex; gap: 4px; margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }
.dc-move button { flex: 1; font-size: 12px; padding: 3px 6px; }
.dc-move button:disabled { opacity: .35; cursor: default; background: #fff; }
.late { color: var(--alert); font-weight: 700; }

/* タスク */
.task-list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.task-list li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 11px 16px; border-top: 1px solid var(--line); }
.task-list li:first-child { border-top: 0; }
.task-list li.overdue { background: #fff7f6; box-shadow: inset 4px 0 0 var(--alert); }
.task-list li.done .t-title { text-decoration: line-through; color: var(--ink3); }
.task-list input[type="checkbox"], .list input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brand); cursor: pointer; margin: 0; }
.t-title { font-weight: 600; overflow-wrap: anywhere; }
.t-sub { font-size: 12px; color: var(--ink2); }
.t-right { display: flex; align-items: center; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.task-form { display: grid; grid-template-columns: minmax(0, 2fr) 150px 140px minmax(0, 1.4fr) auto; gap: 8px; align-items: end; margin-bottom: 14px; }

/* ダイアログ */
dialog { border: 0; border-radius: 18px; padding: 0; width: calc(100vw - 32px); max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--ink); }
dialog::backdrop { background: rgba(20, 30, 28, .45); }
.dlg { padding: 20px 22px; }
.dlg h2 { font-size: 17px; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.palette { max-width: 620px; margin-top: 10vh; }
.pal-box { padding: 10px; }
.pal-input { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 12px 10px; font-size: 16px; outline: none; }
.pal-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.pal-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.pal-list li[aria-selected="true"] { background: var(--brand-bg); box-shadow: inset 3px 0 0 var(--brand); }
.pal-list .pk { font-size: 11px; font-weight: 700; color: var(--brand2); background: #fff; border: 1px solid #c4e4dd; border-radius: 999px; padding: 0 8px; flex-shrink: 0; }
.pal-list .pt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-list .ps { font-size: 12px; color: var(--ink2); flex-shrink: 0; }
.pal-help { margin: 6px 10px 2px; font-size: 12px; color: var(--ink2); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #1f2b29; color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.foot { text-align: center; font-size: 12px; color: var(--ink2); padding: 16px; }
.foot p { margin: 0; }
.noscript { padding: 20px; text-align: center; }

/* タブレット */
@media (max-width: 1024px) {
  .search-btn { min-width: 0; }
  .search-kbd, .reset-label { display: none; }
  .grid-detail { grid-template-columns: 1fr; }
  .task-form { grid-template-columns: 1fr 1fr; }
  .task-form .full { grid-column: 1 / -1; }
}

/* スマホ */
@media (max-width: 720px) {
  .top-inner { flex-wrap: wrap; padding: 6px 16px 0; gap: 8px; min-height: 0; }
  .nav { order: 3; width: 100%; justify-content: space-between; padding-bottom: 6px; }
  .nav a { padding: 6px 12px; flex: 1; text-align: center; }
  .search-label { display: none; }
  .search-btn { padding: 8px; border-radius: 50%; }
  .main { padding: 16px; }
  h1 { font-size: 19px; }
  .grid-home { grid-template-columns: 1fr; }
  .card { padding: 14px 16px; }
  .bar-row { grid-template-columns: 40px minmax(0, 1fr) 96px; gap: 6px; }
  .dl, .form-grid { grid-template-columns: 1fr; }
  .act-form { grid-template-columns: 1fr 1fr; }
  .task-form { grid-template-columns: 1fr; }
  .toolbar label { flex: 1 1 140px; min-width: 0; }

  /* 表をカード表示に切り替え */
  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .resp thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .resp, .resp tbody, .resp tr, .resp td { display: block; width: 100%; }
  .resp tr { background: #fff; border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; padding: 8px 12px; box-shadow: var(--shadow); }
  .resp td { border: 0; padding: 4px 0; display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; align-items: center; }
  .resp td::before { content: attr(data-label); font-size: 12px; color: var(--ink2); font-weight: 600; }
  .resp td.td-name { display: block; padding-bottom: 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
  .resp td.td-name::before { display: none; }
  .sort-mobile { display: flex !important; }

  /* カンバンは縦に並べる */
  .board-wrap { overflow: visible; }
  .board { grid-template-columns: 1fr; min-width: 0; }
  .task-list li { grid-template-columns: 28px minmax(0, 1fr); }
  .t-right { grid-column: 2; justify-content: flex-start; }
}
.sort-mobile { display: none; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
