/*
 * Team Wiki theme — 和モダン×方眼 (Calm grid).
 * Base shapes (forms, buttons, tables, code) come from PicoCSS classless (CDN, light theme).
 * This file sets the palette/typography tokens, the gridded background + content panel,
 * the navigation, and app-specific components.
 */

:root {
  /* Palette */
  --bg:         #edece5;   /* gridded outer ground */
  --panel:      #fdfdfb;   /* content panel */
  --surface:    #ffffff;   /* cards */
  --ink:        #2b2b2b;
  --ink-soft:   #5c5c57;
  --muted:      #8a8a82;
  --accent:     #2f4b7c;   /* 藍 */
  --accent-dark:#26406b;
  --accent-weak:#eef1f6;
  --hairline:   #e7e6e0;
  --grid:       #dcdacd;
  --code-bg:    #f5f5f1;
  --border:     #e7e6e0;
  --page:       62rem;     /* shared width: header inner === content panel */
  --sidebar-width: 15rem;

  /* Map PicoCSS to our palette/typography */
  --pico-font-family-sans-serif: "IBM Plex Sans JP", system-ui, sans-serif;
  --pico-font-family: "IBM Plex Sans JP", system-ui, sans-serif;
  --pico-font-size: 95%;
  --pico-line-height: 1.75;
  --pico-spacing: 0.9rem;
  --pico-form-element-spacing-vertical: 0.45rem;
  --pico-form-element-spacing-horizontal: 0.7rem;
  --pico-color: var(--ink);
  --pico-muted-color: var(--muted);
  --pico-muted-border-color: var(--hairline);
  --pico-primary: var(--accent);
  --pico-primary-background: var(--accent);
  --pico-primary-hover-background: var(--accent-dark);
  --pico-primary-underline: rgba(47, 75, 124, 0.3);
  --pico-card-background-color: var(--surface);
  --pico-card-border-color: var(--hairline);
}

/* Headings share the body sans font (per design). */
body { font-family: var(--pico-font-family-sans-serif); color: var(--ink); }
h1, h2, h3, h4, h5, h6 { font-family: var(--pico-font-family-sans-serif); letter-spacing: 0.01em; }

/* Gridded background on the outer ground. */
body {
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 2.5rem 2.5rem;
  background-position: -1px -1px;
}

/* Content panel: a solid surface centered over the grid.
   `body > main` outranks Pico's container so --page actually applies. */
body > main {
  max-width: var(--page);
  margin: 0 auto;
  padding: 2.6rem 2.2rem 5rem;
  background: var(--panel);
  border-left: 1px solid var(--hairline);
  border-right: 1px solid var(--hairline);
  box-shadow: 0 18px 50px -34px rgba(43, 43, 43, 0.3);
  min-height: 70vh;
}
@media (max-width: 640px) { body > main { padding: 1.6rem 1.1rem 3rem; border: none; box-shadow: none; } }

main a { color: var(--accent); }

/* `main` itself is the page panel, so a semantic <article> inside it must not
   render as a second Pico card. Strip Pico's card visuals — keep it a plain block
   so `main > article` pages and `main`-only pages share the same layout. */
main > article {
  margin: 0; padding: 0;
  background: none; border: 0; border-radius: 0; box-shadow: none;
}

/* ── Side navigation ──────────────────────────
   Wide: fixed left sidebar, content shifted right via body padding.
   Narrow (<= 880px): off-canvas drawer toggled by the topbar hamburger (overlay). */
body { padding-left: var(--sidebar-width); }

.topbar { display: none; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-width); z-index: 30;
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 1rem 0.9rem 1.3rem; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--hairline);
}
.sidebar__brand { font-size: 1.1rem; padding: 0.2rem 0.4rem 0.6rem; }
.sidebar__search { margin: 0 0 0.6rem; }
.sidebar__search input { width: 100%; font-size: 0.85rem; padding: 0.35rem 0.6rem; margin: 0; }
.sidebar__nav { display: flex; flex-direction: column; gap: 0.1rem; }
.sidebar__nav a {
  color: var(--ink-soft); text-decoration: none; font-size: 0.92rem; font-weight: 500;
  padding: 0.4rem 0.55rem; border-radius: 7px;
}
.sidebar__nav a:hover { background: var(--accent-weak); color: var(--accent); }
.nav-group { display: flex; flex-direction: column; gap: 0.1rem; margin-top: 0.9rem; }
.nav-group__label {
  font-size: 0.66rem; font-weight: 600; letter-spacing: 0.12em; color: var(--muted);
  padding: 0 0.55rem 0.2rem;
}
.sidebar__bottom { margin-top: auto; }
.sidebar__user {
  padding-top: 0.9rem; border-top: 1px solid var(--hairline);
  display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start;
}
.sidebar__about { display: block; margin-top: 0.6rem; font-size: 0.8rem; color: var(--muted); }

