:root {
  --bg: #f5f6f9;
  --panel: #ffffff;
  --panel-2: #f2f4f8;
  --line: #dfe3ec;
  --line-strong: #c7cddb;
  --navy: #2b3348;
  --navy-2: #3c465f;
  --text: #1d2233;
  --sub: #4b5266;
  --muted: #7a8199;
  --accent: #3b62d9;
  --accent-soft: #eaeffc;
  --ok: #12855a;
  --done: #8b93a7;
  --ng: #d33049;
  --warn: #b7791f;
  --radius: 10px;
  font-family: "Yu Gothic UI", "Meiryo", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
}

a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------------- ヘッダー ---------------- */
header.top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 20px;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
header.top h1 { font-size: 16px; margin: 0; letter-spacing: .04em; font-weight: 700; }
header.top .spacer { flex: 1; }
header.top .who { font-size: 13px; color: #cfd5e4; }
header.top button {
  background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.28); color: #fff;
}
header.top button:hover { background: rgba(255,255,255,.22); }

nav.tabs { display: flex; gap: 2px; background: var(--navy); padding: 0 14px; }
nav.tabs button {
  background: transparent; border: none; border-radius: 0; color: #b9c1d4;
  padding: 9px 18px; font-weight: 700; font-size: 13.5px; letter-spacing: .04em;
  border-bottom: 3px solid transparent;
}
nav.tabs button:hover { background: rgba(255,255,255,.07); color: #fff; }
nav.tabs button.active { color: #fff; border-bottom-color: #7ea2ff; background: rgba(255,255,255,.07); }

main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 80px; }

.notice {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--sub);
  background: #fdf5e4;
  border: 1px solid #f0d9a8;
  border-radius: 8px;
  padding: 5px 12px;
  display: inline-block;
}

