/*
Theme Name: 物品借用管理システム
Theme URI: https://neo-s.jp
Author: 株式会社ネオ
Author URI: https://neo-s.jp
Description: 物品の借用・返却・履歴管理を行うテーマ。メールアドレス + 6桁認証コードによる二段階認証付き。
Version: 1.5.3
License: GPL-2.0+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: loan-management
*/

:root {
  --lm-bg: #f5f3ee;
  --lm-bg-card: #ffffff;
  --lm-ink: #1a1a1a;
  --lm-ink-soft: #5a5a5a;
  --lm-ink-mute: #9a9a9a;
  --lm-line: #e2dfd6;
  --lm-accent: #c8553d;
  --lm-accent-soft: #f4e3dd;
  --lm-ok: #2d6a4f;
  --lm-ok-soft: #d8e8de;
  --lm-warn: #b8860b;
  --lm-warn-soft: #f5ecd3;
  --lm-danger: #9b2226;
  --lm-danger-soft: #f3dadb;
  --lm-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
  --lm-radius: 4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Manrope', 'Noto Serif JP', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--lm-bg);
  color: var(--lm-ink);
  line-height: 1.6;
  min-height: 100vh;
  padding: 2rem 1rem;
  background-image:
    radial-gradient(circle at 20% 0%, rgba(200, 85, 61, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 100%, rgba(45, 106, 79, 0.04) 0%, transparent 40%);
}

.lm-container { max-width: 1280px; margin: 0 auto; }
.lm-loading { text-align: center; padding: 3rem; color: var(--lm-ink-mute); }

/* === Login === */
.lm-login-card {
  max-width: 420px;
  margin: 4rem auto;
  background: var(--lm-bg-card);
  border: 1px solid var(--lm-line);
  border-radius: var(--lm-radius);
  padding: 2.5rem;
  box-shadow: var(--lm-shadow);
}
.lm-login-card h2 {
  font-family: 'Noto Serif JP', serif;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
}
.lm-login-subtitle {
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  color: var(--lm-ink-mute);
  text-transform: uppercase;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--lm-ink);
  padding-bottom: 1rem;
}
.lm-login-help {
  font-size: 0.85rem;
  color: var(--lm-ink-soft);
  margin-bottom: 1.25rem;
  line-height: 1.7;
}
.lm-login-help small { color: var(--lm-ink-mute); font-size: 0.75rem; }
.lm-error {
  background: var(--lm-danger-soft);
  color: var(--lm-danger);
  padding: 0.6rem 0.9rem;
  border-radius: var(--lm-radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.lm-info {
  background: var(--lm-ok-soft);
  color: var(--lm-ok);
  padding: 0.6rem 0.9rem;
  border-radius: var(--lm-radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.lm-step-back {
  background: none;
  border: none;
  color: var(--lm-ink-mute);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
  margin-top: 1rem;
  text-decoration: underline;
}
.lm-step-back:hover { color: var(--lm-ink); }
.lm-verify-code-input {
  text-align: center;
  font-size: 1.5rem !important;
  letter-spacing: 0.5em;
  font-family: monospace !important;
  font-weight: 700;
}
.lm-verify-meta {
  font-size: 0.85rem;
  color: var(--lm-ink-soft);
  margin-bottom: 1rem;
  line-height: 1.7;
}
.lm-verify-email { font-weight: 600; color: var(--lm-ink); }
.lm-verify-timer {
  text-align: center;
  font-size: 0.85rem;
  color: var(--lm-ink-mute);
  margin-top: 0.5rem;
}
.lm-verify-timer.lm-expired { color: var(--lm-danger); }
.lm-verify-resend {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.85rem;
}
.lm-verify-resend a {
  color: var(--lm-accent);
  cursor: pointer;
  text-decoration: underline;
}

/* === Header === */
.lm-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 2px solid var(--lm-ink);
  padding-bottom: 1.25rem;
  margin-bottom: 2.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.lm-brand h1 {
  font-family: 'Noto Serif JP', serif;
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--lm-ink);
}
.lm-brand .lm-subtitle {
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  color: var(--lm-ink-mute);
  text-transform: uppercase;
  margin-top: 0.25rem;
}
.lm-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
}
.lm-stats { display: flex; gap: 1.5rem; font-family: 'Noto Serif JP', serif; }
.lm-stat { text-align: right; }
.lm-stat .lm-num { font-size: 1.5rem; font-weight: 700; line-height: 1; color: var(--lm-ink); }
.lm-stat .lm-label {
  font-size: 0.65rem;
  color: var(--lm-ink-mute);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 0.2rem;
}
.lm-stat.lm-danger .lm-num { color: var(--lm-danger); }
.lm-stat.lm-warn .lm-num { color: var(--lm-warn); }
.lm-user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--lm-ink-soft);
}
.lm-user-info .lm-username { font-weight: 600; color: var(--lm-ink); }
.lm-role-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  background: var(--lm-accent);
  color: white;
  border-radius: 3px;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
}