.site-footer {
  margin-top: 3rem; padding-top: 1.1rem; border-top: 1px solid var(--hairline);
  font-size: 0.82rem; color: var(--muted);
}
.site-footer p { margin: 0.2rem 0; }

.backdrop { display: none; }

@media (max-width: 880px) {
  body { padding-left: 0; }
  .topbar {
    display: flex; align-items: center; gap: 0.6rem; position: sticky; top: 0; z-index: 10;
    padding: 0.45rem 0.9rem; border-bottom: 1px solid var(--hairline);
    background: rgba(253, 253, 251, 0.92); backdrop-filter: saturate(1.2) blur(8px);
  }
  .topbar__toggle { background: none; border: 0; font-size: 1.4rem; line-height: 1; padding: 0.1rem 0.4rem; cursor: pointer; color: var(--ink); }
  .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: 0 0 40px rgba(43, 43, 43, 0.18); }
  .sidebar__brand { display: none; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(20, 17, 15, 0.35); }
}

.brand { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.02em; }
.brand-logo { max-height: 28px; width: auto; vertical-align: middle; }
.brand a { color: var(--ink); }
.brand::before {
  content: ""; display: inline-block; width: 0.5rem; height: 0.5rem;
  background: var(--accent); border-radius: 2px; margin-right: 0.5rem;
  transform: translateY(-1px) rotate(45deg);
}
.sidebar .user-link { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--ink-soft); text-decoration: none; }
.sidebar .user-link:hover { color: var(--accent); }

/* ── Page action conventions ──────────────────
   back-link (上の戻り) / page-header (index: 見出し+主ボタン) /
   actions (show: 編集・履歴 左、削除は右へ分離). */
.back-link { display: inline-block; color: var(--muted); text-decoration: none; font-size: 0.85rem; margin-bottom: 0.5rem; }
.back-link:hover { color: var(--accent); }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.actions { display: flex; align-items: center; gap: 0.9rem; margin: 0.6rem 0 1.4rem; padding-bottom: 0.9rem; border-bottom: 1px solid var(--hairline); }
.actions form.button_to { margin-left: auto; }

/* 管理者専用操作を上部で強調するブロック */
.admin-box { border: 1px solid var(--accent); border-left-width: 3px; background: var(--accent-weak); border-radius: 8px; padding: 0.7rem 0.9rem; margin: 0 0 1.3rem; }
.admin-box__label { display: inline-block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; color: var(--accent); margin-bottom: 0.35rem; }
.admin-box p { margin: 0; }

/* ── App components ───────────────────────── */

