/* パンセノート — 標準的な読みやすさ優先のスタイル */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --fg: #1a1a1a;
  --card: #ffffff;
  --border: #c8ccd4;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #b91c1c;
  --muted: #5c6370;
  --voice-pastel-search-bg: #cfe8ff;
  --voice-pastel-search-border: #9ec5f0;
  --voice-pastel-search-fg: #1e3a5f;
  --voice-pastel-register-bg: #fff3bf;
  --voice-pastel-register-border: #e8d48b;
  --voice-pastel-register-fg: #5c4a1a;
  --btn-save-green: #e1ffe1;
  --btn-save-green-hover: #d4f6d4;
  --btn-save-green-border: #4caf50;
  --btn-save-green-fg: #000000;
  --btn-delete-red: #ffcdcd;
  --btn-delete-red-hover: #ffc1c1;
  --btn-delete-red-border: #ff5050;
  --btn-delete-red-fg: #000000;
  --form-input-large: 1.05rem;
  --floating-ui-top: 8.5rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Sans",
    "Noto Sans JP", sans-serif;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --fg: #eef0f4;
    --card: #1c1f26;
    --border: #3d4453;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --danger: #f87171;
    --muted: #a8b0c0;
    --voice-pastel-search-bg: #1a3a52;
    --voice-pastel-search-border: #3d6a8a;
    --voice-pastel-search-fg: #dbeafe;
    --voice-pastel-register-bg: #4a4420;
    --voice-pastel-register-border: #8a7a40;
    --voice-pastel-register-fg: #fef3c7;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
}

body.orientation-locked {
  overflow: hidden;
}

.orientation-lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 6000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(15, 23, 42, 0.9);
}

body.orientation-locked .orientation-lock-overlay {
  display: flex;
}

.orientation-lock-box {
  width: min(100%, 24rem);
  padding: 1.25rem 1rem;
  border-radius: 14px;
  background: var(--card);
  color: var(--fg);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.orientation-lock-title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.orientation-lock-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.app-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

/* ======================================================
   ヘッダー — 基本（PC / 768px 以上）
   ====================================================== */

.app-header {
  margin-bottom: 0.5rem;
}

/* 上段: ロゴ（左）＋ボタン群（右） */
.header-top-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem 0.75rem;
}

/* ロゴブロック: 画像と副題（PC用）を縦に並べ、中央揃え */
.app-logo-block {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app-logo {
  height: 100px;
  width: auto;
  display: block;
}

/* 副題 */
.subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  text-align: center;
}

/* PC: ロゴブロック内副題を表示 */
.subtitle-desktop { display: block; }
/* SP/タブレット: header-sub-row 内副題（デフォルト非表示） */
.subtitle-sp      { display: none; }

/* 右ブロック */
.header-right-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  margin-left: auto;
}

/* データ操作ボタン群 */
.header-data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  align-items: center;
}

.header-secondary-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* flex break: デフォルト非表示（スマホで設定ボタンを次行に押し出す） */
.hdr-break {
  display: none;
  flex-basis: 100%;
  height: 0;
}

/* ボタンラベル切替（PC/タブレット=フル、スマホ=短縮） */
.lbl-narrow { display: none;   }
.lbl-wide   { display: inline; }

/* 件数情報 */
.plan-summary {
  margin: 0;
  text-align: right;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}

/* PC用: 右ブロック内（デフォルト表示） */
.plan-summary-pc { display: block; }
/* SP/タブレット用: header-sub-row 内（デフォルト非表示） */
.plan-summary-sp { display: none; }

/* スマホ向け小フォント日本語ラベル（ps-j） */
.ps-j {
  font-size: 0.72em;
  font-weight: normal;
}

button.sm-header {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

button.btn-demo-trigger {
  padding: 0.22rem 0.55rem;
  min-width: 0;
  font-size: 0.76rem;
  font-weight: 700;
  color: #ffffff;
  background: #d92323;
  border-color: #a60d0d;
}

button.btn-demo-trigger:hover:not(:disabled) {
  background: #bf1717;
  border-color: #8f0d0d;
}

/* 設定パネル表示中: メインへ戻る（薄い青背景・文字は黒） */
#btn-settings-toggle.btn-settings-home {
  background: #cfe7ff;
  border-color: #9ec5f0;
  color: #000000;
}

#btn-settings-toggle.btn-settings-home:hover {
  background: #b8d9f7;
  border-color: var(--accent);
}

button.btn-header-import {
  padding: 0.3rem 0.45rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* 副題＋件数情報行（PC では非表示） */
.header-sub-row {
  display: none;
}

/* 音声ボタン行（常に中央配置、ヘッダー最下部） */
.voice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
  justify-content: center;
  align-items: stretch;
}

/* ======================================================
   タブレット・スマホ寄り（880px 以下）
   ====================================================== */
@media (max-width: 880px) {
  /* 副題を sub-row へ切替 */
  .subtitle-desktop { display: none; }
  .subtitle-sp      { display: block; }

  /* 件数情報を sub-row へ切替 */
  .plan-summary-pc { display: none; }
  .plan-summary-sp { display: block; }

  /* 副題（左）＋件数情報（右）を1行に */
  .header-sub-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.2rem;
  }

  .header-sub-row .subtitle-sp {
    margin: 0;
    text-align: left;
    flex-shrink: 0;
  }

  .header-sub-row .plan-summary-sp {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-align: right;
    font-size: 0.85rem;
  }
}