/* === Tabs === */
.lm-tabs {
  display: flex;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--lm-line);
  flex-wrap: wrap;
}
.lm-tab {
  padding: 0.75rem 1.25rem;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--lm-ink-mute);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.lm-tab:hover { color: var(--lm-ink); }
.lm-tab.lm-active { color: var(--lm-ink); border-bottom-color: var(--lm-accent); }
.lm-tab .lm-count {
  display: inline-block;
  background: var(--lm-line);
  color: var(--lm-ink-soft);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  margin-left: 0.4rem;
}
.lm-tab.lm-active .lm-count { background: var(--lm-accent); color: white; }

/* === Toolbar === */
.lm-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  align-items: center;
}
.lm-search { flex: 1; min-width: 200px; position: relative; }
.lm-search input {
  width: 100%;
  padding: 0.65rem 0.9rem 0.65rem 2.25rem;
  border: 1px solid var(--lm-line);
  border-radius: var(--lm-radius);
  background: var(--lm-bg-card);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--lm-ink);
}
.lm-search input:focus { outline: none; border-color: var(--lm-accent); }
.lm-search::before {
  content: "⌕";
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--lm-ink-mute);
  font-size: 1rem;
  pointer-events: none;
}

/* === Buttons === */
.lm-btn {
  padding: 0.65rem 1.1rem;
  border: 1px solid var(--lm-ink);
  background: var(--lm-ink);
  color: white;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--lm-radius);
  white-space: nowrap;
  text-decoration: none;
  display: inline-block;
}
.lm-btn:hover { background: #000; color: white; }
.lm-btn.lm-secondary { background: transparent; color: var(--lm-ink); }
.lm-btn.lm-secondary:hover { background: var(--lm-ink); color: white; }
.lm-btn.lm-accent { background: var(--lm-accent); border-color: var(--lm-accent); }
.lm-btn.lm-accent:hover { background: #a8412d; border-color: #a8412d; }
.lm-btn.lm-small { padding: 0.35rem 0.7rem; font-size: 0.75rem; }
.lm-btn.lm-danger { background: transparent; color: var(--lm-danger); border-color: var(--lm-danger); }
.lm-btn.lm-danger:hover { background: var(--lm-danger); color: white; }
.lm-btn.lm-block { display: block; width: 100%; }

/* === Panel & Table === */
.lm-panel {
  background: var(--lm-bg-card);
  border: 1px solid var(--lm-line);
  border-radius: var(--lm-radius);
  overflow-x: auto;
  box-shadow: var(--lm-shadow);
}
.lm-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.lm-table thead th {
  text-align: left;
  padding: 0.85rem 1rem;
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--lm-ink-mute);
  border-bottom: 1px solid var(--lm-line);
  background: #fafaf7;
}
.lm-table tbody td { padding: 0.9rem 1rem; border-bottom: 1px solid var(--lm-line); vertical-align: middle; }
.lm-table tbody tr:last-child td { border-bottom: none; }
.lm-table tbody tr:hover { background: #fafaf7; }
.lm-table td.lm-actions { text-align: right; white-space: nowrap; }
.lm-table td.lm-actions .lm-btn { margin-left: 0.4rem; }

.lm-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}
.lm-badge.lm-borrowed { background: var(--lm-warn-soft); color: var(--lm-warn); }
.lm-badge.lm-overdue { background: var(--lm-danger-soft); color: var(--lm-danger); }
.lm-badge.lm-returned { background: var(--lm-line); color: var(--lm-ink-soft); }

.lm-empty { padding: 3rem 1rem; text-align: center; color: var(--lm-ink-mute); font-size: 0.9rem; }
.lm-empty .lm-icon { font-size: 2rem; display: block; margin-bottom: 0.5rem; opacity: 0.4; }

.lm-overdue-row { background: rgba(155, 34, 38, 0.04); }
.lm-purpose-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--lm-accent-soft);
  color: var(--lm-accent);
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
}
.lm-item-meta { font-size: 0.75rem; color: var(--lm-ink-mute); margin-top: 0.15rem; }

