/* 教務手帳 — スマホ優先。1本のCSSで完結させる（ビルド工程を持たない） */

:root {
  --bg: #f4f4f0;
  --surface: #ffffff;
  --surface-2: #fafaf7;
  --ink: #1b1d22;
  --muted: #6b7078;
  --line: #e2e2da;
  --accent: #1d3f5e;      /* 藍 */
  --accent-soft: #e7eef5;
  --warn: #b8442a;        /* 朱＝期限ぎれ・最優先 */
  --warn-soft: #fbeae5;
  --ok: #2c7a5b;
  --hi: #b07d1a;          /* 高 */
  --r: 12px;
  --pad: 16px;
  --tabh: 58px;
  --font: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #22262d;
    --ink: #e9e9e4;
    --muted: #9aa0a8;
    --line: #2c313a;
    --accent: #7fb3dd;
    --accent-soft: #1f2c3a;
    --warn: #e08469;
    --warn-soft: #38241f;
    --ok: #6cbf9a;
    --hi: #d8ad51;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-feature-settings: "palt";
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { font-size: 15px; line-height: 1.6; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

[hidden] { display: none !important; }

/* ---------- ログイン ---------- */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--accent) 0%, #0f2437 100%);
}
.login-box {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 22px 24px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .28);
}
.login-box h1 { margin: 12px 0 2px; font-size: 1.3rem; letter-spacing: .04em; }
.login-box .sub { margin: 0 0 18px; color: var(--muted); font-size: .85rem; }
.login-box input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
}
.mark {
  width: 46px; height: 46px; margin: 0 auto; border-radius: 12px;
  background: var(--accent);
  position: relative;
}
.mark::before, .mark::after {
  content: ""; position: absolute; left: 10px; right: 10px; height: 3px; border-radius: 2px;
  background: #fff; opacity: .9;
}
.mark::before { top: 16px; }
.mark::after { top: 26px; right: 20px; }