/* Revision diff */
.diff ins { background: #d4f8d4; text-decoration: none; }
.diff del { background: #f8d4d4; text-decoration: none; }

/* Wiki links */
.wikilink-new { color: #c00; }

/* Inline citations */
.ref { font-size: 0.75em; vertical-align: super; }
.ref a { text-decoration: none; }
.ref-broken { color: #c00; }

/* 出典 card */
.citations {
  margin: 2.5rem 0 0; padding: 1.3rem 1.5rem;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px;
}
.citations h2 { font-size: 1.05rem; margin: 0 0 0.7rem; }
.citations ol { padding-left: 1.4rem; margin: 0; }
.citations li { font-size: 0.9rem; color: var(--ink-soft); margin-bottom: 0.5rem; line-height: 1.7; }

/* Chronicle date inputs */
.date-clear {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.25rem;
}
.date-clear:hover { color: #c00; }
.date-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.date-row input { font: inherit; width: auto; display: inline-block; margin-bottom: 0; }
.date-row input[name$="_year]"] { width: 6em; }
.date-row input[name$="_month]"],
.date-row input[name$="_day]"],
.date-row input[name$="_hour]"],
.date-row input[name$="_minute]"] { width: 4.5em; }

/* Avatars & profile */
.avatar { border-radius: 50%; object-fit: cover; vertical-align: middle; display: inline-block; }
.avatar-initial { color: #fff; text-align: center; font-weight: 600; }
.profile { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.contributors { display: flex; gap: 0.25rem; flex-wrap: wrap; margin: 0.5rem 0; }
.contributors a { line-height: 0; }

/* Citation picker (editor toolbar popup) */
.citation-btn { margin: 0 6px; background: transparent; border: 0; color: var(--ink); }
.citation-picker { padding: 8px; }
.citation-picker__search { width: 100%; margin-bottom: 6px; }
.citation-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
.citation-list__empty { color: var(--muted); padding: 4px; }
/* Picker options are plain text rows, not Pico's blue primary buttons. */
.citation-list button {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--ink);
  padding: 0.35rem 0.5rem; border-radius: 6px; font-size: 0.9rem; line-height: 1.4;
}
.citation-list button:hover { background: var(--accent-weak); color: var(--accent); }
.citation-thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

/* Materials table */
.materials-table th a.sort-link { color: inherit; text-decoration: none; }
.materials-table th a.sort-link:hover { color: var(--accent); }
.pagy { display: flex; gap: 0.4rem; flex-wrap: wrap; padding: 0.75rem 0; list-style: none; }
.pagy a, .pagy span { padding: 0.1rem 0.5rem; }

/* Stacked form: each field group owns its spacing; label sits tight to its control. */
.stacked-form .field { margin-bottom: 1.6rem; }
.stacked-form .field:last-child { margin-bottom: 0; }
.stacked-form .field > label { margin-bottom: 0.4rem; }
.stacked-form .field > :where(input, textarea, select) { margin-bottom: 0; }
.field__hint { display: block; margin: -0.1rem 0 0.55rem; font-size: 0.8rem; line-height: 1.5; color: var(--muted); }
.field__hint code { font-size: 0.85em; }
.field__check { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0.6rem 0; font-weight: 400; }
.media-preview { margin: 0.1rem 0 0.6rem; }

/* Compact, inline per-page selector */
.per-form { margin: 0 0 1rem; }
.per-select { display: inline-block; margin: 0 0 0 0.4rem; }

/* Pico full-widths only submit controls (button[type=submit], input[type=submit], select)
   with NO !important. Match that selector — later in the cascade wins — to keep them
   content-width. Other buttons / [role=button] are already auto-width by default. */
button[type="submit"], input[type="submit"], select { width: auto; }

/* button_to renders a <form>; keep it inline so action buttons sit beside links/text.
   Button styling now uses Pico variants (.secondary / .outline). */
form.button_to { display: inline; }

/* Compact inline action button (delete / logout) — sits beside text links. */
.btn-sm { padding: 0.18rem 0.6rem; font-size: 0.8rem; line-height: 1.4; }

/* Article metadata badges */
.badges { display: flex; gap: 0.5rem; margin: 0.25rem 0 1rem; }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 500; letter-spacing: 0.04em;
  padding: 0.18rem 0.7rem; border-radius: 999px;
  border: 1px solid var(--hairline); color: var(--ink-soft); background: var(--surface);
}
.badge-status { background: var(--accent); color: #fff; border-color: var(--accent); }
.badge-kind { border-color: var(--accent); color: var(--accent); background: var(--accent-weak); }
.when { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 1rem; }
.bibliography { margin: 0.5rem 0; }
.bibliography dt { font-size: 0.8rem; color: var(--muted); }
.bibliography dd { margin: 0 0 0.4rem; }

/* Material thumbnails */
.material-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; vertical-align: middle; }
.material-thumb--icon { display: inline-flex; align-items: center; justify-content: center; font-size: 1.3rem; background: var(--code-bg); }

/* WIP marker (e.g. 年表 (検討中)) */
.wip { color: var(--muted); font-size: 0.7rem; font-weight: normal; }

/* Chronicle (interim flat view) */
.chronicle-note { margin: 0 0 1.4rem; }
.chronicle-list { margin: 0; padding-left: 1.1rem; }
.chronicle-list li { margin-bottom: 0.35rem; }

/* Home dashboard */
.dashboard-stats { display: flex; gap: 1.4rem; flex-wrap: wrap; margin: 0.5rem 0 1.4rem; color: var(--ink-soft); font-size: 0.9rem; }
.dashboard-stats strong { font-size: 1.15rem; color: var(--ink); }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1.2rem; }
.dashboard-card { background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px; padding: 1rem 1.2rem; margin-bottom: 1.2rem; }
.dashboard-card h2 { font-size: 1.05rem; margin: 0 0 0.7rem; }
.dashboard-card ul { margin: 0; padding-left: 1.1rem; }
.dashboard-card li { margin-bottom: 0.35rem; }
