/* Notifedi の部品。tokens.css の後に読む。管理画面、運営者の画面、公開ページで共有する。 */

/* 土台 */
*, *::before, *::after { box-sizing: border-box; }
/* hidden wins over display: flex and grid of the classes. */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--t-md);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 {
  margin: 0;
  line-height: var(--leading-tight);
  font-feature-settings: "palt";
  text-wrap: balance;
  letter-spacing: -0.01em;
}
h1 { font-size: var(--t-xl); font-weight: 650; }
h2 { font-size: var(--t-lg); font-weight: 650; }
h3 { font-size: var(--t-md); font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 0.15em; }
a:hover { color: var(--accent-strong); }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-1); }
.hint { color: var(--muted); font-size: var(--t-sm); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.between { justify-content: space-between; }
/* 2 つの欄を横に並べる(狭ければ縦に) */
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--s-4); }
.two > * { min-width: 0; }
@media (prefers-reduced-motion: no-preference) {
  a, button, .btn, input, select, textarea, tr { transition: background-color 120ms, border-color 120ms, color 120ms; }
}

/* ヘッダーとナビ */
header.site {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-3) var(--s-5);
  padding: var(--s-2) var(--s-4);
  background: var(--header-bg);
  color: var(--header-fg);
  border-bottom: 1px solid var(--header-line);
  font-size: var(--t-sm);
}
header.site .brand { font-weight: 700; color: var(--header-fg); text-decoration: none; font-size: var(--t-md); }
header.site .brand { display: inline-flex; align-items: center; gap: 0.45em; }
header.site .scope { color: var(--header-muted); padding-left: var(--s-3); border-left: 1px solid var(--header-line); }
header.site nav { display: flex; gap: var(--s-1); }
header.site nav a {
  color: var(--header-muted); text-decoration: none; padding: var(--s-1) var(--s-2); border-radius: var(--r-2);
}
header.site nav a:hover { color: var(--header-fg); background: var(--header-hover); }
header.site nav a[aria-current="page"] { color: var(--header-current-fg); background: var(--header-current); }
header.site .user { margin-left: auto; color: var(--header-muted); }
header.site .btn-quiet { color: var(--header-muted); }
header.site .btn-quiet:hover { color: var(--header-fg); background: var(--header-hover); }
main { max-width: var(--content); margin: 0 auto; padding-block: var(--s-5) var(--s-7); padding-inline: var(--s-4); }
main.stack { gap: var(--s-5); }

/* 見出しの行: 見出しと操作を同じ行に */
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s-2) var(--s-4); }
.page-head .hint { flex-basis: 100%; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.crumbs + .page-head { margin-top: calc(-1 * var(--s-3)); }

/* パンくず: 戻るリンクの代わり */
ul.crumbs { display: flex; flex-wrap: wrap; gap: var(--s-1); list-style: none; margin: 0; padding: 0; font-size: var(--t-sm); color: var(--muted); }
ul.crumbs a { color: var(--muted); text-decoration: none; }
ul.crumbs a:hover { color: var(--fg); text-decoration: underline; }
ul.crumbs li + li::before { content: "›"; margin-right: var(--s-1); }

/* フォームの幅は本文の幅まで */
form.form { max-width: var(--prose); }

/* ボタン */
.btn, input[type="submit"] {
  display: inline-flex; align-items: center; gap: 0.4em;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2);
  background: var(--surface);
  color: var(--fg);
  font: inherit; font-size: var(--t-sm); font-weight: 550; line-height: 1.2;
  text-decoration: none; cursor: pointer;
  box-shadow: var(--shadow);
}
/* Links as buttons keep the button colors on hover, not the link color. */
.btn:hover { background: var(--surface-2); color: var(--fg); }
.btn-primary, input[type="submit"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover, input[type="submit"]:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-fg); }
.btn-danger { color: var(--bad); border-color: color-mix(in oklch, var(--bad) 45%, var(--line-strong)); }
.btn-danger:hover { background: var(--bad-soft); color: var(--bad); }
.btn-quiet { border-color: transparent; box-shadow: none; background: transparent; color: var(--accent); }
.btn-quiet:hover { background: var(--accent-soft); color: var(--accent-strong); }
.btn-sm { padding: 0.25rem 0.6rem; font-size: var(--t-xs); }
.btn[disabled], input[type="submit"][disabled] { opacity: 0.5; cursor: not-allowed; }