.inline-warning {
  margin: -0.35rem 0 0.75rem;
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 600;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  padding: 0.45rem 0.85rem;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary,
a.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover,
a.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.btn-action-green {
  background: var(--btn-save-green);
  border-color: var(--btn-save-green-border);
  color: var(--btn-save-green-fg);
  font-weight: 700;
}

button.btn-action-green:hover:not(:disabled) {
  background: var(--btn-save-green-hover);
  border-color: var(--btn-save-green-border);
  color: var(--btn-save-green-fg);
}

button.btn-action-green:focus-visible {
  outline: 2px solid var(--btn-save-green-border);
  outline-offset: 2px;
}

button.btn-action-green:disabled {
  background: #E3E3E3;
  border-color: #E3E3E3;
  color: #C1C1C1;
  cursor: not-allowed;
  opacity: 1;
}

button.btn-action-delete {
  background: var(--btn-delete-red);
  border-color: var(--btn-delete-red-border);
  color: var(--btn-delete-red-fg);
}

button.btn-action-delete:hover {
  background: var(--btn-delete-red-hover);
  border-color: var(--btn-delete-red-border);
  color: var(--btn-delete-red-fg);
}

button.btn-action-delete:focus-visible {
  outline: 2px solid var(--btn-delete-red-border);
  outline-offset: 2px;
}
button.btn-action-delete:disabled {
  background: #ccc;
  border-color: #ccc;
  color: #888;
  cursor: not-allowed;
  opacity: 0.55;
}

button.voice-lg {
  min-height: 4rem;
  min-width: 0;
  max-width: 16rem;
  flex: 0 0 auto;
  width: auto;
  padding: 0.55rem 0.85rem;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  white-space: normal;
}

button.voice-btn {
  border-radius: 6px;
  border-width: 2px;
  white-space: normal;
}

/* 案A: マイクをタイトル行に統合、サブテキストはボタン全幅 */
.voice-btn-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 0.15rem;
}

.voice-btn-title-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.voice-btn-mic {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  opacity: 0.85;
}

.voice-btn-mic svg {
  display: block;
}

.voice-btn-title {
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
}

/* 音声検索ボタンのタイトルはやや大きく */
button.voice-btn-search .voice-btn-title {
  font-size: 1.15rem;
}

.voice-btn-sub {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.9;
  display: block;
  line-height: 1.3;
  white-space: nowrap;
}

#voice-register-sub-primary,
#voice-register-sub-secondary {
  width: 100%;
  text-align: center;
}

#voice-register-sub-secondary {
  min-height: 1.3em;
}

button.voice-btn-search {
  background: var(--voice-pastel-search-bg);
  border-color: var(--voice-pastel-search-border);
  color: var(--voice-pastel-search-fg);
}

button.voice-btn-search:hover {
  filter: brightness(0.97);
}

button.voice-btn-register {
  background: var(--voice-pastel-register-bg);
  border-color: var(--voice-pastel-register-border);
  color: var(--voice-pastel-register-fg);
}

button.voice-btn-register:hover {
  filter: brightness(0.97);
}

button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

#manual-search {
  flex: 1 1 220px;
  min-width: 0;
  font: inherit;
  font-size: var(--form-input-large);
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
}

#btn-search {
  font-size: var(--form-input-large);
  font-weight: 600;
  padding: 0.5rem 0.85rem;
  background: var(--voice-pastel-search-bg);
  border-color: var(--voice-pastel-search-border);
  color: var(--voice-pastel-search-fg);
}

#btn-search:hover {
  filter: brightness(0.97);
}

.search-meta {
  min-height: 1.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.search-meta.has-result {
  color: #c0392b;
  font-weight: 700;
  font-size: 0.97rem;
}

@media (prefers-color-scheme: dark) {
  .search-meta.has-result {
    color: #f87171;
  }
}

.table-wrap {
  overflow-x: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

table.entries-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: 0.9rem;
  table-layout: fixed;
  border: 1px solid var(--border);
}

.entries-table col.col-title {
  width: auto;
  min-width: 0;
}

.entries-table col.col-booknum {
  width: 8rem;
}

.entries-table col.col-actions {
  width: 14rem;
  min-width: 14rem;
}

table.entries-table.voice-register-mode col.col-actions {
  width: 12rem;
  min-width: 12rem;
}

th,
td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.5rem;
  vertical-align: middle;
}

.entries-table thead th {
  border-bottom: 2px solid var(--border);
}

th {
  text-align: left;
  background: rgba(0, 0, 0, 0.055);
  white-space: nowrap;
}

.entries-table th.th-booknum {
  text-align: center;
}

.entries-table th.th-title {
  text-align: left;
}

.entries-table th.th-actions {
  text-align: center;
}

.entries-table tr.row-tappable {
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  th {
    background: rgba(255, 255, 255, 0.04);
  }
}

.entries-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.028);
}

@media (prefers-color-scheme: dark) {
  .entries-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.04);
  }
}

td input.inline {
  width: 100%;
  min-width: 0;
  font: inherit;
  padding: 0.25rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
}

td textarea.inline {
  width: 100%;
  min-width: 0;
  font: inherit;
  padding: 0.25rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
  box-sizing: border-box;
}

.entries-table td.col-title input.inline {
  font-size: var(--form-input-large);
}

.entries-table td.col-title textarea.inline {
  font-size: var(--form-input-large);
}

.title-display-readonly {
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
  font-size: var(--form-input-large);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
}

.title-display-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

.title-display-row .title-display-readonly {
  flex: 1 1 auto;
}

.title-cell {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  min-width: 0;
}

