/* 管理画面の共通スタイル。
   iPhone の設定アプリのような「薄い灰色の背景 + 角丸のカード + 内側に寄せた区切り線」が基本。
   スマホ(片手操作)を基準にし、広い画面では中央寄せにする。 */

:root {
  /* アプリ共通の色:アクア→ブルーのグラデーション(清潔感と近未来感。汚れのイメージを打ち消す) */
  --color-primary: #1d4ed8; /* グラデーションが使えない所の単色 */
  --color-primary-hover: #1e40af;
  --color-primary-text: #ffffff;
  --gradient-primary: linear-gradient(135deg, #0e7490, #1d4ed8);
  --gradient-primary-hover: linear-gradient(135deg, #0b5e75, #1e40af);
  --shadow-glow: 0 4px 14px rgb(29 78 216 / 0.3);
  --color-accent: #1d4ed8; /* リンク・文字のボタン・アイコン */
  --color-accent-soft: rgb(29 78 216 / 0.1);
  --color-bg: #f4f9fc;
  --color-surface: #ffffff;
  --color-fill: #edf3f8; /* 入力欄などの塗り */
  --color-fill-strong: #e0e9f1;
  --color-text: #0f1b2d;
  --color-muted: #556274;
  --color-faint: #8592a3;
  --color-separator: rgb(14 64 110 / 0.11);
  --color-danger: #d70015;
  --color-danger-bg: #fff0f0;
  --color-success: #1b7f3b;
  --color-success-bg: #eaf7ee;
  --color-dirty-bg: #fff8e1;
  --color-dirty-border: #f5a524;
  --color-up: #d70015;
  --color-down: #0a64d8;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 3px rgb(15 27 45 / 0.06), 0 1px 1px rgb(15 27 45 / 0.03);
  --shadow-float: 0 10px 28px rgb(15 27 45 / 0.14), 0 2px 6px rgb(15 27 45 / 0.06);
  --tap: 48px; /* 指で押しやすい高さ */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; }

/* .btn などの display 指定より優先して隠す */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", system-ui, sans-serif;
  font-size: 16px; /* 16px 未満だと iOS が入力時に拡大する */
  line-height: 1.55;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

.icon { width: 1.15em; height: 1.15em; flex-shrink: 0; vertical-align: -0.2em; }

/* ---- ヘッダー ---- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgb(244 249 252 / 0.82);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--color-separator);
}

.app-header__top {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 12px 4px 16px;
}
.app-header__top form { margin: 0; }

.app-header__company {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9375rem;
  font-weight: 700;
}

.header-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 0 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--color-accent);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s var(--ease);
}
.header-action:active { background: var(--color-fill-strong); }

/* メニューは iOS のセグメントコントロール風 */
.app-nav {
  display: flex;
  gap: 2px;
  max-width: calc(720px - 32px);
  margin: 4px 16px 10px;
  padding: 2px;
  border-radius: 10px;
  background: rgb(14 64 110 / 0.07);
}
@media (min-width: 752px) {
  .app-nav { margin-left: auto; margin-right: auto; }
}

.app-nav__link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 8px;
  color: var(--color-text);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.app-nav__link[aria-current="page"] {
  background: var(--color-surface);
  font-weight: 700;
  box-shadow: 0 3px 8px rgb(0 0 0 / 0.12), 0 3px 1px rgb(0 0 0 / 0.04);
}

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.page-title { margin: 0 0 16px; font-size: 1.75rem; font-weight: 800; letter-spacing: 0; }

/* ---- カード・フォーム ---- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px;
}
.card--flush { padding: 0; overflow: hidden; }
.card + .card, .form + .card { margin-top: 20px; }

.form { display: grid; gap: 18px; }
.form__field { display: grid; gap: 6px; }
.form__field > span { font-size: 0.8125rem; font-weight: 600; color: var(--color-muted); }
.form__section { margin: 6px 0 -4px; font-size: 1.0625rem; font-weight: 700; }
.form__section:first-child { margin-top: 0; }
.form__hint { color: var(--color-faint); font-size: 0.8125rem; }
.form__field-error { margin: 0; color: var(--color-danger); font-size: 0.8125rem; font-weight: 600; }
.form__check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.form__check input { width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--color-primary); }
.form__radios { display: flex; flex-wrap: wrap; gap: 0 24px; margin: 0; padding: 0; border: none; }
.form__radios legend { width: 100%; padding: 0 0 2px; font-size: 0.8125rem; font-weight: 600; color: var(--color-muted); }
.form__actions { display: flex; justify-content: flex-end; gap: 8px; }

.form__error,
.flash {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
}
.form__error { background: var(--color-danger-bg); color: var(--color-danger); }
.flash { background: var(--color-success-bg); color: var(--color-success); animation: flash-in 0.35s var(--ease); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-4px); } }

input[type="email"],
input[type="password"],
input[type="text"],
input[type="url"],
input[type="tel"],
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--color-fill);
  color: inherit;
  font: inherit;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  background: var(--color-surface);
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-accent-soft);
}
input::placeholder, textarea::placeholder { color: #aeaeb2; }
textarea { min-height: auto; resize: vertical; line-height: 1.5; }
select {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

/* ---- ボタン ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--color-fill-strong);
  color: var(--color-text);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background-color 0.15s var(--ease), opacity 0.15s var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn--primary { background: var(--color-primary); background-image: var(--gradient-primary); color: var(--color-primary-text); box-shadow: var(--shadow-glow); }
.btn--primary:disabled { box-shadow: none; }
.btn--ghost { background: transparent; color: var(--color-accent); padding: 0 12px; }
.btn--block { width: 100%; }
.btn--small { min-height: 40px; padding: 0 14px; font-size: 0.875rem; background: var(--color-fill); color: var(--color-accent); }
.btn--icon {
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 999px;
  background: var(--color-fill);
  color: var(--color-accent);
}
.btn--icon:disabled { color: var(--color-faint); opacity: 0.45; }
.btn--danger { background: var(--color-danger-bg); color: var(--color-danger); }

.hint { margin: 0 0 16px; padding: 0 4px; font-size: 0.8125rem; color: var(--color-muted); }
.hint--after { margin-top: 16px; }

.item-image__preview { display: block; width: 100%; max-width: 360px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-fill); }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--color-fill-strong);
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--color-muted);
  vertical-align: 0.15em;
  letter-spacing: 0.04em;
}

/* ---- ログイン ---- */

.login { max-width: 380px; margin: 0 auto; padding: 72px 16px 32px; }
.login__mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(145deg, #06b6d4, #1d4ed8);
  color: #fff;
  font-size: 1.875rem;
  font-weight: 800;
  box-shadow: 0 8px 22px rgb(29 78 216 / 0.32);
}
.login__title { margin: 0; font-size: 1.375rem; font-weight: 800; text-align: center; }
.login__lead { margin: 4px 0 24px; text-align: center; color: var(--color-muted); font-size: 0.9375rem; }

/* ---- 単価一覧 ---- */

/* 画面下の保存バーに隠れないよう余白を取る */
.price-form { padding-bottom: 112px; }

.price-group { margin-bottom: 24px; }
.price-group__title,
.item-group__title {
  margin: 0 0 6px;
  padding: 0 16px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-muted);
  letter-spacing: 0.04em;
}

.price-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 12px;
  padding: 12px 14px 12px 16px;
  transition: background-color 0.2s var(--ease);
}
/* 区切り線は左を空けて内側に寄せる(iOS の一覧と同じ) */
.price-row + .price-row::before,
.item-row + .item-row::before,
.history__row + .history__row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: 1px solid var(--color-separator);
}
/* 変更・エラーの行は左端に色の帯を出す */
.price-row::after {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: transparent;
  transition: background-color 0.2s var(--ease);
}
.price-row.is-dirty { background: var(--color-dirty-bg); }
.price-row.is-dirty::after { background: var(--color-dirty-border); }
.price-row.is-invalid { background: var(--color-danger-bg); }
.price-row.is-invalid::after { background: var(--color-danger); }

