/* public/src/styles/base.css
 * 期限メモの土台となるスタイル。公開ページとアプリの両方が読み込む。
 *
 * 方針（仕様書 §9）
 *  - スマートフォンを基準に組み、広い画面で段組みを増やす
 *  - 状態を色だけで表さない。必ずアイコン・ラベル・文字を添える
 *  - キーボード操作で全機能に届く。フォーカスは常に見える
 *  - 動きは控えめ。prefers-reduced-motion を尊重する
 *  - ダークモードは MVP では作らない
 */

:root {
  --ink: #1b1d20;
  --ink-soft: #4a4f57;
  --ink-faint: #6b7280;
  --line: #dfe3e8;
  --line-strong: #c3c9d2;
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-sunken: #eef1f4;

  --brand: #1f5f4b;
  --brand-dark: #17493a;
  --brand-tint: #e8f2ee;

  /* 状態色。色だけに意味を持たせないので、彩度は控えめでよい */
  --state-expired: #9b1c1c;
  --state-expired-bg: #fdeaea;
  --state-today: #9a3412;
  --state-today-bg: #fdf0e6;
  --state-soon: #92620a;
  --state-soon-bg: #fdf6e3;
  --state-near: #1e4f7a;
  --state-near-bg: #e9f1f8;
  --state-ok: #2f6b4f;
  --state-ok-bg: #eaf3ee;
  --state-done: #4a4f57;
  --state-done-bg: #eef1f4;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);

  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP",
    "Yu Gothic", Meiryo, system-ui, -apple-system, sans-serif;

  --wrap: 62rem;
  --gap: 1rem;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  /* 16px 未満にしない。iOS で入力時に画面が拡大されるのを避ける意味もある */
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3, h4 { line-height: 1.4; margin: 0 0 0.5em; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0625rem; }
p { margin: 0 0 1em; }
ul, ol { margin: 0 0 1em; padding-left: 1.4em; }

a { color: var(--brand-dark); }
a:hover { color: var(--brand); }

/* フォーカスは常に見える。outline: none は使わない */
:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
  border-radius: 3px;
}

img { max-width: 100%; height: auto; }

/* 読み上げ専用テキスト */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* キーボード利用者のための本文へスキップ */
.skip-link {
  position: absolute;
  left: 0; top: -3rem;
  background: var(--brand-dark);
  color: #fff;
  padding: 0.6rem 1rem;
  z-index: 100;
  transition: top 0.1s;
}
.skip-link:focus { top: 0; }

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: 1rem;
}

/* ------------------------------------------------------------------ */
/* ボタン                                                              */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  /* 指で押せる大きさ（WCAG 2.2 の Target Size を満たす） */
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--bg-soft); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-dark); color: #fff; }

.btn-danger { color: var(--state-expired); border-color: #e5b4b4; }
.btn-danger:hover { background: var(--state-expired-bg); }

.btn-quiet { border-color: transparent; background: transparent; }
.btn-quiet:hover { background: var(--bg-soft); }

.btn-sm { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.875rem; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ------------------------------------------------------------------ */
/* フォーム                                                            */
/* ------------------------------------------------------------------ */

.field { margin-bottom: 1.1rem; }

.field > label,
.field > .label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.field-hint {
  display: block;
  font-size: 0.875rem;
  color: var(--ink-faint);
  margin-bottom: 0.35rem;
}

.req {
  font-size: 0.75rem;
  color: var(--state-expired);
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 0.3em;
  margin-left: 0.4em;
  vertical-align: 0.1em;
}
.opt {
  font-size: 0.75rem;
  color: var(--ink-faint);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0 0.3em;
  margin-left: 0.4em;
  vertical-align: 0.1em;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], input[type="url"], input[type="search"],
select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.65rem;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
textarea { min-height: 7rem; resize: vertical; line-height: 1.7; }

input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--state-expired);
  background: #fffafa;
}

.field-error {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--state-expired);
}
.field-error::before { content: "⚠ "; }

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.checkbox-row input[type="checkbox"] {
  width: 22px; height: 22px;
  min-height: 0;
  margin-top: 0.2rem;
  flex: none;
}
.checkbox-row label { font-weight: normal; }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  margin: 0 0 1.1rem;
}
legend { font-weight: 600; padding-inline: 0.4rem; }