.title-cell input.inline,
.title-cell textarea.inline {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.title-cell textarea.desktop-title-textarea {
  line-height: 1.35;
  resize: none;
}

.memo-indicator {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.35rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: #dbeafe;
  color: #3b82f6;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.memo-indicator.is-hidden {
  visibility: hidden;
}

.title-cell .row-memo {
  flex: 0 0 auto;
  margin: 0;
}

.title-cell .btn-memo {
  width: 3.8rem;
  min-width: 3.8rem;
  max-width: 3.8rem;
}

/* 冊目・頁 統合セル */
td.col-booknum {
  text-align: center;
  padding: 0.2rem 0.3rem;
}

.booknum-wrap {
  display: flex;
  flex-direction: row;
  gap: 0.3rem;
  justify-content: center;
  align-items: center;
}

.booknum-wrap input.inline-num {
  width: 3rem;
  max-width: 3rem;
  min-width: 0;
  text-align: center;
  font-size: var(--form-input-large);
  font-variant-numeric: tabular-nums;
  display: block;
  margin: 0;
}

.readonly-box {
  display: block;
  width: 3rem;
  max-width: 3rem;
  min-width: 0;
  min-height: 1.9rem;
  text-align: center;
  font-size: var(--form-input-large);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  padding: 0.25rem 0.1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
  box-sizing: border-box;
}

.readonly-box:empty::before {
  content: "\00a0";
}

td.col-title {
  width: auto;
  min-width: 16.8rem;
}

td.readonly {
  color: var(--muted);
  white-space: nowrap;
}

.actions {
  text-align: center;
  white-space: nowrap;
}

.actions button {
  margin: 0.15rem;
  vertical-align: middle;
}

.entries-table td.col-actions {
  white-space: nowrap;
  width: 14rem;
  min-width: 14rem;
  max-width: 14rem;
  box-sizing: border-box;
  vertical-align: middle;
}

.entries-table td.col-actions.voice-register-actions {
  width: 12rem;
  min-width: 12rem;
  max-width: 12rem;
}

/* メモボタン */
button.btn-memo {
  background: #ffffff;
  border-color: var(--border);
  color: #000000;
}

button.btn-memo.has-memo {
  background: #CFE7FF;
}

button.btn-memo:hover {
  border-color: var(--accent);
}

button.btn-memo.memo-active {
  border-color: var(--accent);
  font-weight: 700;
}

button.btn-action-ai {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.entries-table td.col-actions .row-ai-search {
  font-size: 0.75rem;
  font-weight: 400;
  padding: 0.25rem 0.35rem;
}

.entries-table td.col-actions .row-delete {
  font-size: 0.85rem;
  font-weight: 400;
  padding: 0.35rem 0.45rem;
  margin-right: 0.4rem;
}

button.btn-action-ai:hover {
  background: #bfdbfe;
  border-color: #60a5fa;
}

@media (prefers-color-scheme: dark) {
  button.btn-memo {
    background: #f0f0f0;
    color: #000000;
  }
  button.btn-memo.has-memo {
    background: #CFE7FF;
  }
  button.btn-action-ai {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1d4ed8;
  }
}

/* メモ展開行 */
tr.memo-row td.memo-cell {
  padding: 0.3rem 0.5rem 0.5rem 0.5rem;
  background: var(--card);
  border-top: none;
}

.memo-photo-layout {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
}

.memo-photo-layout > .memo-textarea,
.memo-photo-layout > .memo-photo-textarea,
.memo-photo-layout > .mobile-edit-field {
  flex: 1 1 auto;
  min-width: 0;
}

.memo-photo-layout > .mobile-edit-field {
  margin-bottom: 0;
}

.memo-photo-layout > .photo-thumb-wrap,
.memo-photo-layout > #mobile-edit-photo-slot {
  flex: 0 0 7rem;
  width: 7rem;
  min-width: 7rem;
}

.memo-textarea {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: var(--form-input-large);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  resize: vertical;
  display: block;
  box-sizing: border-box;
}

.photo-thumb-wrap {
  margin: 0 0 0.6rem;
}

.memo-photo-layout .photo-thumb-wrap {
  margin: 0;
}

.photo-thumb-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 7rem;
  min-height: 5rem;
  padding: 0.2rem;
  background: var(--bg);
  border: 1px solid var(--border);
}

.photo-thumb-image {
  display: block;
  max-width: 100%;
  max-height: 10rem;
  border-radius: 6px;
}

.memo-photo-layout .photo-thumb-button {
  width: 100%;
  min-width: 0;
}

.memo-photo-layout #mobile-edit-photo-slot[hidden] {
  display: none !important;
}

.photo-thumb-placeholder {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

button.sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

.entries-table td.col-actions button.sm {
  font-size: var(--form-input-large);
  font-weight: 600;
  padding: 0.35rem 0.55rem;
  flex-shrink: 0;
}

/* 設定パネル（details要素の代替、JS制御で排他表示） */
.settings-panel {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  background: var(--card);
}

.settings-panel-title {
  font-weight: 600;
  font-size: 1rem;
  margin: 0 0 0.75rem;
  color: var(--fg);
}

.settings-body {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.settings-body ul {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
}

.settings-lead {
  color: var(--fg);
  margin: 0 0 0.75rem;
}

.settings-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.settings-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.45rem 0.85rem;
  font-weight: 600;
}

.license-self-service-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.9rem;
  margin-bottom: 0.55rem;
}

.license-self-service-row .settings-link-button {
  background: #f6f9fc;
  color: var(--fg);
}

#btn-force-refresh {
  background: #f6f9fc;
  border-color: var(--border);
  color: var(--fg);
}

.license-maintenance-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  z-index: 2066;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.license-maintenance-overlay[hidden] {
  display: none;
}

.license-maintenance-dialog {
  width: min(100%, 32rem);
  max-height: min(90vh, 40rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
}

.license-maintenance-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.license-maintenance-title {
  margin: 0;
  font-size: 1.08rem;
}

#license-maintenance-close {
  position: static;
  justify-self: end;
}

.license-maintenance-body {
  overflow-y: auto;
  padding: 1rem;
}

.license-maintenance-lead,
.license-maintenance-flow,
.license-maintenance-note,
.license-maintenance-status {
  margin: 0;
  line-height: 1.65;
}

.license-maintenance-flow,
.license-maintenance-note {
  margin-top: 0.75rem;
}

.license-maintenance-note {
  color: var(--muted);
  font-size: 0.92rem;
}

.license-maintenance-status {
  margin-top: 0.75rem;
  color: var(--danger);
  font-size: 0.92rem;
}

.license-maintenance-status[hidden] {
  display: none;
}

.license-maintenance-label {
  display: block;
  margin-top: 0.95rem;
  margin-bottom: 0.35rem;
  font-weight: 700;
}

.license-maintenance-input {
  width: 100%;
  min-width: 0;
  font: inherit;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
}

.license-maintenance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.license-maintenance-actions .settings-license-btn,
.license-maintenance-actions .settings-link-button {
  min-height: 2.5rem;
}

#btn-device-transfer {
  background: #cfe7ff;
  border-color: #9ec5f0;
  color: #000000;
  font-weight: 700;
}

#btn-device-transfer:hover {
  background: #b8d9f7;
  border-color: var(--accent);
}

#btn-plan-up {
  background: #f6c6ad;
  border-color: #ef9867;
  color: #000000;
  font-weight: 700;
}

#btn-plan-up:hover {
  background: #f3b493;
  border-color: #ef9867;
}

