:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #1d2330;
  --muted: #6b7385;
  --primary: #2457d6;
  --primary-hover: #1c47b4;
  --primary-soft: #e9effc;
  --danger: #d23b3b;
  --danger-soft: #fdecec;
  --success: #1f8a4c;
  --success-soft: #e6f5ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
[hidden] { display: none !important; }

/* ---- ボタン・フォーム ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #f3c4c4; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #b52f2f; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text);
}
textarea.input { resize: vertical; min-height: 80px; }
.input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.check input { margin-top: 4px; }
.check small { display: block; color: var(--muted); }

.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--success-soft); color: var(--success); }

/* ---- レイアウト ---- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-size: 15px;
}
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; text-align: right; line-height: 1.3; }
.topbar .who strong { color: var(--text); display: block; }

.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; flex: 1; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab {
  padding: 10px 16px; border: 0; background: none; font: inherit; font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-color: var(--primary); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---- テーブル ---- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn + .btn { margin-left: 6px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #eef0f3; color: var(--muted);
}
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-red { background: var(--danger-soft); color: var(--danger); }

/* ---- カタログ一覧 ---- */
.toolbar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar .input { max-width: 280px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; }
.cat {
  display: flex; flex-direction: column; overflow: hidden;
  transition: box-shadow .2s, transform .2s;
}
.cat:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.cat-thumb {
  position: relative; aspect-ratio: 3 / 4; background: #eceef2; display: grid; place-items: center;
  overflow: hidden; cursor: pointer; border-bottom: 1px solid var(--border);
}
.thumb-slot { width: 100%; height: 100%; display: grid; place-items: center; }
.cat-thumb canvas { max-width: 88%; max-height: 92%; box-shadow: 0 4px 14px rgba(0,0,0,.18); background: #fff; }
.cat-thumb .ph { color: #a2a9b7; font-size: 13px; }
.cat-thumb .badge { position: absolute; top: 10px; left: 10px; }
.cat-body { padding: 14px 16px 10px; flex: 1; }
.cat-no { font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 2px; font-family: ui-monospace, Menlo, monospace; }
.cat-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; word-break: break-word; }
.cat-meta { color: var(--muted); font-size: 12px; }
.cat-actions { display: flex; gap: 6px; padding: 10px 12px 14px; flex-wrap: wrap; }
.cat-actions .btn { flex: 1; }

.empty {
  text-align: center; padding: 64px 24px; color: var(--muted);
  border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}
.empty h3 { color: var(--text); margin-bottom: 8px; }

/* ---- モーダル ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 20, 30, .45); z-index: 100;
  display: grid; place-items: center; padding: 20px; animation: fade .15s;
}
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 40px); overflow: auto;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; flex: 1; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: #fafbfc; }
@keyframes fade { from { opacity: 0; } }

.dropzone {
  border: 2px dashed #c6ccd8; border-radius: 10px; padding: 28px 16px; text-align: center;
  color: var(--muted); cursor: pointer; transition: all .15s; background: #fafbfc;
}
.dropzone.over, .dropzone:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dropzone strong { color: var(--text); display: block; margin-top: 4px; word-break: break-all; }
.progress { height: 6px; border-radius: 3px; background: #e7eaf0; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width .2s; }

.copy-row { display: flex; gap: 8px; }
.copy-row .input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

/* ---- トースト ---- */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1d2330; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg);
  font-size: 13px; animation: fade .2s; max-width: 360px;
}
.toast.error { background: var(--danger); }