/* ---------- 骨格 ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(env(safe-area-inset-top), 8px) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 1.15rem; letter-spacing: .03em; }
.top-right { display: flex; align-items: center; gap: 8px; }
.icon {
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
}
.icon:active { background: var(--line); }

.view {
  max-width: 720px; margin: 0 auto;
  padding: 14px var(--pad) calc(var(--tabh) + env(safe-area-inset-bottom) + 84px);
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  height: var(--tabh); font-size: .72rem; letter-spacing: .02em;
  border-top: 2px solid transparent;
}
.tabs button.on { color: var(--accent); border-top-color: var(--accent); font-weight: 700; }

.fab {
  position: fixed; right: 18px; z-index: 31;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 28px; border: 0;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
.fab:active { transform: translateY(1px); }

/* ---------- 部品 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 14px;
}
.card > h2 {
  margin: 0; padding: 11px 14px;
  font-size: .82rem; letter-spacing: .06em; color: var(--muted);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.card > h2 .n { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }
.card.alert { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.card.alert > h2 { color: var(--warn); background: var(--warn-soft); border-bottom-color: color-mix(in srgb, var(--warn) 30%, var(--line)); }

.daybar {
  display: flex; align-items: baseline; gap: 10px;
  margin: 2px 0 14px;
}
.daybar .d { font-size: 1.6rem; font-weight: 700; letter-spacing: .02em; }
.daybar .s { color: var(--muted); font-size: .8rem; }

/* 一覧の行 */
.it {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
}
.card > h2 + .it, .list > .it:first-child { border-top: 0; }
.it .box {
  flex: 0 0 auto; width: 22px; height: 22px; margin-top: 1px;
  border: 2px solid var(--muted); border-radius: 6px;
  background: transparent; display: grid; place-items: center; padding: 0;
}
.it .box::after { content: "✓"; font-size: 14px; line-height: 1; color: #fff; opacity: 0; }
.it.done .box { background: var(--ok); border-color: var(--ok); }
.it.done .box::after { opacity: 1; }
.it .time {
  flex: 0 0 auto; width: 46px; text-align: right;
  font-variant-numeric: tabular-nums; font-size: .84rem; color: var(--accent); font-weight: 700;
  padding-top: 1px;
}
.it .body { flex: 1 1 auto; min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.it .t { display: block; word-break: break-word; }
.it.done .t { color: var(--muted); text-decoration: line-through; }
.it .meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.it .memo { display: block; color: var(--muted); font-size: .8rem; margin-top: 3px; white-space: pre-wrap; word-break: break-word; }
.it .p1 .t::before, .it .p2 .t::before { content: ""; }

.tag {
  display: inline-block; font-size: .7rem; line-height: 1.5; padding: 1px 7px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.tag.who { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 700; }
.tag.due { font-variant-numeric: tabular-nums; }
.tag.over { background: var(--warn-soft); border-color: transparent; color: var(--warn); font-weight: 700; }
.tag.pri1 { color: var(--hi); border-color: color-mix(in srgb, var(--hi) 45%, var(--line)); }
.tag.pri2 { background: var(--warn); border-color: var(--warn); color: #fff; font-weight: 700; }
.tag.rep { color: var(--muted); }

.pill { font-size: .7rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.pill.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }

.empty { padding: 22px 14px; text-align: center; color: var(--muted); font-size: .85rem; }
.note { color: var(--muted); font-size: .78rem; margin: 8px 2px 0; }
.err { color: var(--warn); font-size: .82rem; margin: 10px 2px 0; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 14px; font-size: .88rem;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.danger { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); background: transparent; }
.btn.wide { width: 100%; margin-top: 14px; }
.btn:active { transform: translateY(1px); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 12px 14px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: 5px 12px; font-size: .8rem; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.chip .x { margin-left: 6px; opacity: .6; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1 1 0; border: 0; background: var(--surface); color: var(--muted);
  padding: 9px 6px; font-size: .82rem; border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 700; }

/* ---------- カレンダー ---------- */
.calhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calhead .m { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.calhead .grp { display: flex; gap: 8px; }
.calhead button { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 6px 12px; font-size: .82rem; }
/* 1fr は minmax(auto,1fr)＝中身の最小幅より縮まない。予定名を nowrap で入れているので
   minmax(0,1fr) にしないと列が押し広げられ、overflow:hidden で右の数日が消える */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.cal .wd { background: var(--surface-2); text-align: center; font-size: .7rem; color: var(--muted); padding: 6px 0; }
.cal .wd.sun { color: var(--warn); }
.cal .wd.sat { color: var(--accent); }
.cal .cell {
  background: var(--surface); border: 0; min-height: 60px; min-width: 0; padding: 5px 4px 4px;
  display: flex; flex-direction: column; align-items: stretch; gap: 3px;
}
.cal .cell.out { background: var(--surface-2); opacity: .5; }
.cal .cell .dd { font-size: .78rem; font-variant-numeric: tabular-nums; text-align: left; color: var(--muted); }
.cal .cell.today .dd { background: var(--accent); color: #fff; border-radius: 999px; width: 20px; height: 20px; display: grid; place-items: center; font-weight: 700; }
.cal .cell.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal .cell .b {
  font-size: .62rem; line-height: 1.35; text-align: left;
  background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal .cell .b.task { background: var(--surface-2); color: var(--muted); }
.cal .cell .b.over { background: var(--warn-soft); color: var(--warn); }
.cal .cell .more { font-size: .6rem; color: var(--muted); text-align: left; }

/* ---------- 入力シート ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; }
.scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0;
  max-width: 720px; margin: 0 auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: .95rem; }
.link { border: 0; background: transparent; color: var(--accent); font-size: .88rem; padding: 6px 2px; }
.link.strong { font-weight: 700; }
.sheet-body { overflow-y: auto; padding: 14px 14px calc(env(safe-area-inset-bottom) + 26px); }

.fld { display: block; margin-bottom: 13px; }
.fld > span { display: block; font-size: .76rem; color: var(--muted); margin-bottom: 5px; letter-spacing: .04em; }
.fld > span i { font-style: normal; opacity: .8; }
.fld input[type=text], .fld input[type=date], .fld input[type=time], .fld select, .fld textarea {
  width: 100%; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
}
.fld textarea { resize: vertical; }
.fld .row { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.fld .row input[type=date], .fld .row input[type=time] { width: auto; flex: 1 1 120px; min-width: 0; }
.fld .row em { font-style: normal; color: var(--muted); }
.wdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.wdays button {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 8px; padding: 8px 0; font-size: .8rem;
}
.wdays button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.check { display: flex; align-items: center; gap: 8px; font-size: .86rem; margin: 4px 0 2px; }
.check input { width: 18px; height: 18px; }

/* ---------- 設定 ---------- */
.rrow { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-top: 1px solid var(--line); }
.card > h2 + .rrow { border-top: 0; }
.rrow .body { flex: 1 1 auto; min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.rrow .t { display: block; }
.rrow.off .t { color: var(--muted); text-decoration: line-through; }
.rrow .s { display: block; font-size: .76rem; color: var(--muted); margin-top: 2px; }
.addrow { display: flex; gap: 8px; padding: 0 14px 12px; }
.addrow input { flex: 1 1 auto; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.addrow button { flex: 0 0 auto; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 80;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 84px);
  background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: .82rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
  max-width: 88vw; text-align: center;
}

@media (min-width: 640px) {
  .cal .cell { min-height: 78px; }
}