#btn-license-activate {
  background: #cfe7ff;
  border-color: #9ec5f0;
  color: #000000;
  font-weight: 700;
}

#btn-license-activate:hover:not(:disabled) {
  background: #b8d9f7;
  border-color: var(--accent);
}

.settings-link-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.user-settings-section {
  margin-top: 0.9rem;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.plan-up-section {
  margin-top: 0;
}

.user-settings-title {
  margin: 0 0 0.75rem;
  color: var(--fg);
  font-weight: 600;
}

.plan-up-action-row {
  align-items: center;
  margin-bottom: 0.55rem;
}

.plan-up-note {
  margin: 0;
  color: var(--fg);
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.settings-check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--fg);
  margin-bottom: 0.8rem;
}

.demo-settings-row {
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.settings-check-row input {
  margin: 0;
}

.settings-field-label {
  display: block;
  margin: 0 0 0.35rem;
  color: var(--fg);
  font-weight: 600;
}

.settings-field-label-transfer {
  margin-top: 0.8rem;
}

.settings-select {
  width: 100%;
  max-width: 220px;
  font: inherit;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}

.transfer-action-row {
  margin-top: 0.25rem;
  margin-bottom: 0;
}

#btn-device-transfer {
  width: 100%;
  max-width: 26rem;
}

/* ======================================================
   直近音声認識ログ（開発者用）
   ====================================================== */

.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.1rem 0 0.75rem;
}

.voice-log-toggle-btn {
  width: 100%;
  text-align: left;
  font-size: 0.88rem;
  font-weight: 600;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.3rem 0;
  color: var(--muted);
  cursor: pointer;
}

.voice-log-toggle-btn:hover {
  color: var(--fg);
}

.voice-log-body {
  padding-top: 0.6rem;
}

.voice-log-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.voice-log-actions button {
  font-size: 0.85rem;
  padding: 0.38rem 0.75rem;
}

.voice-log-list {
  display: grid;
  gap: 0.6rem;
}

.voice-log-empty {
  margin: 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.85rem;
}

.voice-log-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  padding: 0.7rem 0.8rem;
}

.voice-log-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.7rem;
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.voice-log-status {
  font-weight: 700;
}

.voice-log-status.ok {
  color: #2563eb;
}

.voice-log-status.ng {
  color: var(--danger);
}

.voice-log-label {
  margin: 0.35rem 0 0.15rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.voice-log-text {
  margin: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.voice-log-text.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.settings-hint {
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
  color: var(--danger);
}

.license-form {
  margin: 0.75rem 0;
}

.license-form label {
  display: block;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.license-key-note {
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--muted);
}

.license-activate-status {
  display: inline-block;
  margin-left: 0.6rem;
  color: var(--danger);
  font-weight: 700;
}

.license-activate-status[hidden] {
  display: none;
}

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

.license-key-input {
  flex: 1 1 220px;
  min-width: 0;
  font: inherit;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.02em;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
}

.license-meta {
  list-style: none;
  padding-left: 0;
  margin: 0.75rem 0 0;
}

.license-meta li {
  margin: 0.25rem 0;
}

.license-meta-action-row {
  margin-top: 0.75rem;
}

.demo-guide-overlay {
  position: fixed;
  inset: 0;
  z-index: 2140;
  background: rgba(0, 0, 0, 0.34);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.demo-guide-overlay[hidden] {
  display: none;
}

.demo-guide-box {
  width: min(100%, 33rem);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: #f9fbff;
  border: 1px solid #c9d7ea;
  border-radius: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.demo-guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 1rem 1rem 0;
}

.demo-guide-title {
  margin: 0;
  color: #0a64a7;
  font-size: 1.35rem;
  line-height: 1.45;
}

.demo-guide-badge {
  flex: 0 0 auto;
  padding: 0.28rem 0.7rem;
  border-radius: 8px;
  background: #e00000;
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
}

.demo-guide-body {
  position: relative;
  padding: 0.75rem 1rem 1rem;
}

.demo-guide-close {
  position: absolute;
  top: 0.35rem;
  right: 0.95rem;
}

.demo-guide-lead {
  margin: 0.55rem 0 0;
  padding-right: 2.3rem;
  color: var(--fg);
  font-size: 1rem;
  line-height: 1.55;
}

.demo-guide-section {
  margin-top: 0.95rem;
}

.demo-guide-section h3 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
  color: #44546a;
}

.demo-guide-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.demo-guide-chip {
  display: inline-flex;
  align-items: center;
  min-height: 2.05rem;
  padding: 0.25rem 0.8rem;
  border: 1px solid #cedcf0;
  border-radius: 999px;
  background: #e8f1fb;
  color: #226aa8;
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.25;
}

.demo-guide-chip-wide {
  max-width: 100%;
}

.demo-guide-note-block {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid #d8dce4;
}

.demo-guide-note-block p {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.55;
}

.demo-guide-note-block p + p {
  margin-top: 0.45rem;
}

.demo-guide-note-block strong {
  color: #cc0000;
}

.demo-guide-start-btn {
  display: block;
  width: min(100%, 22rem);
  margin: 1rem auto 0;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid #2d6dc7;
  background: #2b79d0;
  color: #ffffff;
  font: inherit;
  font-weight: 700;
}

.demo-guide-start-btn:hover {
  background: #2368b7;
}

.license-warning-banner {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid #f59e0b;
  background: rgba(245, 158, 11, 0.12);
  color: var(--fg);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

@media (prefers-color-scheme: dark) {
  .license-warning-banner {
    background: rgba(245, 158, 11, 0.15);
  }
}

.photo-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 2200;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--floating-ui-top) 1rem 1rem;
}

.photo-viewer-overlay[hidden] {
  display: none;
}

.photo-viewer-box {
  width: min(100%, 56rem);
  max-height: calc(100vh - var(--floating-ui-top) - 1rem);
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.28);
}

.photo-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.photo-viewer-title {
  margin: 0;
  font-size: 1rem;
}

.photo-viewer-body {
  padding: 0.75rem;
  text-align: center;
  background: var(--bg);
  overflow: auto;
}

.photo-viewer-image {
  max-width: 100%;
  max-height: calc(100vh - var(--floating-ui-top) - 7rem);
  border-radius: 8px;
}

