/* 資産台帳（試作品）
   見た目のルールは docs/design-rules.md。色はここの変数だけを使い、直接書かない。
   ダークモードは :root[data-theme="dark"] で変数だけを差し替える。 */

/* 書体：M PLUS Rounded 1c（fonts/ に同梱。OFL ライセンス。fonts/OFL.txt）
   読み込めないときは、これまでの BIZ UDPゴシックで表示する */
@font-face {
  font-family: "M PLUS Rounded 1c";
  src: url("../fonts/MPLUSRounded1c-Regular.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "M PLUS Rounded 1c";
  src: url("../fonts/MPLUSRounded1c-Bold.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light;
  --page: #dcf2ef;
  --frame: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f7f7;
  --ink: #213239;
  --ink-soft: #56696f;
  --line: #dfeaea;
  --primary: #13827a;
  --primary-strong: #106f68;
  --primary-ink: #ffffff;
  --primary-soft: #dcf4f1;
  --accent: #ffcf48;
  --accent-ink: #2a2200;
  --side-a: #5fd0c3;
  --side-b: #6bb8e4;
  --hero-a: #5ccdc0;
  --hero-b: #74b4e6;
  --on-color: #0f3b3c;      /* グラデーションの上の文字（明るいミントの上なので濃い紺） */
  --shadow: 0 10px 30px rgba(34, 120, 118, .12);
  --focus: #2f6fd6;
  --glass: rgba(255, 255, 255, .18);        /* グラデーションの上の半透明の面 */
  --glass-hover: rgba(255, 255, 255, .3);
  --switch-on-bg: #ffffff;                  /* 画面の色ボタン（選択中） */
  --switch-on-ink: #17605b;
  --expired: #c62f2f;   --expired-bg: #fde9e9;
  --soon: #a34f08;      --soon-bg: #fff0e1;
  --later: #7e5c00;     --later-bg: #fff6d4;
  --review: #1f5c96;    --review-bg: #e3eefa;   --review-bar: #3a7bc8;  /* 見直しのヒント（期限の色と分ける） */
  --font: "M PLUS Rounded 1c", "BIZ UDPGothic", "BIZ UDPゴシック", "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif;
  --r-frame: 36px; --r-card: 24px; --r-row: 14px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b171b;
  --frame: #102127;
  --surface: #162c33;
  --surface-2: #1c353d;
  --ink: #e4f0f1;
  --ink-soft: #9db4b9;
  --line: #24424a;
  --primary: #45d0c2;
  --primary-strong: #6fe0d4;
  --primary-ink: #062022;
  --primary-soft: #173f3f;
  --accent: #ffd45e;
  --accent-ink: #2a2200;
  --side-a: #1d6d68;
  --side-b: #1c4c6b;
  --hero-a: #1e7c75;
  --hero-b: #275d8a;
  --on-color: #ffffff;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --focus: #8fb8ff;
  --glass: rgba(255, 255, 255, .12);
  --glass-hover: rgba(255, 255, 255, .1);   /* ダークは白を重ねすぎると文字が読みにくくなる（.16 だと 4.34） */
  --switch-on-bg: #e4f0f1;
  --switch-on-ink: #0d4a46;
  --expired: #ff7b72;   --expired-bg: #3a1c1f;
  --soon: #ffab5c;      --soon-bg: #3a2817;
  --later: #f2cc4b;     --later-bg: #36301a;
  --review: #8ec5ff;    --review-bg: #1b2f45;   --review-bar: #8ec5ff;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}
a { color: var(--primary-strong); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 4px 8px; z-index: 10; }

/* デモ用であることを、どの画面でも上に示す（色を反転して、ほかの表示と見分ける） */
.demo-band {
  margin: 16px 24px 0; padding: 8px 16px; border-radius: var(--r-row);
  background: var(--ink); color: var(--surface); font-size: .9rem; font-weight: 700; text-align: center;
}
.demo-band + .shell { margin-top: 12px; }

/* ---- 枠 ---- */
.shell {
  display: grid; grid-template-columns: 230px minmax(0, 1fr);
  margin: 24px; min-height: calc(100vh - 48px);
  background: var(--frame); border-radius: var(--r-frame); box-shadow: var(--shadow);
}
.side {
  margin: 14px; border-radius: 28px; padding: 26px 0 20px;
  background: linear-gradient(180deg, var(--side-a), var(--side-b)); color: var(--on-color);
  display: flex; flex-direction: column;
  /* 長いページでも、メニューと画面の色の切り替えが常に見えるように、画面の高さに固定する
     （外枠の余白 24px×2 ＋ メニューの余白 14px×2 = 76px）
     固定する位置は、最初に表示される位置（外枠 24px ＋ メニュー 14px = 38px）と同じにする。
     違うと、スクロールし始めにメニューが少し動いてから止まる（2026-10-30 なつきさんの指摘で修正） */
  position: sticky; top: 38px; align-self: start;
  height: calc(100vh - 76px); overflow-y: auto;
}
.brand { margin: 0 24px 30px; font-size: 1.35rem; font-weight: 700; letter-spacing: .04em; }
.brand small { display: block; font-size: .75rem; font-weight: 400; opacity: .85; letter-spacing: 0; }
.menu { list-style: none; margin: 0; padding: 0; }
.menu a, .menu-soon {
  display: flex; align-items: center; gap: 12px;
  margin: 3px 0 3px 14px; padding: 11px 18px; border-radius: 999px 0 0 999px;
  color: inherit; text-decoration: none; font-weight: 700;
}
.menu a:hover { background: var(--glass-hover); }
.menu a[aria-current="page"] { background: var(--frame); color: var(--primary-strong); }
.menu-soon { cursor: not-allowed; font-weight: 400; } /* 薄くすると読めないので、押せないことは細い文字・「準備中」・マウスの形で伝える */
.menu-soon { flex-wrap: wrap; row-gap: 0; }
.menu-soon small { flex-basis: 100%; padding-left: 32px; font-size: .7rem; line-height: 1.2; }
.menu a, .menu-soon { white-space: nowrap; }
.ic { width: 20px; height: 20px; flex: none; }

.theme-switch { margin: auto 22px 0; padding-top: 20px; }
.theme-switch .label { display: block; font-size: .75rem; opacity: .85; margin: 0 0 6px 6px; }
.theme-switch div { display: flex; background: var(--glass); border-radius: 999px; padding: 4px; }
.theme-switch button {
  flex: 1; border: 0; border-radius: 999px; padding: 6px 0; background: none; color: inherit;
  font: inherit; font-size: .85rem; cursor: pointer;
}
.theme-switch button:hover { background: var(--glass-hover); }
.theme-switch button[aria-pressed="true"] { background: var(--switch-on-bg); color: var(--switch-on-ink); font-weight: 700; }

main { padding: 30px 36px 56px 18px; width: 100%; max-width: 1180px; }
main:focus { outline: none; }

h1 { font-size: 1.6rem; margin: 0 0 4px; line-height: 1.4; }
h1, h2, h3 { text-wrap: balance; overflow-wrap: anywhere; }
h2 { font-size: 1.15rem; margin: 32px 0 12px; }
h3 { font-size: 1rem; margin: 20px 0 8px; }
.lead { color: var(--ink-soft); margin: 0 0 22px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; }
.h-count { margin-left: 10px; font-size: .9rem; font-weight: 400; color: var(--ink-soft); }
.muted { color: var(--ink-soft); }
.note { font-size: .85rem; color: var(--ink-soft); }
section + section { margin-top: 12px; }

/* ---- カード ---- */
.card { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 22px 24px; }

/* ---- 管理番号のラベルテープ ---- */
.tape {
  display: inline-block; padding: 2px 12px;
  background: var(--surface-2); color: var(--ink);
  border: 1px dashed var(--line); border-radius: 8px;
  font-weight: 700; letter-spacing: .06em; white-space: nowrap;
}
.tape-lg { font-size: 1.2rem; padding: 3px 16px; }

/* ---- ボタン ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 6px 22px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--primary-strong);
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
  touch-action: manipulation; white-space: nowrap; flex: none;
}
.btn:hover { background: var(--primary-soft); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: var(--accent); filter: brightness(.95); }
.btn-danger { color: var(--expired); border-color: var(--expired); }
.btn-danger:hover { background: var(--expired-bg); }
.btn-small { min-height: 34px; padding: 2px 16px; font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---- メッセージ ---- */
.message { margin: 0 0 18px; padding: 12px 18px; border-radius: var(--r-row); font-weight: 700; }
.message-success { background: var(--primary-soft); color: var(--primary-strong); }
.message-error { background: var(--expired-bg); color: var(--expired); }
.errors { margin: 0 0 20px; padding: 14px 20px; background: var(--expired-bg); color: var(--ink); border-radius: var(--r-row); }
.errors p { margin: 0 0 4px; font-weight: 700; color: var(--expired); }
.errors ul { margin: 0; padding-left: 1.2em; }
.errors a { color: var(--expired); }

/* ---- 絞り込みのつまみ ---- */
.tabs, .chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.tab, .chip {
  padding: 8px 20px; border: 0; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft);
  font: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.tab:hover, .chip:hover { color: var(--ink); }
.tab[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); box-shadow: var(--shadow); }

.filters { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin-bottom: 14px; }
.filters label { display: grid; gap: 4px; font-size: .85rem; color: var(--ink-soft); }
.filters input[type="search"] { border-radius: 999px; padding-left: 18px; min-width: 260px; }
.count { color: var(--ink-soft); margin: 0 0 6px; font-size: .9rem; }

/* ---- 表（行を丸いカードのように見せる） ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0 8px; }
th { padding: 4px 16px; text-align: left; font-size: .85rem; color: var(--ink-soft); font-weight: 700; white-space: nowrap; }
td { padding: 12px 16px; text-align: left; vertical-align: middle; background: var(--surface); }
td:first-child { border-radius: var(--r-row) 0 0 var(--r-row); }
td:last-child { border-radius: 0 var(--r-row) var(--r-row) 0; }
tbody tr { box-shadow: var(--shadow); border-radius: var(--r-row); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
tr.row-overdue td { background: var(--expired-bg); }
td.num { text-align: right; }
.row-link { color: inherit; text-decoration: none; font-weight: 700; }
.row-link:hover .tape { border-color: var(--primary); }
.empty { padding: 36px; text-align: center; color: var(--ink-soft); background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow); }

/* ---- 状態 ---- */
.pill { display: inline-block; padding: 3px 14px; border-radius: 999px; font-size: .85rem; font-weight: 700; white-space: nowrap; }
.pill-expired { color: var(--expired); background: var(--expired-bg); }
.pill-within30 { color: var(--soon); background: var(--soon-bg); }
.pill-within60 { color: var(--later); background: var(--later-bg); }
.pill-plain { color: var(--ink-soft); background: var(--surface-2); }
.pill-loan { color: var(--primary-strong); background: var(--primary-soft); }
.pill-available { color: var(--primary-strong); background: transparent; box-shadow: inset 0 0 0 2px var(--primary); } /* 利用可能：貸出中と同じ色の枠だけ（新しい色を足さない） */
.pill-review { color: var(--review); background: var(--review-bg); }

/* ---- ホーム ---- */
.home-top { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 22px; margin-bottom: 8px; }
/* 横に並んだカードの上下をそろえる（全体の「section + section の上の余白」を、横並びのところでは打ち消す。間は gap で空ける）
   ホームの上の段と、ダッシュボードの「種類ごと・状態ごとの数」 */
.home-top > *, .dash-counts > * { margin: 0; }
.hero {
  border-radius: var(--r-card); padding: 26px 30px; color: var(--on-color);
  background: linear-gradient(120deg, var(--hero-a), var(--hero-b)); box-shadow: var(--shadow);
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 28px; align-items: center;
}
.hero-label { color: var(--on-color); font-weight: 700; margin: 0; display: flex; align-items: center; gap: 8px; }
.hero-label::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.hero-big { font-size: 5rem; font-weight: 700; line-height: 1; margin: 0; }
.hero-big small { font-size: 1.1rem; margin-left: 6px; }
.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.hero-stats li { background: var(--glass); border-radius: 18px; padding: 12px 16px; }
.hero-stats b { display: block; font-size: 1.8rem; line-height: 1.3; }
.ring-head { display: flex; justify-content: space-between; align-items: baseline; }
.ring-head h2 { margin: 0; }
.ring { display: grid; place-items: center; margin: 10px 0 0; }
.ring-outer { width: 140px; height: 140px; border-radius: 50%; display: grid; place-items: center; }
.ring-inner { width: 110px; height: 110px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; line-height: 1.3; }
.ring-inner b { display: block; font-size: 1.9rem; color: var(--primary-strong); }
.section-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 26px 0 4px; }
.section-head h2 { margin: 0; }

/* ---- ダッシュボード ---- */
.dash-counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 22px; }
.dash-counts h2 { margin-top: 0; }
.stat-tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat-tile { background: var(--surface-2); border-radius: 18px; padding: 12px 14px; display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.stat-tile .muted:first-child { flex-basis: 100%; font-size: .9rem; }
.stat-tile b { font-size: 1.9rem; line-height: 1.2; }
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.insight { display: flex; gap: 12px; align-items: baseline; background: var(--surface); border-radius: var(--r-row); box-shadow: var(--shadow); padding: 14px 18px; }
/* 押せることが分かるように、下線を付ける */
.insight a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--primary); text-underline-offset: 4px; }
.insight a:hover { color: var(--primary-strong); }
.rate { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.rate-bar { flex: 1; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.rate-fill { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.rate-fill.rate-low { background: var(--review-bar); }
.ai-text { margin-top: 10px; font-size: .9rem; line-height: 1.6; }
details summary { cursor: pointer; color: var(--primary-strong); font-weight: 700; }

/* ---- 詳細 ---- */
.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 0 32px; margin: 0;
  background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 10px 24px;
}
.facts div { display: grid; grid-template-columns: 8em 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--ink-soft); font-size: .9rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.now-status { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px; font-weight: 700; }
.now-status > span { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.now-status .now-label { white-space: nowrap; }
/* 貸出・返却の欄（左）と基本情報（右）。スマホ幅では1列にし、貸出・返却の欄を上にする */
.detail-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 24px; align-items: start; margin-top: 16px; }
.detail-cols > * { margin-top: 0; }
.detail-cols > section > h2:first-child { margin-top: 0; }
.loan-panel .fields { grid-template-columns: minmax(0, 1fr); }
.loan-panel .facts { background: transparent; box-shadow: none; padding: 0; grid-template-columns: minmax(0, 1fr); }
.detail-cols .card > h2:first-child { margin-top: 0; }
.detail-facts .facts { background: transparent; box-shadow: none; padding: 0; }
.loan-panel .actions { margin-top: 16px; } /* ボタンが上の入力欄にくっつかないように */

/* ---- フォーム ---- */
form { max-width: 860px; }
fieldset { border: 0; border-radius: var(--r-card); background: var(--surface); box-shadow: var(--shadow); padding: 18px 24px 24px; margin: 0 0 22px; }
legend { font-weight: 700; padding: 0; float: left; width: 100%; margin-bottom: 12px; font-size: 1.05rem; }
legend ~ * { clear: both; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px 20px; }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field label, .field .label { font-weight: 700; font-size: .95rem; }
.req { color: var(--expired); font-size: .8rem; margin-left: 6px; font-weight: 400; }
.hint { font-size: .8rem; color: var(--ink-soft); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-row); padding: 8px 14px; min-height: 42px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
/* 外側を角丸にすると「ファイルを選択」ボタンの角が切れるので、外側は角丸にせず、ボタンをふつうの .btn と同じ形にする */
input[type="file"] { border: 0; border-radius: 0; padding: 0; min-height: auto; background: none; }
input[type="file"]::file-selector-button {
  min-height: 42px; margin-right: 12px; padding: 6px 22px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--primary-strong);
  font: inherit; font-weight: 700; cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--primary-soft); }