/* ---- ログイン ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, #eaf0fd 0%, #f5f6f8 60%); }
.auth-stack { width: 100%; max-width: 400px; }
.auth-card { width: 100%; max-width: 400px; padding: 36px 32px; }
.auth-links { text-align: center; margin-top: 18px; font-size: 13px; }
.auth-card .brand { justify-content: center; margin-bottom: 8px; font-size: 20px; }
.auth-card p.sub { text-align: center; color: var(--muted); margin: 0 0 28px; }

@media (max-width: 640px) {
  .topbar { padding: 0 14px; }
  .topbar .who { display: none; }
  .container { padding: 20px 14px 40px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; }
}

/* ---- プラン・容量 ---- */
.usage-card { display: flex; gap: 28px; align-items: center; padding: 18px 22px; margin-bottom: 24px; flex-wrap: wrap; }
.usage-label { font-size: 12px; color: var(--muted); }
.usage-plan-name { font-size: 20px; font-weight: 700; line-height: 1.3; }
.usage-plan-name span { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.usage-main { flex: 1; min-width: 240px; }
.usage-nums { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; margin-bottom: 6px; flex-wrap: wrap; }
.usage-bar { height: 10px; border-radius: 5px; background: #e7eaf0; overflow: hidden; }
.usage-bar > div { height: 100%; border-radius: 5px; background: var(--primary); transition: width .3s; }
.usage-bar.warn > div { background: #e0a100; }
.usage-bar.full > div { background: var(--danger); }
.usage-msg { margin-top: 8px; font-size: 12px; }
.usage-msg.warn { color: #9a6b00; }
.usage-msg.full { color: var(--danger); }
.usage-actions { flex: none; }
/* プラン変更の影響 */
.plan-choices { display: grid; gap: 12px; }
.plan-choice { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.plan-choice.is-current { background: #fafbfc; }
.plan-choice.is-down { border-color: #f3c4c4; }
.plan-choice-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.plan-choice-head strong { font-size: 16px; }
.plan-choice-head span { color: var(--muted); font-size: 13px; }
.impact { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; }
.impact li { padding-left: 20px; position: relative; margin-top: 4px; }
.impact-warn li { color: var(--danger); }
.impact-warn li::before { content: "⚠"; position: absolute; left: 0; }
.impact-good li { color: var(--success); }
.impact-good li::before { content: "✓"; position: absolute; left: 2px; font-weight: 700; }
.impact-current, .impact-none { color: var(--muted); }
/* 本棚 */
.shelf-card { display: flex; align-items: center; gap: 16px; padding: 16px 22px; margin: -8px 0 24px; flex-wrap: wrap; }
.shelf-icon { width: 48px; height: 48px; border-radius: 10px; background: var(--primary-soft); display: grid; place-items: center; font-size: 24px; flex: none; overflow: hidden; }
.shelf-icon img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.shelf-main { flex: 1; min-width: 220px; }
.shelf-main .badge { margin-left: 6px; }
.shelf-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.shelf-toggle { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; cursor: pointer; flex-wrap: wrap; }
.logo-row { display: flex; align-items: center; gap: 10px; }
.logo-preview { width: 120px; height: 56px; border: 1px dashed var(--border); border-radius: 8px; display: grid; place-items: center; overflow: hidden; background: #fff; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cat.locked { opacity: .72; }
.cat.locked .cat-thumb { background: repeating-linear-gradient(45deg, #eceef2, #eceef2 10px, #e4e7ec 10px, #e4e7ec 20px); cursor: pointer; }
.cat.locked:hover { transform: none; box-shadow: var(--shadow); opacity: .85; }
.lock-icon { font-size: 40px; filter: grayscale(1); }
.table .usage-bar { height: 6px; width: 120px; margin-top: 4px; }

/* ---- 本文検索の結果 ---- */
.search-status { align-self: center; color: var(--muted); font-size: 13px; }
.hint-inline { color: var(--muted); font-size: 12px; }
.hit { margin-top: 10px; padding: 10px; background: #fffbea; border: 1px solid #f3e3a4; border-radius: 8px; font-size: 12px; }
.hit-head { font-weight: 700; color: #7a5c00; margin-bottom: 4px; }
.hit-snippet { color: var(--text); line-height: 1.5; word-break: break-all; }
.hit mark { background: #ffd54a; color: inherit; padding: 0 1px; border-radius: 2px; }
.hit-pages { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; align-items: center; }
.page-chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px; background: #fff; border: 1px solid #e6d58f;
  color: #7a5c00; font-weight: 600; font-size: 12px;
}
.page-chip:hover { background: #ffe58a; text-decoration: none; }

/* 操作ログ */
.badge-amber { background: #fff4e0; color: #9a5b00; }
.log-filters { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; padding: 16px; margin-bottom: 16px; }
.log-filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.log-filters .input { min-width: 150px; }
.log-dates { display: flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 400; }
.log-dates .input { min-width: 0; width: 150px; }
.log-q { flex: 1 1 240px; }
.log-filter-actions { display: flex; gap: 8px; }
.log-table td { vertical-align: top; font-size: 13px; }
.log-time { white-space: nowrap; color: var(--muted); }
.log-sub { color: var(--muted); font-size: 12px; }
.log-table .badge, .log-table th { white-space: nowrap; }
.log-detail { margin-top: 4px; color: var(--muted); font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.log-table tr.log-warn td { background: #fffaf0; }
.log-table tr.log-error td { background: #fff3f3; }

/* 2段階認証 */
.code-input { font-size: 22px; letter-spacing: 0.3em; text-align: center; font-family: ui-monospace, Menlo, monospace; }
.twofa-qr { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.twofa-qr img { flex: none; width: 180px; height: 180px; border: 1px solid var(--border); border-radius: 8px; }
.twofa-key { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: #f4f5f7; padding: 6px 8px; border-radius: 6px; word-break: break-all; overflow-wrap: anywhere; }
.recovery-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; font-family: ui-monospace, Menlo, monospace; font-size: 15px;
  background: #f8f9fb; border: 1px solid var(--border); border-radius: 8px; padding: 14px 18px; margin: 12px 0; }
.twofa-steps { padding-left: 20px; margin: 0 0 12px; }
.twofa-steps li { margin-bottom: 6px; }
.twofa-banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: #fff4e0; border: 1px solid #f3d29b; color: #7a4a00; border-radius: 10px; padding: 12px 16px; margin: 16px 0 0; }