/* ======================================================
   規約承認モーダル
   ====================================================== */

.terms-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding:
    max(0.75rem, env(safe-area-inset-top))
    1rem
    max(0.75rem, env(safe-area-inset-bottom))
    1rem;
}

.terms-overlay[hidden] {
  display: none;
}

.terms-box {
  background: var(--card);
  color: var(--fg);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.35);
  width: 100%;
  max-width: 680px;
  max-height: min(90vh, calc(100vh - 2rem));
  max-height: calc(100dvh - max(1.5rem, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
  display: flex;
  flex-direction: column;
  padding: 1.75rem 1.75rem 1.5rem;
  gap: 1rem;
  margin: auto 0;
}

.terms-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.75rem;
  color: var(--fg);
}

.terms-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  background: var(--bg);
  min-height: 200px;
  max-height: 50vh;
  outline: none;
}

.terms-scroll:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.terms-section {
  margin-bottom: 1.1rem;
}

.terms-section:last-child {
  margin-bottom: 0;
}

.terms-section h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0 0 0.35rem;
  color: var(--accent);
}

.terms-section p {
  font-size: 0.88rem;
  margin: 0 0 0.5rem;
  line-height: 1.65;
  color: var(--fg);
}

.terms-section p:last-child {
  margin-bottom: 0;
}

.terms-section ol,
.terms-section ul {
  margin: 0 0 0.7rem 1.35rem;
  padding: 0;
  color: var(--fg);
}

.terms-section li {
  font-size: 0.88rem;
  line-height: 1.65;
  margin-bottom: 0.4rem;
}

.terms-section li:last-child {
  margin-bottom: 0;
}

.terms-section a {
  color: var(--accent);
  word-break: break-word;
}

.terms-meta {
  font-size: 0.84rem;
  color: var(--muted);
}

.terms-agree-row {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.terms-agree-label {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.terms-agree-label input[type="checkbox"] {
  margin-top: 0.15rem;
  flex-shrink: 0;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.terms-agree-note {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--fg);
}

.terms-agree-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.terms-agree-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.terms-agree-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* ======================================================
   共通ダイアログ（alert / confirm 置換）
   ====================================================== */

.app-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.app-dialog-overlay.app-dialog-overlay-flow {
  align-items: flex-start;
  padding: var(--floating-ui-top) 1rem 1rem;
}

.app-dialog-overlay[hidden] {
  display: none;
}

.app-dialog-box {
  width: min(100%, 28rem);
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.28);
  padding: 1.15rem 1rem 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  position: relative;
}

.app-dialog-overlay.app-dialog-overlay-flow .app-dialog-box {
  max-height: calc(100vh - var(--floating-ui-top) - 1rem);
}

.app-dialog-message {
  margin: 0;
  font-size: 1rem;
  line-height: 1.6;
  text-align: center;
  white-space: pre-wrap;
}

.app-dialog-detail {
  margin: 0.65rem 0 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--muted);
  text-align: center;
  white-space: pre-wrap;
  word-break: break-word;
}

.app-dialog-detail-chip {
  display: table;
  max-width: 100%;
  margin: 0.65rem auto 0;
  padding: 0.38rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  font-weight: 600;
}

.app-dialog-message.app-dialog-message-guide,
.app-dialog-detail.app-dialog-detail-guide {
  text-align: left;
}

.app-dialog-close-btn {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  width: 2rem;
  height: 2rem;
  grid-column: auto;
  justify-self: auto;
  align-self: auto;
}

.app-dialog-close-btn[hidden] {
  display: none;
}

.app-dialog-sections {
  margin-top: 0.85rem;
}

.app-dialog-sections[hidden] {
  display: none;
}

.app-dialog-section {
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.app-dialog-section + .app-dialog-section {
  margin-top: 0.7rem;
}

.app-dialog-section-title {
  margin: 0 0 0.55rem;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--fg);
  text-align: left;
}

.app-dialog-section-body {
  margin: 0;
  line-height: 1.65;
  color: var(--fg);
  white-space: pre-wrap;
  text-align: left;
}

.app-dialog-section-action-wrap {
  margin-top: 0.75rem;
  text-align: left;
}

.app-dialog-section-action {
  min-width: 8.5rem;
}

.app-dialog-section-meta {
  margin: 0;
}

.app-dialog-section-meta-row {
  display: grid;
  grid-template-columns: 5.2rem 1fr;
  gap: 0.5rem;
  align-items: start;
}

