/* ===========================================================================
   学校図書管理システム Webフロントエンド共通スタイル
   SPEC.md 7.3節: 色やスタイルはこのファイルに一元化し、HTML/JSには書かない。
   CSS変数(--color-primary等)は7.3節記載の値をそのまま採用する。
   =========================================================================== */

:root {
  --color-primary: #557aa3; /* サックスブルー */
  --color-primary-dark: #1f4569;
  --color-primary-light: #e7eff6;
  --color-bg: #ffffff;
  --color-bg-alt: #f5f7fa;
  --color-table-header: #f0f4f8;
  --color-table-row-alt: #f8fafc;
  --color-danger: #d64545;
  --color-danger-bg: #fbe9e9;
  --color-success: #2d8a4e;
  --color-success-bg: #e8f5ec;
  --color-warning: #b8860b;
  --color-warning-bg: #fdf3d9;
  --color-text: #222933;
  --color-text-muted: #6b7684;
  --color-border: #dbe2ea;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(30, 41, 59, 0.12);
  --shadow-hover: 0 4px 12px rgba(30, 41, 59, 0.18);
  --header-height: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", "Meiryo", system-ui, sans-serif;
  background: var(--color-bg-alt);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: 2rem;
}

a {
  color: var(--color-primary);
}

img {
  max-width: 100%;
}

h1, h2, h3 {
  margin: 0 0 0.6em;
  color: var(--color-text);
}

/* ---------------------------------------------------------------------------
   ヘッダー・ナビゲーション(共通)
   --------------------------------------------------------------------------- */

.app-header {
  background: var(--color-primary);
  color: var(--color-bg);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  height: var(--header-height);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}

.app-header .app-title {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  color: var(--color-bg);
  text-decoration: none;
}

.app-nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  overflow-x: auto;
}

.app-nav a {
  color: var(--color-bg);
  text-decoration: none;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  white-space: nowrap;
  opacity: 0.85;
}

.app-nav a.active,
.app-nav a:hover {
  background: rgba(255, 255, 255, 0.18);
  opacity: 1;
}

.app-user {
  font-size: 0.85rem;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-user button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.6);
  color: var(--color-bg);
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.app-user button:hover {
  background: rgba(255, 255, 255, 0.15);
}

main.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header-row h1 {
  margin: 0;
}

/* ---------------------------------------------------------------------------
   フォーム部品
   --------------------------------------------------------------------------- */

label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="email"],
select,
textarea {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--color-primary);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-bg);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-danger {
  background: var(--color-bg);
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger-bg);
}

.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

/* ---------------------------------------------------------------------------
   カード・パネル共通
   --------------------------------------------------------------------------- */

.panel {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 1.05rem;
  border-left: 4px solid var(--color-primary);
  padding-left: 0.5rem;
}

.empty-message {
  color: var(--color-text-muted);
  padding: 1rem 0;
  text-align: center;
  font-size: 0.9rem;
}

.loading-message {
  color: var(--color-text-muted);
  padding: 1rem 0;
  text-align: center;
  font-size: 0.9rem;
}