/* バッジ: 状態は色と文字の両方で */
.badge {
  display: inline-flex; align-items: center; gap: 0.4em;
  padding: 0.1em 0.55em; border-radius: 999px;
  font-size: var(--t-xs); font-weight: 550; line-height: 1.5; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge::before { content: ""; width: 0.5em; height: 0.5em; border-radius: 50%; background: currentColor; }
.badge[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); }
.badge[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); }
.badge[data-tone="bad"] { background: var(--bad-soft); color: var(--bad); }
.badge[data-tone="info"] { background: var(--accent-soft); color: var(--accent); }
.badge[data-tone="muted"]::before { background: var(--line-strong); }

/* 表 */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-3); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
table.data th, table.data td { text-align: left; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data thead th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--muted);
  font-size: var(--t-xs); font-weight: 600; letter-spacing: 0.02em;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: color-mix(in oklch, var(--surface-2) 60%, var(--surface)); }
table.data td.num, table.data th.num { font-variant-numeric: tabular-nums; text-align: right; }
table.data .primary { font-weight: 550; color: var(--fg); }

/* パネル: 区切りが要るものだけに使う */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-3); padding: var(--s-4) var(--s-5); }
.panel > h2 { margin-bottom: var(--s-3); }

/* 統計のタイル */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: var(--s-3); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-3); padding: var(--s-3) var(--s-4); }
.stat .label { font-size: var(--t-xs); color: var(--muted); font-weight: 600; letter-spacing: 0.02em; }
.stat .value { font-size: var(--t-xl); font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: var(--s-1); }
.stat .delta { font-size: var(--t-xs); color: var(--muted); }
.stat .delta[data-tone="ok"] { color: var(--ok); }
.stat .delta[data-tone="bad"] { color: var(--bad); }

/* 定義リスト */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-5); margin: 0; font-size: var(--t-sm); }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* フォーム */
.field { display: flex; flex-direction: column; gap: var(--s-1); margin: 0; padding: 0; border: none; min-width: 0; }
.field > label, .field > legend { font-weight: 600; font-size: var(--t-sm); padding: 0; }
.field .hint { order: 1; }
.field .error { order: 2; color: var(--bad); font-size: var(--t-sm); }
.field input[type="text"], .field input[type="email"], .field input[type="url"], .field input[type="number"],
.field input[type="password"], .field input[type="datetime-local"], .field select, .field textarea {
  width: 100%; padding: 0.45rem 0.6rem;
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  background: var(--surface); color: var(--fg); font: inherit; font-size: var(--t-md);
}
.field textarea { min-height: 3lh; resize: vertical; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field[data-invalid] input, .field[data-invalid] textarea { border-color: var(--bad); }
.choice { display: flex; gap: var(--s-2); align-items: flex-start; font-weight: 400; font-size: var(--t-md); }
.choice input { margin-top: 0.3em; accent-color: var(--accent); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; padding-top: var(--s-2); }
.form-actions .hint { margin-left: auto; }

/* 通知 */
.notice {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-2);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  background: var(--surface); font-size: var(--t-sm);
}
.notice[data-tone="ok"] { border-left-color: var(--ok); }
.notice[data-tone="warn"] { border-left-color: var(--warn); background: var(--warn-soft); }
.notice[data-tone="bad"] { border-left-color: var(--bad); background: var(--bad-soft); }
.notice strong { font-weight: 650; }

/* トースト: 右下に重ねる */
.toasts { position: fixed; right: var(--s-4); bottom: calc(var(--s-4) + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: var(--s-2); z-index: 10; max-width: min(22rem, calc(100vw - 2 * var(--s-4))); }
.toast {
  display: flex; gap: var(--s-3); align-items: center;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-3);
  background: var(--fg); color: var(--bg); font-size: var(--t-sm);
  box-shadow: 0 8px 24px oklch(0% 0 0 / 0.25);
}
.toast .tone { width: 0.5em; height: 0.5em; border-radius: 50%; flex: none; background: var(--ok); }
.toast[data-tone="bad"] .tone { background: var(--bad); }
.toast button { margin-left: auto; background: none; border: none; color: inherit; opacity: 0.7; cursor: pointer; font: inherit; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 180ms ease-out; }
  @keyframes toast-in { from { opacity: 0; translate: 0 6px; } }
}