.app-dialog-section-meta-row + .app-dialog-section-meta-row {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.app-dialog-section-meta dt,
.app-dialog-section-meta dd {
  margin: 0;
}

.app-dialog-section-meta dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.app-dialog-section-meta dd {
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.app-dialog-section-steps {
  margin: 0;
  padding-left: 1.2rem;
  line-height: 1.7;
  color: var(--fg);
}

.app-dialog-section-steps li + li {
  margin-top: 0.35rem;
}

.app-dialog-actions {
  display: flex;
  justify-content: center;
  gap: 0.65rem;
  margin-top: 1rem;
}

.app-dialog-btn {
  min-width: 6.2rem;
  padding: 0.55rem 0.95rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  font: inherit;
  font-weight: 700;
}

.app-dialog-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.app-dialog-btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.app-dialog-btn-danger {
  background: var(--btn-delete-red);
  border-color: var(--btn-delete-red-border);
  color: var(--btn-delete-red-fg);
}

.app-dialog-btn-danger:hover {
  background: var(--btn-delete-red-hover);
  border-color: var(--btn-delete-red-border);
}

.app-dialog-btn-danger:disabled {
  background: #ccc;
  border-color: #ccc;
  color: #888;
  cursor: not-allowed;
  opacity: 0.55;
}

.app-dialog-btn-secondary {
  background: var(--card);
  color: var(--fg);
}

.import-confirm-box {
  width: min(100%, 32rem);
}

.import-confirm-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.5;
  text-align: center;
}

.import-confirm-meta {
  margin: 1rem 0 0;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.import-confirm-meta-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.5rem;
  align-items: start;
}

.import-confirm-meta-row + .import-confirm-meta-row {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.import-confirm-meta dt,
.import-confirm-meta dd {
  margin: 0;
}

.import-confirm-meta dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.import-confirm-meta dd {
  font-weight: 700;
  line-height: 1.5;
  word-break: break-word;
}

.import-confirm-mode-wrap {
  margin-top: 0.9rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.import-confirm-mode-title {
  margin: 0 0 0.7rem;
  font-size: 0.92rem;
  line-height: 1.55;
}

.import-confirm-note {
  margin: -0.2rem 0 0.7rem;
  text-align: left;
}

.import-confirm-option {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  line-height: 1.55;
  cursor: pointer;
}

.import-confirm-option + .import-confirm-option {
  margin-top: 0.65rem;
}

.import-confirm-option input {
  margin-top: 0.2rem;
}

.mobile-edit-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  z-index: 2050;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  overscroll-behavior-y: contain;
}

.mobile-edit-sheet-overlay[hidden] {
  display: none;
}

.mobile-edit-sheet {
  width: min(100%, 32rem);
  background: var(--card);
  color: var(--fg);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  box-shadow: 0 -10px 36px rgba(0, 0, 0, 0.22);
  padding: 0.7rem 0.95rem calc(0.95rem + env(safe-area-inset-bottom));
  max-height: min(88vh, 42rem);
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: contain;
}

.mobile-edit-sheet-handle {
  width: 3rem;
  height: 0.3rem;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto 0.65rem;
  pointer-events: none;
  touch-action: none;
}

.mobile-edit-sheet-title {
  margin: 0 0 0.7rem;
  text-align: center;
  font-size: 1rem;
}

.mobile-edit-sheet-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 0.5rem;
  margin-bottom: 0.7rem;
  min-height: 2rem;
}

.mobile-edit-sheet-header .mobile-edit-sheet-title {
  margin: 0;
  grid-column: 2;
  justify-self: center;
}

.mobile-edit-close-btn {
  grid-column: 3;
  justify-self: end;
  align-self: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.mobile-edit-close-btn:hover {
  border-color: var(--accent);
}

.mobile-edit-sheet-body {
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

.mobile-edit-field {
  display: block;
  margin-bottom: 0.7rem;
}

.mobile-edit-field > span {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.mobile-edit-field input,
.mobile-edit-field textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
}

.mobile-edit-field textarea {
  resize: vertical;
}

.mobile-edit-bookpage-row {
  display: flex;
  gap: 0.6rem;
}

.mobile-edit-bookpage-row .mobile-edit-field {
  flex: 1 1 0;
}

#mobile-edit-book,
#mobile-edit-page {
  text-align: center;
}

.mobile-edit-sheet-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.mobile-edit-sheet-actions .app-dialog-btn {
  flex: 1 1 0;
  min-width: 0;
}

#mobile-edit-ai {
  flex: 1.2 1 0;
  white-space: nowrap;
  word-break: keep-all;
  letter-spacing: -0.01em;
  background: var(--voice-pastel-search-bg);
  border-color: var(--voice-pastel-search-border);
  color: var(--voice-pastel-search-fg);
}

#mobile-edit-save,
#mobile-edit-delete {
  flex: 0.8 1 0;
}

#mobile-edit-save {
  background: var(--btn-save-green);
  border-color: var(--btn-save-green-border);
  color: var(--btn-save-green-fg);
  font-weight: 700;
}

#mobile-edit-save:hover {
  background: var(--btn-save-green-hover);
  border-color: var(--btn-save-green-border);
}

.ai-lookup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  z-index: 2060;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.ai-lookup-overlay[hidden] {
  display: none;
}

.ai-lookup-dialog {
  width: min(100%, 34rem);
  max-height: min(90vh, 44rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
}

.ai-lookup-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 0.5rem;
  padding: 1rem 1rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.ai-lookup-title {
  margin: 0;
  grid-column: 2;
  justify-self: center;
  text-align: center;
  font-size: 1.02rem;
}

.ai-lookup-body {
  padding: 1rem;
  overflow-y: auto;
}

.ai-lookup-field {
  display: block;
  margin-bottom: 0.85rem;
}

.ai-lookup-field:last-child {
  margin-bottom: 0;
}

.ai-lookup-field > span {
  display: block;
  margin-bottom: 0.32rem;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--muted);
}

.ai-lookup-field textarea,
.ai-lookup-field select,
.ai-lookup-field input {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  padding: 0.58rem 0.68rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  box-sizing: border-box;
}

.ai-lookup-field textarea {
  resize: vertical;
}

.ai-lookup-actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  padding: 0 1rem 1rem;
}

.ai-lookup-actions .app-dialog-btn {
  flex: 0 1 auto;
  min-width: 0;
  width: min(100%, 26rem);
}

#ai-lookup-search {
  background: var(--voice-pastel-search-bg);
  border-color: var(--voice-pastel-search-border);
  color: var(--voice-pastel-search-fg);
  text-align: center;
  white-space: normal;
}

#mobile-edit-ai:hover,
#ai-lookup-search:hover {
  filter: brightness(0.97);
}

.device-transfer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  z-index: 2065;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.device-transfer-overlay[hidden] {
  display: none;
}

.device-transfer-dialog {
  width: min(100%, 42rem);
  max-height: min(90vh, 48rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
}

.device-transfer-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 0.5rem;
  padding: 1rem 1rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.device-transfer-title {
  margin: 0;
  grid-column: 2;
  text-align: center;
  font-size: 1.08rem;
}

.device-transfer-body {
  overflow-y: auto;
  padding: 1rem;
}

.device-transfer-lead {
  margin: 0;
  line-height: 1.65;
}

.device-transfer-lead + .device-transfer-lead {
  margin-top: 0.65rem;
}

.device-transfer-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1rem;
}

.device-transfer-actions .app-dialog-btn {
  width: 100%;
}

.device-transfer-actions .app-dialog-btn:disabled {
  background: #e3e3e3;
  border-color: #d0d0d0;
  color: #8a8a8a;
  cursor: not-allowed;
  opacity: 1;
  filter: none;
}