/* === Modal === */
.lm-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.lm-modal-backdrop.lm-show { display: flex; }
.lm-modal {
  background: var(--lm-bg-card);
  border-radius: var(--lm-radius);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.lm-modal.lm-modal-wide { max-width: 880px; }
.lm-modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--lm-line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.lm-modal-header h2 { font-family: 'Noto Serif JP', serif; font-size: 1.15rem; font-weight: 700; margin: 0; }
.lm-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--lm-ink-mute); line-height: 1; padding: 0; }
.lm-modal-body { padding: 1.5rem; }
.lm-modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--lm-line);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.lm-form-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--lm-accent);
  margin: 0.25rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--lm-accent-soft);
}
.lm-form-section-title:not(:first-child) { margin-top: 1.5rem; }
.lm-form-row { margin-bottom: 1rem; }
.lm-form-row label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lm-ink-soft);
  margin-bottom: 0.35rem;
}
.lm-form-row input,
.lm-form-row textarea,
.lm-form-row select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--lm-line);
  border-radius: var(--lm-radius);
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--lm-bg-card);
  color: var(--lm-ink);
}
.lm-form-row input:focus,
.lm-form-row textarea:focus,
.lm-form-row select:focus { outline: none; border-color: var(--lm-accent); }
.lm-form-row textarea { resize: vertical; min-height: 70px; }
.lm-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* === Detail view === */
.lm-detail-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.875rem;
}
.lm-detail-grid dt {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lm-ink-mute);
  padding-top: 0.15rem;
}
.lm-detail-grid dd {
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--lm-line);
  word-break: break-word;
  margin: 0;
}
.lm-detail-grid dd:last-of-type { border-bottom: none; }
.lm-detail-section-title {
  font-family: 'Noto Serif JP', serif;
  font-size: 0.95rem;
  font-weight: 700;
  margin: 1rem 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid var(--lm-ink);
}
.lm-detail-section-title:first-child { margin-top: 0; }

/* 詳細モーダル内のアクションボタン群（デスクトップ） */
.lm-detail-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--lm-line);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.lm-domain-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: #fafaf7;
  border: 1px solid var(--lm-line);
  border-radius: 4px;
  margin-bottom: 0.4rem;
}
.lm-domain-row code { font-family: monospace; font-size: 0.9rem; }

/* === Footer === */
.lm-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--lm-line);
  font-size: 0.75rem;
  color: var(--lm-ink-mute);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.lm-footer a { color: var(--lm-ink-soft); cursor: pointer; text-decoration: underline; }