.field-error { margin: 0; color: var(--expired); font-size: .9rem; font-weight: 700; }
[aria-invalid="true"] { border-color: var(--expired); border-width: 2px; }
.field[hidden] { display: none; }
.radio-row { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.radio-row label { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; }
.radio-row input { width: auto; min-height: auto; accent-color: var(--primary); }
.deadline-row { display: grid; grid-template-columns: 1fr 1fr 2fr auto; gap: 10px; align-items: end; padding: 12px 0; border-bottom: 1px solid var(--line); }
.danger-zone { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---- 設定 ---- */
.option-list { list-style: none; margin: 0 0 12px; padding: 0; }
.option-list li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.option-list input { max-width: 260px; }
.option-stopped input { color: var(--ink-soft); text-decoration: line-through; }
.add-row { display: flex; gap: 8px; max-width: 440px; }

/* ---- 貸出・返却 ---- */
.return-cell { display: flex; gap: 8px; align-items: center; }
.return-cell input { width: auto; min-height: 34px; padding: 2px 10px; }

/* ---- 高さが低い画面（ノートパソコンなど） ----
   メニューを画面の高さに固定しているので、行の間隔を詰めて、画面の色の切り替えまで収める */
@media (max-height: 760px) and (min-width: 761px) {
  .side { padding: 16px 0 12px; }
  .brand { margin-bottom: 14px; }
  .menu a, .menu-soon { padding-top: 7px; padding-bottom: 7px; }
  .menu-soon small { flex-basis: auto; padding-left: 0; margin-left: 2px; } /* 「準備中」は名前の横に並べて、押せないことを残す */
  .theme-switch { padding-top: 10px; }
}

/* ---- スマートフォン幅 ---- */
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); margin: 10px; min-height: 0; border-radius: 24px; }
  .demo-band { margin: 10px 10px 0; font-size: .85rem; }
  .demo-band + .shell { margin-top: 8px; }
  .side { margin: 8px; padding: 14px 0 10px; border-radius: 20px; position: static; height: auto; overflow: visible; }
  .brand { margin: 0 16px 8px; }
  .menu { display: flex; overflow-x: auto; padding: 0 8px; }
  .menu li { flex: none; }
  .menu a, .menu-soon { margin: 0; padding: 8px 14px; border-radius: 999px; }
  .menu-soon { display: none; }
  .theme-switch { margin: 10px 16px 0; padding-top: 0; }
  main { padding: 16px 14px 40px; }
  .table-wrap table { min-width: 680px; }
  td, th { padding: 10px 12px; }
  /* 狭い画面では、短い欄（種類など）が1文字ずつ縦に折れないように、表は1行のまま横にスクロールさせる */
  .table-wrap td, .table-wrap th { white-space: nowrap; }
  .home-top { grid-template-columns: minmax(0, 1fr); }
  .hero { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 22px; }
  .hero-big { font-size: 4rem; }
  .deadline-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .deadline-row > :nth-child(3), .deadline-row > button { grid-column: 1 / -1; }
  .facts div { grid-template-columns: 7em 1fr; }
  .detail-cols { grid-template-columns: minmax(0, 1fr); }
  .filters input[type="search"] { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