.device-transfer-result {
  margin-top: 1rem;
  padding: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.device-transfer-result[hidden] {
  display: none;
}

.device-transfer-result-title {
  margin: 0 0 0.7rem;
  font-size: 0.92rem;
  font-weight: 700;
}

.device-transfer-result-meta {
  margin: 0;
}

.device-transfer-result-row {
  display: grid;
  grid-template-columns: 5.2rem 1fr;
  gap: 0.5rem;
  align-items: start;
}

.device-transfer-result-row + .device-transfer-result-row {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.device-transfer-result-meta dt,
.device-transfer-result-meta dd {
  margin: 0;
}

.device-transfer-result-meta dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.device-transfer-result-meta dd {
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.device-transfer-main-btn {
  background: #cfe7ff;
  border-color: #9ec5f0;
  color: #000000;
  font-weight: 700;
}

.device-transfer-main-btn:hover {
  background: #b8d9f7;
  border-color: var(--accent);
}

.device-transfer-case-block {
  margin-top: 1rem;
  padding: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.device-transfer-case-title {
  margin: 0 0 0.7rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.device-transfer-case-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.device-transfer-case-tab {
  text-align: left;
  min-height: 3rem;
  padding: 0.6rem 0.7rem;
  line-height: 1.45;
  background: var(--card);
}

.device-transfer-case-tab[aria-selected="true"] {
  border-color: var(--accent);
  background: #eef6ff;
  color: #0f3d75;
  font-weight: 700;
}

.device-transfer-case-panel {
  margin-top: 0.8rem;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.device-transfer-case-panel-title {
  margin: 0 0 0.45rem;
  font-size: 0.96rem;
}

.device-transfer-case-panel-text {
  margin: 0;
  line-height: 1.7;
  white-space: pre-wrap;
}

.device-transfer-caution {
  margin: 1rem 0 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--muted);
}

.mobile-inline-editor-cell {
  padding: 0.55rem 0.45rem;
  background: var(--bg);
}

.mobile-inline-editor {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  padding: 0.8rem 0.8rem 0.9rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

.mobile-inline-editor .mobile-edit-field {
  margin-bottom: 0.8rem;
}

.mobile-inline-editor .mobile-edit-field:last-of-type {
  margin-bottom: 0;
}

.mobile-inline-editor textarea,
.mobile-inline-editor input {
  background: var(--bg);
}

.mobile-inline-editor .mobile-inline-title {
  min-height: 5.2rem;
}

.mobile-inline-editor-actions {
  margin-top: 0.85rem;
}

.table-wrap.voice-register-mobile-mode {
  overflow: visible;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  width: 100%;
  max-width: 100%;
}

table.entries-table.voice-register-mobile-mode {
  display: block;
  width: 100%;
  min-width: 0;
  border: none;
  table-layout: auto;
  background: transparent;
}

table.entries-table.voice-register-mobile-mode colgroup,
table.entries-table.voice-register-mobile-mode thead {
  display: none;
}

table.entries-table.voice-register-mobile-mode tbody,
table.entries-table.voice-register-mobile-mode tr,
table.entries-table.voice-register-mobile-mode td {
  display: block;
  width: 100%;
  max-width: 100%;
  border: none;
  background: transparent;
  box-sizing: border-box;
}

table.entries-table.voice-register-mobile-mode tbody tr:nth-child(even) {
  background: transparent;
}

table.entries-table.voice-register-mobile-mode .mobile-inline-editor-row {
  margin: 0;
}

table.entries-table.voice-register-mobile-mode .mobile-inline-editor-cell {
  padding: 0;
}

@media (max-width: 880px) {
  .terms-overlay {
    padding:
      max(0.45rem, env(safe-area-inset-top))
      0.45rem
      max(0.45rem, env(safe-area-inset-bottom))
      0.45rem;
  }

  .terms-box {
    padding: 1.25rem 1rem 1rem;
    border-radius: 10px;
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - max(0.9rem, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    gap: 0.8rem;
  }

  .terms-title {
    font-size: 0.97rem;
    padding-bottom: 0.55rem;
  }

  .terms-scroll {
    min-height: 0;
    max-height: none;
    padding: 0.75rem 0.85rem;
  }

  .terms-agree-row {
    padding-top: 0.7rem;
  }

  .terms-agree-label {
    font-size: 0.88rem;
  }

  .terms-agree-note {
    font-size: 0.88rem;
  }

.license-maintenance-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  z-index: 2066;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.license-maintenance-overlay[hidden] {
  display: none;
}

.license-maintenance-dialog {
  width: min(100%, 32rem);
  max-height: min(90vh, 40rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
}

.license-maintenance-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.license-maintenance-title {
  margin: 0;
  font-size: 1.08rem;
}

#license-maintenance-close {
  position: static;
  justify-self: end;
}

.license-maintenance-body {
  overflow-y: auto;
  padding: 1rem;
}

.license-maintenance-lead,
.license-maintenance-flow,
.license-maintenance-note,
.license-maintenance-status {
  margin: 0;
  line-height: 1.65;
}

.license-maintenance-flow,
.license-maintenance-note {
  margin-top: 0.75rem;
}

.license-maintenance-note {
  color: var(--muted);
  font-size: 0.92rem;
}

.license-maintenance-status {
  margin-top: 0.75rem;
  color: var(--danger);
  font-size: 0.92rem;
}

.license-maintenance-status[hidden] {
  display: none;
}

.license-maintenance-label {
  display: block;
  margin-top: 0.95rem;
  margin-bottom: 0.35rem;
  font-weight: 700;
}

.license-maintenance-input {
  width: 100%;
  min-width: 0;
  font: inherit;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
}

.license-maintenance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.license-maintenance-actions .settings-license-btn,
.license-maintenance-actions .settings-link-button {
  min-height: 2.5rem;
}

  .terms-agree-btn {
    width: 100%;
  }

  .terms-section h3 {
    font-size: 0.87rem;
  }

  .terms-section p {
    font-size: 0.83rem;
  }

  .terms-section li {
    font-size: 0.83rem;
  }

  .app-dialog-box {
    width: min(100%, 22rem);
    padding: 1rem 0.85rem 0.9rem;
    border-radius: 12px;
  }

  .app-dialog-message {
    font-size: 0.95rem;
  }

  .app-dialog-detail {
    font-size: 0.84rem;
  }

  .app-dialog-actions {
    gap: 0.45rem;
  }

  .app-dialog-btn {
    min-width: 5.6rem;
    padding: 0.52rem 0.75rem;
    font-size: 0.92rem;
  }

  .mobile-inline-editor-cell {
    padding: 0.45rem 0.35rem;
  }

  .mobile-inline-editor {
    padding: 0.75rem 0.7rem 0.85rem;
  }

  .table-wrap.voice-register-mobile-mode {
    margin-top: 0.2rem;
  }
}

/* ======================================================
   トースト
   ====================================================== */

#toast {
  position: fixed;
  left: 50%;
  top: var(--floating-ui-top);
  transform: translateX(-50%);
  bottom: auto;
  max-width: min(520px, calc(100% - 2rem));
  padding: 0.65rem 1rem;
  border-radius: 10px;
  background: #111827;
  color: #f9fafb;
  font-size: 0.9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 1000;
}

#toast.show {
  opacity: 1;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ======================================================
   スマホ寄りレイアウト（880px 以下）
   ====================================================== */
@media (max-width: 880px) {
  /* ロゴ・副題 */
  .app-logo { height: 72px; }
  .subtitle  { font-size: 0.78rem; }

  /* ボタンラベルを短縮表示に切替 */
  .lbl-wide   { display: none;   }
  .lbl-narrow { display: inline; }

  /* 設定ライセンスボタンを次行へ押し出し（右寄せ） */
  .hdr-break         { display: block; }
  .header-secondary-actions {
    width: 100%;
    justify-content: flex-end;
  }
  #btn-settings-toggle {
    white-space: nowrap;
    letter-spacing: -0.02em;
    padding: 0.3rem 0.5rem;
    font-size: 0.82rem;
  }

  /* 件数情報フォントサイズ */
  .header-sub-row .plan-summary-sp { font-size: 0.78rem; }

  /* 音声ボタン */
  .voice-row {
    flex-wrap: nowrap;
    gap: 0.35rem;
  }

  button.voice-lg {
    flex: 0 0 auto;
    min-width: 0;
    max-width: none;
    width: auto;
    padding: 0.4rem 0.5rem;
    min-height: 3.35rem;
  }

  .voice-btn-mic svg              { width: 18px; height: 18px; }
  .voice-btn-title                { font-size: 0.88rem; }
  button.voice-btn-search .voice-btn-title { font-size: 0.95rem; }
  .voice-btn-sub                  { font-size: 0.68rem; }
  .voice-btn-title-row            { gap: 0.25rem; }

  /* 冊目・頁列: スマホでは幅を縮小 */
  .entries-table col.col-booknum   { width: 5.5rem; }

  /* スマホでの冊目・頁入力: 小さく */
  .booknum-wrap                    { gap: 0.15rem; }

  .booknum-wrap input.inline-num {
    width: 2rem;
    max-width: 2rem;
    font-size: 0.75rem;
    padding: 0.15rem 0.1rem;
  }

  .readonly-box {
    width: 2rem;
    max-width: 2rem;
    min-height: 1.5rem;
    font-size: 0.75rem;
    line-height: 1.2;
    padding: 0.15rem 0.1rem;
  }

  /* 冊目・頁ヘッダー: 小さめ */
  .entries-table th.th-booknum {
    font-size: 0.72rem;
  }

  /* スマホでは横スクロール前提で表示する */
  .table-wrap                      { overflow-x: scroll; }

  /* スマホ寄りでもタブレット幅は活用する */
  table.entries-table:not(.voice-register-mobile-mode) { width: 100%; min-width: 26rem; }

  .entries-table:not(.voice-register-mobile-mode) col.col-title,
  table.entries-table:not(.voice-register-mobile-mode) td.col-title { min-width: 15rem; }

  .table-wrap.phone-sheet-mode:not(.voice-register-mobile-mode) { overflow-x: auto; }

  table.entries-table.phone-sheet-mode:not(.voice-register-mobile-mode) {
    width: 100%;
    min-width: 21.5rem;
  }

  table.entries-table.phone-sheet-mode:not(.voice-register-mobile-mode) col.col-title,
  table.entries-table.phone-sheet-mode:not(.voice-register-mobile-mode) td.col-title {
    min-width: 14rem;
  }

  table.entries-table.phone-sheet-mode:not(.voice-register-mobile-mode) .title-display-readonly {
    font-size: 0.88rem;
  }

  .entries-table col.col-actions   { width: 5rem; min-width: 5rem; }

  .entries-table td.col-actions {
    width: 5rem;
    min-width: 5rem;
    max-width: 5rem;
  }

  .entries-table td.col-actions button.sm {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.3rem;
  }

  #mobile-edit-ai { letter-spacing: -0.02em; }

  .title-cell {
    gap: 0.2rem;
  }

  .title-display-readonly {
    font-size: 0.95rem;
    padding: 0.28rem 0.32rem;
  }

  .title-display-row {
    gap: 0.2rem;
  }

  table.entries-table.phone-sheet-mode .memo-indicator {
    min-width: 0.9rem;
    padding: 0.12rem 0.08rem;
    font-size: 0.58rem;
    line-height: 1;
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: -0.05em;
    align-self: stretch;
  }

  .title-cell .btn-memo {
    min-width: 3.8rem;
    padding: 0.2rem 0.3rem;
    font-size: 0.72rem;
    font-weight: 600;
  }

  .actions {
    text-align: center;
    padding: 0.1rem;
  }
  .actions button {
    margin: 0.1rem;
  }

  .mobile-edit-sheet {
    width: 100%;
    max-height: 90vh;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .mobile-edit-close-btn {
    width: 2.1rem;
    height: 2.1rem;
    font-size: 1.05rem;
  }

  .ai-lookup-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .ai-lookup-dialog {
    width: 100%;
    max-height: 90vh;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
  }

  .ai-lookup-actions {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  .device-transfer-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .device-transfer-dialog {
    width: 100%;
    max-height: 90vh;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
  }

  .device-transfer-header {
    padding: 0.9rem 0.9rem 0.75rem;
  }

  .device-transfer-body {
    padding: 0.9rem 0.9rem calc(0.95rem + env(safe-area-inset-bottom));
  }

  .device-transfer-case-tabs {
    grid-template-columns: 1fr;
  }
}