/* === Domain / admin row: long content guard === */
.lm-domain-row { flex-wrap: wrap; gap: 0.4rem; }
.lm-domain-row code { word-break: break-all; flex: 1 1 200px; min-width: 0; }

/* === Responsive: tablet (≤700px) === */
@media screen and (max-width: 700px) {
  body { padding: 1rem 0.5rem; }

  /* ヘッダー */
  .lm-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
  .lm-header-right { align-items: flex-start; width: 100%; }
  .lm-stats { gap: 1rem; flex-wrap: wrap; row-gap: 0.75rem; }
  .lm-stat { text-align: left; min-width: 70px; }
  .lm-stat .lm-num { font-size: 1.25rem; }
  .lm-user-info { flex-wrap: wrap; gap: 0.4rem 0.6rem; }

  /* ツールバー */
  .lm-toolbar { gap: 0.5rem; }
  .lm-search { flex: 1 1 100%; min-width: 0; }
  .lm-toolbar > select,
  .lm-toolbar > .lm-btn { flex: 1 1 auto; min-width: 0; }

  /* タブ */
  .lm-tab { padding: 0.65rem 0.85rem; font-size: 0.85rem; }
  .lm-tab .lm-count { margin-left: 0.3rem; padding: 0.05rem 0.4rem; }

  /* テーブル → コンパクトリスト化（1項目1行、タップで詳細） */
  .lm-panel { overflow-x: visible; border-radius: var(--lm-radius); }
  .lm-table thead { display: none; }
  .lm-table tbody { display: block; }
  .lm-table tbody tr {
    display: flex !important;
    align-items: center;
    gap: 0.6rem;
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid var(--lm-line);
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(200, 85, 61, 0.12);
  }
  .lm-table tbody tr:last-child { border-bottom: none; }
  .lm-table tbody tr:active { background: rgba(200, 85, 61, 0.06); }

  /* デフォルトで非表示。物品名と状態だけ表示 */
  .lm-table tbody td {
    display: none !important;
    padding: 0;
    border: none;
  }
  .lm-table tbody td[data-label]::before { display: none !important; }

  /* 物品列：左側に伸びる主要情報 */
  .lm-table tbody td[data-label="物品"] {
    display: block !important;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
  }
  .lm-table tbody td[data-label="物品"] strong {
    font-size: 0.95rem;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .lm-table tbody td[data-label="物品"] .lm-item-meta {
    font-size: 0.7rem;
    margin-top: 0.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 借用者を物品列の補助情報として擬似的に追加（::after で構造を変えずに表示） */
  .lm-table tbody td[data-label="借用者"] {
    display: block !important;
    flex: 0 1 auto;
    font-size: 0.75rem;
    color: var(--lm-ink-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 35%;
  }
  .lm-table tbody td[data-label="借用者"] .lm-item-meta { display: none; }

  /* 状態バッジ */
  .lm-table tbody td[data-label="状態"] {
    display: block !important;
    flex: 0 0 auto;
  }

  /* 行右端のシェブロン */
  .lm-table tbody tr::after {
    content: "›";
    color: var(--lm-ink-mute);
    font-size: 1.4rem;
    font-weight: 300;
    flex: 0 0 auto;
    line-height: 1;
    margin-left: -0.2rem;
  }

  /* 行内のアクションボタンはモバイルでは非表示（詳細モーダルから操作） */
  .lm-table td.lm-actions { display: none !important; }

  /* 詳細モーダル内のアクションボタン群：モバイルではフルワイドで縦積み */
  .lm-detail-actions {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--lm-line);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  .lm-detail-actions .lm-btn { width: 100%; min-height: 44px; }

  /* モーダル */
  .lm-modal-backdrop { padding: 0; align-items: stretch; }
  .lm-modal {
    max-height: 100vh;
    border-radius: 0;
    width: 100vw;
    max-width: 100vw;
  }
  .lm-modal-header { padding: 1rem 1.1rem; }
  .lm-modal-header h2 { font-size: 1.05rem; }
  .lm-modal-body { padding: 1rem 1.1rem; }
  .lm-modal-footer {
    padding: 0.85rem 1.1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .lm-modal-footer .lm-btn { flex: 1 1 auto; min-width: 110px; }

  /* 詳細グリッド：縦積み */
  .lm-detail-grid {
    grid-template-columns: 1fr;
    gap: 0.1rem 0;
  }
  .lm-detail-grid dt {
    padding-top: 0.5rem;
    padding-bottom: 0;
    border-bottom: none;
  }
  .lm-detail-grid dd {
    padding-bottom: 0.5rem;
    padding-left: 0;
  }

  /* フォーム */
  .lm-form-grid { grid-template-columns: 1fr; }
  .lm-form-row label { font-size: 0.7rem; }

  /* ボタンタップ領域：最低44px */
  .lm-btn { min-height: 44px; padding: 0.7rem 1rem; }
  .lm-btn.lm-small { min-height: 36px; padding: 0.45rem 0.7rem; font-size: 0.8rem; }

  /* ドメイン/管理者行：縦展開 */
  .lm-domain-row { padding: 0.6rem 0.75rem; }
  .lm-domain-row code { font-size: 0.85rem; }

  /* フッター */
  .lm-footer { flex-direction: column; align-items: flex-start; }
}

/* === Responsive: phone (≤480px) === */
@media screen and (max-width: 480px) {
  body { padding: 0.75rem 0.4rem; }

  .lm-brand h1 { font-size: 1.2rem; }
  .lm-brand .lm-subtitle { font-size: 0.6rem; letter-spacing: 0.2em; }

  /* タブ：もっと縮める */
  .lm-tab { padding: 0.55rem 0.7rem; font-size: 0.8rem; }

  /* 認証コード入力欄：letter-spacing控えめに */
  .lm-verify-code-input {
    font-size: 1.3rem !important;
    letter-spacing: 0.35em;
    padding-left: 0.35em !important; /* 中央揃え調整 */
  }

  /* ログインカード */
  .lm-login-card { margin: 1.5rem auto; padding: 1.5rem 1.2rem; }
  .lm-login-card h2 { font-size: 1.25rem; }

  /* ボタン文字サイズ */
  .lm-btn { font-size: 0.85rem; }

  /* 統計：更にコンパクト */
  .lm-stats { gap: 0.75rem; }
  .lm-stat .lm-num { font-size: 1.1rem; }
  .lm-stat .lm-label { font-size: 0.6rem; letter-spacing: 0.1em; }
}

/* === Print === */
.lm-print-only { display: none; }

@media print {
  /* A4 縦・余白指定 — ブラウザのデフォルトヘッダー/フッター（URL・日時・ページ番号）を
     CSS Paged Media で空指定にして抑制（対応ブラウザのみ）。
     非対応ブラウザでは印刷ダイアログの「ヘッダーとフッター」のチェックを外して頂く必要があります。 */
  @page {
    size: A4 portrait;
    margin: 10mm 12mm;
    @top-left { content: ""; }
    @top-center { content: ""; }
    @top-right { content: ""; }
    @bottom-left { content: ""; }
    @bottom-center { content: ""; }
    @bottom-right { content: ""; }
  }

  /* 背景・カラーリセット */
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    background: none !important;
    background-image: none !important;
    color: #000 !important;
    -webkit-print-color-adjust: economy;
    print-color-adjust: economy;
  }

  /* Step 1: モーダル以外の body 直下要素を全部非表示 */
  body > *:not(.lm-modal-backdrop) { display: none !important; }

  /* Step 2: モーダルチェーンを「箱なし」にして子要素を body 直下扱いに */
  .lm-modal-backdrop,
  .lm-modal,
  .lm-modal-body {
    display: contents !important;
  }

  /* Step 3: モーダル内のヘッダー・フッター・印刷エリア以外を全て非表示 */
  .lm-modal-header,
  .lm-modal-footer,
  .lm-modal-body > *:not(.lm-print-area) {
    display: none !important;
  }

  /* Step 4: 印刷エリア本体 — 自然なブロックフローでページ先頭に配置 */
  .lm-print-area {
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: none !important;
    box-shadow: none !important;
    border: none !important;
    position: static !important;
    font-size: 9.5pt;
    line-height: 1.45;
    color: #000;
  }

  /* 印刷専用要素を表示 */
  .lm-print-only { display: block !important; }

  /* セクション見出し */
  .lm-print-area .lm-detail-section-title {
    font-size: 10.5pt;
    margin: 0.45rem 0 0.2rem;
    padding-bottom: 0.15rem;
    border-bottom: 1.5px solid #000;
    color: #000;
    page-break-after: avoid;
    break-after: avoid;
  }
  .lm-print-area .lm-detail-section-title:first-child { margin-top: 0; }

  /* 詳細グリッド：印刷時は2カラム固定（モバイルの縦積みを上書き） */
  .lm-print-area .lm-detail-grid {
    display: grid !important;
    grid-template-columns: 80px 1fr !important;
    gap: 0.15rem 0.6rem !important;
    font-size: 9.5pt;
  }
  .lm-print-area .lm-detail-grid dt {
    color: #555 !important;
    padding-top: 0.1rem !important;
    padding-bottom: 0 !important;
    font-size: 7.8pt !important;
    border-bottom: none !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    font-weight: 600 !important;
  }
  .lm-print-area .lm-detail-grid dd {
    padding-left: 0 !important;
    padding-bottom: 0.2rem !important;
    border-bottom: 1px solid #ccc !important;
    color: #000 !important;
    margin: 0 !important;
  }

  /* バッジ・タグ：背景なし白黒枠 */
  .lm-print-area .lm-badge,
  .lm-print-area .lm-purpose-tag {
    background: none !important;
    border: 1px solid #555 !important;
    color: #000 !important;
    padding: 0.05rem 0.4rem !important;
    font-size: 8pt !important;
  }

  /* 印刷ヘッダー：タイトル＋メタ情報 */
  .lm-print-header {
    display: flex !important;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 2px solid #000;
    padding-bottom: 0.35rem;
    margin: 0 0 0.6rem !important;
    page-break-after: avoid;
    break-after: avoid;
  }
  .lm-print-header h1 {
    font-family: 'Noto Serif JP', serif;
    font-size: 16pt;
    font-weight: 700;
    letter-spacing: 0.15em;
    margin: 0;
    color: #000;
  }
  .lm-print-header-meta {
    font-size: 8.5pt;
    color: #000;
    text-align: right;
    line-height: 1.4;
    display: block;
    margin: 0;
  }
  .lm-print-header-meta > div { display: block; }
  .lm-print-header-meta dt {
    display: inline;
    color: #777;
    font-size: 7pt;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0 !important;
    border: none !important;
    font-weight: 400 !important;
  }
  .lm-print-header-meta dd {
    display: inline;
    margin: 0 0 0 0.4em;
    padding: 0 !important;
    border: none !important;
    font-weight: 600;
    color: #000;
  }

  /* 承認印欄 */
  .lm-print-seals {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 0.7rem !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .lm-print-seal-box {
    border: 1px solid #000;
    text-align: center;
    height: 22mm;
    display: flex;
    flex-direction: column;
    background: none !important;
  }
  .lm-print-seal-label {
    font-size: 8pt;
    letter-spacing: 0.2em;
    background: #000 !important;
    color: #fff !important;
    padding: 0.15rem 0;
    font-weight: 600;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .lm-print-seal-name {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9pt;
    color: #000;
    padding: 0.3rem;
  }

  /* 改ページ抑制 */
  .lm-print-area > * { page-break-inside: avoid; break-inside: avoid; }
}