.price-row__label { display: grid; min-width: 0; gap: 1px; }
.price-row__name { font-weight: 700; overflow-wrap: anywhere; }
.price-row__note { font-size: 0.8125rem; color: var(--color-muted); }
.price-row__meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: start;
  margin-top: 2px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-faint);
  text-decoration: none;
  white-space: nowrap;
}
.price-row__meta .icon { width: 13px; height: 13px; }

.price-row__input { display: flex; align-items: center; gap: 6px; }
.price-row__input input {
  width: 6.4em;
  min-height: var(--tap);
  padding: 8px 12px;
  font-size: 1.125rem;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  scroll-margin-top: 140px;
}
.price-row__input input::placeholder { font-size: 0.875rem; font-weight: 600; }
.price-row.is-dirty .price-row__input input:not(:focus) { background: var(--color-surface); border-color: var(--color-dirty-border); }
.price-row.is-invalid .price-row__input input { background: var(--color-surface); border-color: var(--color-danger); }
.price-row__unit { min-width: 2.8em; font-size: 0.75rem; font-weight: 600; color: var(--color-faint); white-space: nowrap; }

.price-row__error { grid-column: 1 / -1; margin: 0; font-size: 0.8125rem; font-weight: 600; color: var(--color-danger); }
.price-row__error:empty { display: none; }

/* 片手で押せるよう、保存ボタンは画面の下に浮かせる */
.save-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 696px;
  margin: 0 auto;
  padding: 8px 8px 8px 18px;
  border-radius: 18px;
  background: rgb(255 255 255 / 0.88);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: var(--shadow-float);
}
.save-bar__status { flex: 1; font-size: 0.875rem; font-weight: 600; color: var(--color-muted); font-variant-numeric: tabular-nums; }
.save-bar .btn--primary { min-width: 8.5em; }
.save-bar .btn--ghost { color: var(--color-muted); }