/* ---------------- ボタン ---------------- */
button, .btn {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { background: var(--panel-2); border-color: #a9b3c9; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
button.primary:hover { background: #2f52c0; border-color: #2f52c0; }
button.danger { color: var(--ng); border-color: #f0bcc4; }
button.danger:hover { background: #fdeef0; border-color: #e59aa6; }
button.small { padding: 3px 9px; font-size: 12px; }
button.link { border: none; background: none; color: var(--accent); padding: 2px 4px; }
button.link:hover { background: none; text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- フォーム ---------------- */
input, select, textarea {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 100px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 700; }
.field { margin-bottom: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

/* ---------------- ツールバー ---------------- */
.toolbar {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 16px;
}
.toolbar .f { min-width: 130px; }
.toolbar .f label { margin-bottom: 3px; }
.toolbar .grow { flex: 1; }
.toolbar select, .toolbar input { padding: 6px 9px; }

/* ---------------- 設定 ---------------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px;
}
.panel h2 { font-size: 15px; margin: 0 0 4px; }
.panel .hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; color: var(--muted); font-weight: 700; }
td.actions { text-align: right; white-space: nowrap; }
tr.off td { color: var(--muted); background: #fafbfc; }

/* ---------------- モーダル ---------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(20,25,40,.5);
  display: flex; align-items: flex-start; justify-content: center; padding: 30px 14px;
  overflow: auto; z-index: 60;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 560px;
  padding: 20px 22px; box-shadow: 0 12px 40px rgba(20,25,40,.28);
}
.modal h2 { margin: 0 0 14px; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.modal-actions .left { margin-right: auto; }

.msg { padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.msg.error { background: #fdeef0; border: 1px solid #f0bcc4; color: #a01f33; }
.msg.ok { background: #e8f6ef; border: 1px solid #a8dcc4; color: #0d6b49; }

/* ---------------- ログイン ---------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--navy); }
.login-box { background: #fff; border-radius: 12px; padding: 28px 26px; width: 100%; max-width: 380px; box-shadow: 0 14px 44px rgba(0,0,0,.3); }
.login-box h1 { font-size: 18px; margin: 0 0 4px; }
.login-box .sub { font-size: 12.5px; color: var(--muted); margin-bottom: 18px; }

.tag {
  display: inline-block; font-size: 11px; font-weight: 700; line-height: 1.5;
  padding: 0 8px; border-radius: 999px; background: var(--panel-2); color: var(--sub); white-space: nowrap;
}
.tag.plan5 { background: #eaeffc; color: #3b62d9; }
.tag.plan15 { background: #f4eafd; color: #7c3fc9; }
.tag.ended { background: #eceef2; color: var(--muted); }
.tag.warn { background: #fde8d4; color: #b4530f; }
.empty { text-align: center; color: var(--muted); padding: 44px 10px; }

/* ---------------- 集計タイル ---------------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px;
}
.stat .k { font-size: 11.5px; color: var(--muted); font-weight: 700; }
.stat .v { font-size: 22px; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.stat .d { font-size: 11.5px; color: var(--muted); }
.stat.alert .v { color: #c2410c; }

/* ---------------- 一覧（年×月のマス） ---------------- */
.listbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.listbar .spacer { flex: 1; }
.yearnav { display: flex; align-items: center; gap: 8px; }
.yearnav strong { font-size: 16px; min-width: 64px; text-align: center; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--sub); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend .cell { width: 14px; height: 14px; min-width: 0; padding: 0; border-radius: 3px; display: inline-block; }

.tablewrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow-x: auto;
}
table.matrix { min-width: 980px; }
table.matrix th, table.matrix td { padding: 6px 6px; }
table.matrix th.m { text-align: center; width: 44px; }
table.matrix th.m.now { color: var(--accent); }
table.matrix td.name { min-width: 170px; position: sticky; left: 0; background: var(--panel); z-index: 1; }
table.matrix tr:hover td { background: #fafbfd; }
table.matrix tr.ended td.name .nm { color: var(--muted); }
table.matrix td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.matrix td.mc { text-align: center; padding: 4px 2px; }
.nm { font-weight: 700; cursor: pointer; color: var(--text); background: none; border: none; padding: 0; text-align: left; }
.nm:hover { color: var(--accent); background: none; text-decoration: underline; }
.subline { font-size: 11px; color: var(--muted); display: flex; gap: 5px; flex-wrap: wrap; align-items: center; margin-top: 1px; }
.remain-big { font-weight: 700; font-size: 14px; }
.remain-big.zero { color: var(--muted); font-weight: 400; }

.cell {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; height: 26px; padding: 0 3px; border-radius: 6px;
  font-size: 11.5px; font-weight: 700; border: 1px solid transparent; cursor: pointer;
  font-variant-numeric: tabular-nums; line-height: 1;
}
button.cell:hover { filter: brightness(.95); }
.cell.s-unused  { background: #fbd9a8; border-color: #e7a84d; color: #7a3d00; }
.cell.s-partial { background: linear-gradient(135deg, #fbd9a8 50%, #cfeedd 50%); border-color: #d4b276; color: #6b3a05; }
.cell.s-used    { background: #d6f0e2; border-color: #9fd3b7; color: #1b7048; }
.cell.s-skip    { background: repeating-linear-gradient(45deg, #eef0f4 0 4px, #e2e5ec 4px 8px); border-color: #d3d8e2; color: #8b93a7; }
.cell.s-none    { background: none; color: #c9ced9; cursor: default; font-weight: 400; }
.cell.s-future  { background: none; border: 1px dashed #dde1ea; color: #c9ced9; cursor: default; font-weight: 400; }

.foot-hint { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }

/* ---------------- 詳細 ---------------- */
.modal.wide { max-width: 820px; }
.detail-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: -6px 0 12px; font-size: 12.5px; color: var(--sub); }
.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.mini-stats .stat { padding: 8px 11px; }
.mini-stats .stat .v { font-size: 18px; }
.yeargrid { width: 100%; margin-bottom: 14px; }
.yeargrid th, .yeargrid td { padding: 3px 2px; border: none; text-align: center; }
.yeargrid th.y { text-align: left; font-size: 12.5px; color: var(--sub); width: 52px; }
.yeargrid .cell { min-width: 0; width: 100%; max-width: 50px; }
h3.sec { font-size: 13.5px; margin: 16px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
h3.sec .spacer { flex: 1; }
.memo-box { background: var(--panel-2); border-radius: 8px; padding: 8px 11px; white-space: pre-wrap; word-break: break-word; font-size: 13px; color: var(--sub); }

.call-row {
  display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap;
  padding: 8px 4px; border-bottom: 1px solid var(--line);
}
.call-row:last-child { border-bottom: none; }
.call-row .dt { font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 92px; font-weight: 700; }
.call-row .mn { white-space: nowrap; min-width: 52px; font-weight: 700; text-align: right; }
.call-row .body { flex: 1; min-width: 180px; }
.call-row .alloc { font-size: 12px; color: var(--sub); }
.call-row .memo { font-size: 12.5px; color: var(--sub); white-space: pre-wrap; word-break: break-word; }
.call-row .by { font-size: 11px; color: var(--muted); }
.call-row .who { font-weight: 700; }
.over { color: var(--ng); font-weight: 700; }
.list-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 12px; }
.month-head { font-size: 13px; font-weight: 700; color: var(--sub); margin: 14px 2px 6px; }

.preview {
  background: var(--panel-2); border-radius: 8px; padding: 9px 12px; font-size: 12.5px; color: var(--sub);
}
.preview .hl { color: var(--text); font-weight: 700; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.radio-list label {
  display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: var(--text); font-weight: 400;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; cursor: pointer;
}
.radio-list label:hover { background: var(--panel-2); }
.radio-list input { width: auto; }
.pw-box { font-family: Consolas, monospace; font-size: 16px; background: var(--panel-2); padding: 8px 12px; border-radius: 8px; user-select: all; }

/* ---------------- スマホ ---------------- */
@media (max-width: 700px) {
  header.top { padding: 10px 12px; gap: 8px; }
  header.top h1 { font-size: 14px; }
  nav.tabs { padding: 0 4px; }
  nav.tabs button { flex: 1; padding: 9px 6px; font-size: 12.5px; }
  main { padding: 14px 10px 70px; }
  .stats, .mini-stats { grid-template-columns: repeat(2, 1fr); }
  .toolbar { padding: 10px; }
  .toolbar .f { min-width: calc(50% - 5px); }
  .row > * { min-width: 100%; }
  table { font-size: 12px; }
  th, td { padding: 6px 4px; }
  table.matrix td.name { min-width: 128px; }
  .modal { padding: 16px 14px; }
  .yeargrid .cell { font-size: 10.5px; height: 24px; }
}
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