/* ------------------------------------------------------------------ */
/* 通知・お知らせ                                                      */
/* ------------------------------------------------------------------ */

.notice {
  display: flex;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line-strong);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  margin-bottom: 1rem;
}
.notice p:last-child { margin-bottom: 0; }
.notice-icon { flex: none; font-weight: 700; }

.notice-info { border-left-color: var(--state-near); background: var(--state-near-bg); }
.notice-warn { border-left-color: var(--state-soon); background: var(--state-soon-bg); }
.notice-error { border-left-color: var(--state-expired); background: var(--state-expired-bg); }
.notice-success { border-left-color: var(--state-ok); background: var(--state-ok-bg); }

/* ------------------------------------------------------------------ */
/* 期限の状態バッジ                                                    */
/*                                                                     */
/* 色に加えて必ず「記号 + 文字」を持たせる。色が見分けられなくても、    */
/* また白黒印刷でも、状態が分かるようにするため。                      */
/* ------------------------------------------------------------------ */

.state {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.15em 0.55em;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}
.state-mark { font-size: 0.9em; }

.state-expired { color: var(--state-expired); background: var(--state-expired-bg); }
.state-today   { color: var(--state-today);   background: var(--state-today-bg); }
.state-within7 { color: var(--state-soon);    background: var(--state-soon-bg); }
.state-within30 { color: var(--state-near);   background: var(--state-near-bg); }
.state-within90 { color: var(--state-ok);     background: var(--state-ok-bg); }
.state-later   { color: var(--state-done);    background: var(--state-done-bg); }
.state-completed { color: var(--state-done);  background: var(--state-done-bg); }
.state-archived { color: var(--state-done);   background: var(--state-done-bg); }

/* ------------------------------------------------------------------ */
/* カード・表                                                          */
/* ------------------------------------------------------------------ */

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 1rem;
  margin-bottom: 1rem;
}

.card-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
}

.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  background: var(--bg-soft);
}
.stat-label { font-size: 0.875rem; color: var(--ink-soft); margin: 0; }
.stat-value { font-size: 1.75rem; font-weight: 700; margin: 0.1rem 0 0; line-height: 1.2; }
.stat-value .unit { font-size: 0.875rem; font-weight: 600; margin-left: 0.15em; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.875rem; color: var(--ink-soft); white-space: nowrap; }

/* ------------------------------------------------------------------ */
/* 期限一覧                                                            */
/* ------------------------------------------------------------------ */

.deadline-list { list-style: none; margin: 0; padding: 0; }

.deadline-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  background: var(--bg);
}
.deadline-link {
  display: grid;
  gap: 0.15rem 0.75rem;
  grid-template-columns: 1fr auto;
  padding: 0.8rem 0.9rem;
  color: inherit;
  text-decoration: none;
}
.deadline-link:hover { background: var(--bg-soft); color: inherit; }
.deadline-title { font-weight: 700; }
.deadline-meta {
  grid-column: 1 / -1;
  font-size: 0.875rem;
  color: var(--ink-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.75rem;
}
.deadline-days { text-align: right; font-weight: 700; white-space: nowrap; }

/* 期限切れの項目は左端の太線でも示す（色以外の手掛かり） */
.deadline-item.is-expired { border-left: 5px solid var(--state-expired); }
.deadline-item.is-today { border-left: 5px solid var(--state-today); }
.deadline-item.is-within7 { border-left: 5px solid var(--state-soon); }

.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--ink-soft);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

/* ------------------------------------------------------------------ */
/* ページ送り                                                          */
/* ------------------------------------------------------------------ */

.pager { display: flex; align-items: center; justify-content: center; gap: 0.75rem; margin: 1rem 0; }
.pager-status { font-size: 0.875rem; color: var(--ink-soft); }

/* ------------------------------------------------------------------ */
/* 動きの抑制                                                          */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* コントラストを強めたい利用者向け */
@media (prefers-contrast: more) {
  :root { --line: #999; --line-strong: #555; --ink-faint: #444; }
}