/* ---- 品目・カテゴリ ---- */

.item-group { margin-bottom: 24px; scroll-margin-top: 140px; }
.item-group__head { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; padding-right: 4px; }
.item-group__head .item-group__title { flex: 1; margin: 0; }
.item-group__head .btn--icon { width: 34px; min-height: 34px; background: transparent; }
.item-group__head .btn--icon .icon { width: 18px; height: 18px; }

.move { display: inline-flex; gap: 4px; }
.move form { margin: 0; }

.item-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 10px 16px;
  scroll-margin-top: 140px;
  transition: background-color 0.4s var(--ease);
}
.item-row:target { background: var(--color-dirty-bg); }
.item-row--empty { margin: 0; color: var(--color-faint); font-size: 0.875rem; }
.item-row__label { flex: 1; display: grid; min-width: 0; gap: 1px; }
.item-row__thumb { width: 44px; height: 44px; flex-shrink: 0; margin-right: 4px; border-radius: 8px; object-fit: cover; background: var(--color-fill); }
.item-row__thumb--empty { display: block; border: 1px dashed var(--color-fill-strong); }
.item-row__name { font-weight: 700; overflow-wrap: anywhere; }
.item-row__note { font-size: 0.8125rem; color: var(--color-muted); }
.item-row__note a { font-weight: 600; text-decoration: none; }

.add-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  color: var(--color-accent);
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
}

.danger-zone { margin-top: 20px; }
.danger-zone form { margin: 0; }

/* ---- 履歴 ---- */

.history-head { display: grid; gap: 2px; margin-bottom: 20px; }
.history-head p { margin: 0; }
.history-head__category { font-size: 0.75rem; font-weight: 700; color: var(--color-faint); letter-spacing: 0.06em; }
.history-head__name { font-size: 1.25rem; font-weight: 800; }
.history-head__note { font-size: 0.875rem; color: var(--color-muted); }
.history-head__links { display: flex; gap: 8px; margin-top: 10px !important; }
.history-head__links a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--color-fill);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

.history { margin: 0 0 16px; padding: 0; list-style: none; }
.history__row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 12px 16px;
}
.history__date { grid-column: 1 / -1; font-size: 0.75rem; font-weight: 600; color: var(--color-faint); }
.history__change { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.history__old { color: var(--color-faint); font-weight: 600; }
.history__new { font-size: 1.25rem; font-weight: 800; letter-spacing: 0; }
.history__new small { margin-left: 3px; font-size: 0.75rem; font-weight: 600; color: var(--color-faint); }
.history__diff {
  align-self: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.history__diff:empty { display: none; }
.history__diff--up { background: rgb(215 0 21 / 0.08); color: var(--color-up); }
.history__diff--down { background: rgb(10 100 216 / 0.08); color: var(--color-down); }
.history__more { width: 100%; margin-bottom: 8px; }

/* ---- 設定 ---- */

.logo-settings__preview { display: flex; align-items: center; padding: 16px; border-radius: var(--radius-sm); background: var(--color-fill); }
.logo-settings__preview img { max-width: 240px; max-height: 56px; }
.logo-settings form { margin: 0; }
input[type="file"] { font: inherit; font-size: 0.875rem; }
input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 8px 14px;
  border: none;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.public-url { margin: 0; overflow-wrap: anywhere; font-weight: 600; }

@media (hover: hover) {
  .header-action:hover { background: var(--color-accent-soft); }
  .btn--icon:hover:not(:disabled), .btn--small:hover { background: var(--color-fill-strong); }
  .btn--primary:hover:not(:disabled) { background-image: var(--gradient-primary-hover); }
  a.price-row__meta:hover { color: var(--color-accent); }
}

/* ---- 単価一覧:価格を公開ページに表示するスイッチ ---- */

.price-row__controls { display: grid; justify-items: end; gap: 6px; }
.badge--warn { background: #fff1db; color: #a15c00; }

.price-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-muted);
  cursor: pointer;
  user-select: none;
}
/* チェックボックスは見えなくして、iOS 風のスイッチを描く(キーボードと読み上げでは本物のチェックボックスとして動く) */
.price-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.price-switch__track {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 22px;
  border-radius: 999px;
  background: var(--color-fill-strong);
  transition: background-color 0.2s var(--ease);
}
.price-switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.2);
  transition: transform 0.2s var(--ease);
}
.price-switch input:checked + .price-switch__track { background: #22a35a; }
.price-switch input:checked + .price-switch__track::after { transform: translateX(14px); }
.price-switch input:focus-visible + .price-switch__track { outline: 3px solid var(--color-accent-soft); outline-offset: 2px; }