/* 空の状態: 次の操作を添える */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  padding: var(--s-7) var(--s-4); text-align: center;
  border: 1px dashed var(--line-strong); border-radius: var(--r-3); color: var(--muted);
}
.empty h3 { color: var(--fg); }

/* ページ送りとタブ */
.pager { display: flex; gap: var(--s-3); font-size: var(--t-sm); }
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--line); font-size: var(--t-sm); }
.tabs a { padding: var(--s-2) var(--s-3); color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 0.3em; }

/* ダイアログ */
dialog.confirm { border: 1px solid var(--line); border-radius: var(--r-3); padding: var(--s-5); background: var(--surface); color: var(--fg); max-width: 28rem; box-shadow: 0 16px 48px oklch(0% 0 0 / 0.25); }
dialog.confirm::backdrop { background: oklch(0% 0 0 / 0.4); }


/* Rails の flash と検証のエラー。tone は .notice と同じ */
.notice:not([data-tone]) { border-left-color: var(--ok); }
.alert { display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-2); border: 1px solid var(--line); border-left: 3px solid var(--bad); background: var(--bad-soft); font-size: var(--t-sm); }
ul.alert { flex-direction: column; gap: var(--s-1); list-style: none; margin: 0; }
.errors { padding: var(--s-3) var(--s-4); border-radius: var(--r-2); border: 1px solid var(--line); border-left: 3px solid var(--bad); background: var(--bad-soft); font-size: var(--t-sm); }
.errors ul { margin: 0; padding-left: 1.2em; }

/* 単独の入力(検索など) */
.input { padding: 0.45rem 0.6rem; border: 1px solid var(--line-strong); border-radius: var(--r-2); background: var(--surface); color: var(--fg); font: inherit; font-size: var(--t-sm); }
.input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
form.inline { display: inline-flex; gap: var(--s-2); align-items: center; margin: 0; }
form.inline-block { display: inline; margin: 0; }

/* 固定した投稿の印(公開ページとホーム) */
.pin { display: inline-flex; align-items: center; gap: 0.3em; color: var(--accent); font-weight: 600; font-size: var(--t-xs); padding: 0.1em 0.5em; border-radius: 999px; background: var(--accent-soft); }
.reactions { display: flex; flex-wrap: wrap; gap: var(--s-3); margin: var(--s-2) 0 0; color: var(--muted); font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
td .reactions { margin: 0; }
article.post.pinned { border-color: color-mix(in oklch, var(--accent) 35%, var(--line)); }

/* 「?」の補足: 重ねるか焦点を当てると出る */
.help { position: relative; display: inline-flex; align-items: center; color: var(--muted); cursor: help; border-radius: 50%; }
.help:hover, .help:focus-visible { color: var(--accent); }
.help .help-text { position: absolute; left: 0; top: calc(100% + 0.4rem); z-index: 5; width: max-content; max-width: min(22rem, 80vw); padding: var(--s-2) var(--s-3); border-radius: var(--r-2); background: var(--fg); color: var(--bg); font-size: var(--t-xs); line-height: 1.5; box-shadow: 0 8px 24px oklch(0% 0 0 / 0.25); visibility: hidden; opacity: 0; }
.help:hover .help-text, .help:focus-within .help-text { visibility: visible; opacity: 1; }
@media (prefers-reduced-motion: no-preference) { .help .help-text { transition: opacity 120ms; } }

/* 投稿の横の書き手: アイコンと、表示名の下にハンドル */
.author { display: inline-flex; align-items: center; gap: var(--s-2); text-decoration: none; color: var(--fg); min-width: 0; }
.author .who { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.author .who strong { font-weight: 650; }
.author .who .handle { font-family: var(--mono); color: var(--muted); font-size: var(--t-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.author:hover .who strong { text-decoration: underline; }
.avatar-xs { flex: none; width: 2.75rem; height: 2.75rem; border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: var(--t-md); }
img.avatar-xs { background: oklch(100% 0 0); border: 1px solid var(--line); }
