/* ============================================================
   admin.css — 管理ダッシュボードの見た目
   ============================================================ */

:root {
  --a-primary: #12489b;
  --a-primary-dark: #0a2f6b;
  --a-bg: #f2f5f9;
  --a-panel: #fff;
  --a-line: #dde5ee;
  --a-text: #1c2b3a;
  --a-muted: #66788b;
  --a-ok: #1f8a4c;
  --a-danger: #c33;
}

* { box-sizing: border-box; }

/* hidden 属性を必ず優先する（.modal などの display 指定に負けないように） */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--a-bg);
  color: var(--a-text);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.7;
}

button, input, textarea, select { font-family: inherit; font-size: 14px; color: inherit; }

/* ---------- ボタン ---------- */
.btn {
  border: 1px solid var(--a-line); background: #fff; color: var(--a-text);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f6f9fd; }
.btn.primary { background: var(--a-primary); border-color: var(--a-primary); color: #fff; }
.btn.primary:hover { background: var(--a-primary-dark); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn.danger { color: var(--a-danger); border-color: #e8bcbc; }
.btn.danger:hover { background: #fdf2f2; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- ログイン ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #12489b, #0a2f6b);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 16px; padding: 38px 34px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25); text-align: center;
}
.login-card h1 { font-size: 19px; margin: 0 0 6px; color: var(--a-primary-dark); }
.login-card p { margin: 0 0 20px; color: var(--a-muted); font-size: 13px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--a-line); border-radius: 8px; margin-bottom: 14px;
}
.login-card button {
  width: 100%; padding: 13px; border: 0; border-radius: 8px;
  background: var(--a-primary); color: #fff; font-weight: 800; cursor: pointer;
}
.login-error { color: var(--a-danger); font-weight: 700; margin: 14px 0 0 !important; }
.login-hint { margin: 20px 0 0 !important; font-size: 12px; color: #93a2b3; }
.login-hint code { background: #f0f3f7; padding: 2px 6px; border-radius: 4px; }

/* ---------- 上部バー ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  background: var(--a-primary-dark); color: #fff; padding: 0 18px; height: 58px;
}
.brand { font-weight: 800; font-size: 15px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255, 255, 255, .35); }
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, .12); }
.topbar .btn.primary { background: #fff; color: var(--a-primary-dark); border-color: #fff; }
.topbar .btn.primary:hover { background: #e7eefa; }
.status { font-size: 12.5px; color: #bcd3f2; min-width: 0; }
.status.ok { color: #9ff0bf; font-weight: 700; }
.status.err { color: #ffb3b3; font-weight: 700; }

/* ---------- レイアウト ---------- */
.layout {
  display: grid;
  grid-template-columns: 200px minmax(320px, 1fr) minmax(280px, 42%);
  height: calc(100vh - 58px);
}
.layout.no-preview { grid-template-columns: 200px 1fr; }
.layout.no-preview .preview { display: none; }

/* ---------- サイドバー ---------- */
.sidebar {
  background: #fff; border-right: 1px solid var(--a-line);
  overflow-y: auto; padding: 14px 10px;
}
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border: 0; background: none; border-radius: 8px;
  cursor: pointer; text-align: left; font-weight: 700; color: var(--a-text);
}
.side-item:hover { background: #f2f6fb; }
.side-item.is-active { background: var(--a-primary); color: #fff; }
.side-icon {
  width: 26px; height: 26px; border-radius: 7px; background: #eaf1fa; color: var(--a-primary);
  display: flex; align-items: center; justify-content: center; font-size: 13px; flex: 0 0 auto;
}
.side-item.is-active .side-icon { background: rgba(255, 255, 255, .22); color: #fff; }

/* ---------- 編集エリア ---------- */
.editor { overflow-y: auto; padding: 24px; }
.editor-inner { max-width: 720px; margin: 0 auto; }
.sec-title-row h1 { font-size: 20px; margin: 0 0 4px; color: var(--a-primary-dark); }
.sec-title-row p { margin: 0 0 22px; color: var(--a-muted); font-size: 13px; }

.card {
  background: var(--a-panel); border: 1px solid var(--a-line); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 16px;
}

.f { margin-bottom: 18px; }
.f:last-child { margin-bottom: 0; }
.f > label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 13.5px; }
.f .help { font-size: 12px; color: var(--a-muted); margin: 5px 0 0; line-height: 1.6; }
.f input[type=text], .f input[type=url], .f textarea, .f select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--a-line); border-radius: 8px; background: #fff;
}
.f textarea { min-height: 96px; resize: vertical; line-height: 1.7; }
.f input:focus, .f textarea:focus, .f select:focus { outline: 2px solid var(--a-primary); border-color: transparent; }

/* 色 */
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=color] { width: 46px; height: 38px; padding: 0; border: 1px solid var(--a-line); border-radius: 8px; background: #fff; cursor: pointer; }
.color-row input[type=text] { max-width: 130px; font-family: ui-monospace, Consolas, monospace; }

/* ON/OFF */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; }
.switch input { width: 18px; height: 18px; accent-color: var(--a-primary); }

/* 画像 */
.img-field { display: flex; gap: 14px; align-items: flex-start; }
.img-thumb {
  width: 118px; height: 90px; flex: 0 0 auto; border-radius: 8px; overflow: hidden;
  border: 1px dashed var(--a-line); background: #f7f9fc;
  display: flex; align-items: center; justify-content: center; font-size: 11px; color: #9aa9b8;
}
.img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.img-ctrl { flex: 1 1 auto; min-width: 0; }
.img-ctrl input { margin-bottom: 8px; }
.img-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* グループ */
.group { border: 1px solid var(--a-line); border-radius: 10px; padding: 16px; background: #fafcfe; }
.group > h4 { margin: 0 0 14px; font-size: 13px; color: var(--a-primary); }

/* リスト */
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.list-head h4 { margin: 0; font-size: 14px; }
.list-item { border: 1px solid var(--a-line); border-radius: 10px; margin-bottom: 10px; background: #fff; overflow: hidden; }
.list-item-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: #f5f8fc; cursor: pointer; user-select: none;
}
.list-item-head .idx {
  width: 22px; height: 22px; border-radius: 6px; background: var(--a-primary); color: #fff;
  font-size: 11px; display: flex; align-items: center; justify-content: center; font-weight: 800; flex: 0 0 auto;
}
.list-item-title { font-weight: 700; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item-tools { display: flex; gap: 4px; flex: 0 0 auto; }
.icon-btn {
  border: 1px solid var(--a-line); background: #fff; width: 28px; height: 28px; border-radius: 6px;
  cursor: pointer; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: #eef4fb; }
.icon-btn.del:hover { background: #fdeeee; color: var(--a-danger); border-color: #e8bcbc; }
.list-item-body { padding: 16px; border-top: 1px solid var(--a-line); }
.list-item.collapsed .list-item-body { display: none; }
.empty-list { color: var(--a-muted); font-size: 13px; padding: 10px 0; }

/* ---------- プレビュー ---------- */
.preview { border-left: 1px solid var(--a-line); background: #e7ecf2; display: flex; flex-direction: column; min-width: 0; }
.preview-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--a-line); font-size: 12.5px; font-weight: 700;
}
.preview-devices { display: flex; gap: 4px; }
.dev-btn { border: 1px solid var(--a-line); background: #fff; border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.dev-btn.is-active { background: var(--a-primary); color: #fff; border-color: var(--a-primary); }
.preview-stage { flex: 1 1 auto; overflow: auto; display: flex; justify-content: center; padding: 12px; }
#preview-frame { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 8px; box-shadow: 0 3px 14px rgba(0, 0, 0, .12); }

/* ---------- モーダル ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(12, 25, 45, .5); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card { background: #fff; border-radius: 14px; padding: 26px; width: 100%; max-width: 520px; max-height: 86vh; overflow: auto; }
.modal-card h2 { margin: 0 0 18px; font-size: 17px; }
.tool-row { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-top: 1px solid var(--a-line); }
.tool-row > div { flex: 1 1 auto; }
.tool-row strong { display: block; font-size: 14px; }
.tool-row p { margin: 2px 0 0; font-size: 12.5px; color: var(--a-muted); }
.tool-row .btn { flex: 0 0 auto; }
.modal-foot { margin-top: 20px; text-align: right; }
.backup-list { border-top: 1px solid var(--a-line); padding-top: 10px; max-height: 240px; overflow: auto; }
.backup-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 12.5px; }
.backup-row span { flex: 1 1 auto; font-family: ui-monospace, Consolas, monospace; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #1c2b3a; color: #fff; padding: 12px 22px; border-radius: 999px;
  font-weight: 700; font-size: 13.5px; z-index: 90; box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}
.toast.ok { background: var(--a-ok); }
.toast.err { background: var(--a-danger); }

/* ---------- レスポンシブ ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 190px 1fr; }
  .preview { display: none; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar {
    display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--a-line);
    position: sticky; top: 58px; z-index: 20; padding: 8px;
  }
  .side-item { white-space: nowrap; width: auto; }
  .side-item span:not(.side-icon) { font-size: 13px; }
  .editor { padding: 16px; }
  .brand { font-size: 13px; }
  .topbar { padding: 0 10px; gap: 8px; }
  #btn-preview-toggle { display: none; }
}