.error-banner {
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.info-banner {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success);
  color: var(--color-success);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-muted {
  background: var(--color-table-header);
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------------
   図書カード・グリッド(新着情報・検索結果、SPEC 6.2.2節/6.2.4節)
   スマホ1〜2列、PC3〜4列。画面幅に応じて自動調整する。
   --------------------------------------------------------------------------- */

.book-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.9rem;
}

@media (min-width: 620px) {
  .book-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .book-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.book-card {
  display: block;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.book-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.book-card .thumb-wrap {
  aspect-ratio: 3 / 4;
  background: var(--color-bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.book-card .thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card .thumb-wrap .no-thumb {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 0.5rem;
}

.book-card .body {
  padding: 0.55rem 0.6rem 0.7rem;
}

.book-card .title {
  font-size: 0.85rem;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.25rem;
}

.book-card .author {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card .meta-row {
  margin-top: 0.4rem;
}

/* 11〜50件目のリスト形式(SPEC 6.2.2節) */

.book-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--color-border);
}

.book-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.2rem;
  border-bottom: 1px solid var(--color-border);
}

.book-list li:nth-child(odd) {
  background: var(--color-table-row-alt);
}

.book-list a {
  color: var(--color-text);
  text-decoration: none;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-list a:hover {
  color: var(--color-primary);
}

.book-list .author {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* 図書館だよりバックナンバー(SPEC 6.2.2節) */

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

.newsletter-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.8rem;
  padding: 0.6rem 0.2rem;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.newsletter-list a {
  font-weight: 600;
  text-decoration: none;
}

.newsletter-list .summary {
  flex-basis: 100%;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

/* ---------------------------------------------------------------------------
   カード型クエリビルダー(SPEC 5章)
   --------------------------------------------------------------------------- */

.qb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.qb-toolbar select {
  width: auto;
}

.qb-field-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  margin-bottom: 0.7rem;
  background: var(--color-bg-alt);
}

.qb-field-block .qb-field-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.qb-field-block .qb-field-header strong {
  color: var(--color-primary);
}

.qb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.qb-row select,
.qb-row input {
  width: auto;
  flex: 1 1 120px;
  min-width: 90px;
}

.qb-row .qb-tilde {
  color: var(--color-text-muted);
}

.qb-add-field-menu {
  position: relative;
  display: inline-block;
}

.qb-add-field-menu .menu-list {
  position: absolute;
  z-index: 30;
  top: 100%;
  left: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  max-height: 280px;
  overflow-y: auto;
  min-width: 160px;
}

.qb-add-field-menu .menu-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  font: inherit;
}

.qb-add-field-menu .menu-list button:hover {
  background: var(--color-primary-light);
}

/* ---------------------------------------------------------------------------
   図書詳細画面(SPEC 6.2.5節)
   --------------------------------------------------------------------------- */

.book-detail {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 700px) {
  .book-detail {
    grid-template-columns: 220px 1fr;
  }
}

.book-detail .thumb-wrap {
  background: var(--color-bg-alt);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 260px;
}

.book-detail .thumb-wrap img {
  width: 100%;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.detail-table th,
.detail-table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.detail-table th {
  width: 8em;
  color: var(--color-text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   マイページ(SPEC 6.2.6節)
   --------------------------------------------------------------------------- */

.simple-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.simple-table th {
  background: var(--color-table-header);
  text-align: left;
  padding: 0.5rem 0.6rem;
  white-space: nowrap;
}

.simple-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
}

.simple-table tbody tr:nth-child(even) {
  background: var(--color-table-row-alt);
}

.simple-table-scroll {
  overflow-x: auto;
}

/* ---------------------------------------------------------------------------
   カレンダー閲覧(SPEC 6.2.7節)
   --------------------------------------------------------------------------- */

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.calendar-nav .month-label {
  font-weight: 700;
  font-size: 1.05rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-grid .dow {
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  padding-bottom: 0.3rem;
}

.calendar-cell {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  min-height: 54px;
  padding: 0.25rem;
  background: var(--color-bg);
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

@media (min-width: 620px) {
  .calendar-cell {
    min-height: 76px;
    font-size: 0.8rem;
  }
}

.calendar-cell:hover {
  border-color: var(--color-primary);
}

.calendar-cell.empty {
  visibility: hidden;
}

.calendar-cell .day-num {
  font-weight: 600;
}

.calendar-cell.today {
  outline: 2px solid var(--color-primary);
}

.calendar-cell .status-dot {
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  margin-right: 0.2em;
}

.dot-open {
  background: var(--color-success);
}

.dot-closed {
  background: var(--color-danger);
}

.dot-half {
  background: var(--color-warning);
}

.calendar-detail-panel {
  margin-top: 1rem;
}

/* ---------------------------------------------------------------------------
   ログイン画面(SPEC 6.2.1節)
   --------------------------------------------------------------------------- */

.login-wrap {
  max-width: 380px;
  margin: 10vh auto 0;
  padding: 0 1rem;
}

.login-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem 1.5rem;
}

.login-card h1 {
  font-size: 1.2rem;
  text-align: center;
}

.login-card .field {
  margin-bottom: 1rem;
}

.login-card .btn-primary {
  width: 100%;
  justify-content: center;
  margin-top: 0.4rem;
}

.login-note {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 1rem;
  text-align: center;
}

#google-signin-area {
  display: flex;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.login-divider {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  text-align: center;
  margin: 1rem 0;
}

/* ---------------------------------------------------------------------------
   ページネーション
   --------------------------------------------------------------------------- */

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.pagination .page-info {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------------
   ユーティリティ
   --------------------------------------------------------------------------- */

.flex-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.text-muted {
  color: var(--color-text-muted);
}

.text-danger {
  color: var(--color-danger);
}

.text-success {
  color: var(--color-success);
}

.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
