/* BASO 管理画面（2026-11-26 作り直し：携帯でもアプリのように使えるように）
   - スマホが基本。上にタイトルの帯、下に主なタブ。表はカードの形にする（dom.ts の labelTables が見出しを付ける）
   - 900px 以上は左に全部のメニュー
   - 外部のフォント・画像は使わない（CSP：style-src 'self'） */
:root {
  --fg: #0f172a;
  --muted: #64748b;
  --bg: #f3f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #dc2626;
  --warn: #fff7e0;
  --ok: #e9f8f0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  --tabbar: 64px;
  color-scheme: light;
}
* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", Meiryo,
    sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.65;
  font-size: 15px;
  overflow-x: hidden;
}
a {
  color: var(--accent);
}

/* ---- 上の帯 ---- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: .02em;
}
.logo {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
}
.role {
  font-size: .75rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

/* ---- 本文 ---- */
.shell {
  min-height: calc(100vh - 56px);
}
main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar) + 28px + env(safe-area-inset-bottom));
}
.shell.guest main {
  padding-bottom: 32px;
}
h1 {
  font-size: 1.45rem;
  line-height: 1.35;
  margin: 6px 0 16px;
  letter-spacing: .01em;
}
h2 {
  font-size: 1.08rem;
  margin: 26px 0 10px;
}
h3 {
  font-size: 1rem;
  margin: 18px 0 8px;
}
main > section,
main > form,
main > dl.info,
main > details,
main > .card,
main > table {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 0 14px;
}
main > table {
  padding: 4px 0;
}

/* ---- 入力・ボタン（指で押しやすい大きさ。16px 以上で iPhone の拡大を防ぐ） ---- */
form {
  display: grid;
  gap: 14px;
  max-width: 480px;
}
label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: .92rem;
}
input,
select,
textarea {
  font: inherit;
  font-size: 16px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  width: 100%;
  background: #fff;
  color: var(--fg);
}
input[type=checkbox],
input[type=radio] {
  width: 20px;
  min-height: 20px;
  height: 20px;
  accent-color: var(--accent);
}
textarea {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 14px;
  min-height: 120px;
}
textarea[readonly] {
  background: #f8fafc;
}
button {
  font: inherit;
  font-weight: 600;
  min-height: 46px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .06s ease, opacity .15s ease;
}
button:active {
  transform: scale(.98);
}
button:disabled {
  opacity: .5;
  cursor: default;
}
button.link {
  background: none;
  border: none;
  color: var(--accent);
  min-height: 0;
  padding: 0;
  text-decoration: underline;
  font-weight: 500;
}
button.danger {
  background: var(--danger);
  border-color: var(--danger);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}
details > summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 40px;
  display: flex;
  align-items: center;
}

/* ---- 表（パソコン）／カード（スマホ） ---- */
table {
  border-collapse: collapse;
  width: 100%;
}
th,
td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  font-size: .8rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
tr:last-child td {
  border-bottom: none;
}

/* ---- 知らせ・状態 ---- */
.error {
  color: var(--danger);
  font-weight: 600;
}
.notice {
  background: var(--ok);
  padding: 10px 14px;
  border-radius: 12px;
}
.banner {
  position: sticky;
  top: 56px;
  z-index: 25;
  background: var(--warn);
  padding: 10px 16px;
  border-bottom: 1px solid #f5d77a;
}
.small {
  color: var(--muted);
  font-size: .88rem;
}
.status {
  color: var(--muted);
}
.copy {
  margin-top: 6px;
}
tr.warned {
  background: var(--warn);
}
tr.reached {
  background: #fee2e2;
}
dl.info {
  display: grid;
  grid-template-columns: 8.5em 1fr;
  gap: 8px 14px;
}
dl.info dt {
  color: var(--muted);
  font-size: .88rem;
}
dl.info dd {
  margin: 0;
  word-break: break-word;
}
main > label {
  margin: 12px 0;
}

/* ---- 素材画像 ---- */
.stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.stock {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.stock img {
  width: 100%;
  height: auto;
  aspect-ratio: 3/2;
  object-fit: cover;
  display: block;
}
.stock figcaption {
  padding: 10px 12px;
  display: grid;
  gap: 8px;
  font-size: .9rem;
}
.stock.approved {
  border-color: #16a34a;
}
.stock.rejected {
  opacity: .5;
}

/* 条件の変更・公式情報（T3-9） */
label.field {
  display: block;
  margin: 10px 0;
}
label.field > input,
label.field > textarea,
label.field > select {
  display: block;
  width: 100%;
  max-width: 40rem;
  margin-top: 6px;
}
pre.terms {
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #f8fafc;
}

/* サブドメインの候補（T3-13） */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}
button.chip {
  min-height: 36px;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

/* 問い合わせの履歴（T4-1）：吹き出し */
.msg {
  margin: 10px 0;
  max-width: 88%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
}
.msg.out {
  margin-left: auto;
  background: var(--accent-soft);
  border-color: transparent;
  border-radius: 16px 16px 4px 16px;
}

/* ---- メニュー ---- */
.icon {
  width: 24px;
  height: 24px;
  flex: none;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  background: none;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.nav-item[aria-current=page] {
  color: var(--accent);
}
.nav-group {
  margin: 4px 12px 6px;
  font-size: .75rem;
  color: var(--muted);
  letter-spacing: .08em;
}

/* スマホ：下のタブ＋「メニュー」で開く一覧 */
@media (max-width: 899px) {
  .appnav .nav-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: saturate(1.4) blur(10px);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-top: 1px solid var(--line);
  }
  .appnav .nav-bar .nav-item {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-height: 0;
    padding: 6px 0;
    border-radius: 0;
    font-size: .68rem;
    font-weight: 600;
    color: var(--muted);
  }
  .appnav .nav-bar .nav-item[aria-current=page],
  .appnav.open .more-toggle {
    color: var(--accent);
  }
  .appnav .nav-more {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 10px);
    z-index: 39;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 12px;
    background: var(--card);
    border-radius: 18px;
    box-shadow: 0 10px 40px rgba(15, 23, 42, .22);
    transform: translateY(16px);
    opacity: 0;
    visibility: hidden;
    transition: transform .18s ease, opacity .18s ease, visibility .18s;
  }
  .appnav.open .nav-more {
    transform: none;
    opacity: 1;
    visibility: visible;
  }
  .appnav .nav-more .nav-group {
    grid-column: 1 / -1;
  }
  .appnav .nav-more .nav-item {
    min-height: 52px;
    padding: 8px 12px;
    font-size: .9rem;
  }
  .appnav .nav-more .nav-item:active {
    background: var(--bg);
  }
  .appnav .nav-more .logout {
    grid-column: 1 / -1;
    color: var(--danger);
    border-top: 1px solid var(--line);
    border-radius: 0 0 10px 10px;
    margin-top: 4px;
  }

  /* 表をカードの形に（見出しを左に） */
  table.cards-sm,
  table.cards-sm tbody,
  table.cards-sm tr,
  table.cards-sm td {
    display: block;
    width: 100%;
  }
  table.cards-sm thead,
  table.cards-sm tr:has(> th) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  main > table.cards-sm {
    background: none;
    box-shadow: none;
    padding: 0;
  }
  table.cards-sm tr {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin: 0 0 12px;
    padding: 6px 0;
  }
  table.cards-sm td {
    display: grid;
    grid-template-columns: 7.5em 1fr;
    gap: 10px;
    border-bottom: 1px solid var(--line);
    padding: 9px 14px;
    word-break: break-word;
  }
  table.cards-sm td:last-child {
    border-bottom: none;
  }
  table.cards-sm td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: .8rem;
    font-weight: 600;
  }
  table.cards-sm td:first-child {
    font-weight: 700;
  }
  table.cards-sm td:not([data-label]),
  table.cards-sm td[data-label=""] {
    grid-template-columns: 1fr;
  }
  .actions > button {
    flex: 1 1 auto;
  }
  dl.info {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  dl.info dd {
    margin-bottom: 10px;
  }
}

/* パソコン：左に全部のメニュー */
@media (min-width: 900px) {
  .shell:not(.guest) {
    display: grid;
    grid-template-columns: 236px 1fr;
  }
  .appnav {
    position: sticky;
    top: 56px;
    align-self: start;
    height: calc(100vh - 56px);
    overflow-y: auto;
    padding: 16px 12px;
    border-right: 1px solid var(--line);
    background: var(--card);
  }
  .appnav .nav-bar,
  .appnav .nav-more {
    display: grid;
    gap: 2px;
  }
  .appnav .nav-more {
    margin-top: 14px;
  }
  .appnav .more-toggle {
    display: none;
  }
  .appnav .nav-item {
    padding: 9px 12px;
    font-size: .92rem;
    color: #334155;
  }
  .appnav .nav-item:hover {
    background: var(--bg);
  }
  .appnav .nav-item[aria-current=page] {
    background: var(--accent-soft);
    color: var(--accent);
  }
  .appnav .nav-item .icon {
    width: 20px;
    height: 20px;
  }
  .appnav .logout {
    margin-top: 10px;
    color: var(--muted);
  }
  main {
    padding: 24px 28px 48px;
  }
  table {
    background: var(--card);
  }
}

/* ---- 状態の表示（chip）・案件ボード ---- */
.chip-s {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  background: #eef2f7;
  color: #334155;
  white-space: nowrap;
}
.chip-s.good {
  background: var(--ok);
  color: #15803d;
}
.chip-s.warn {
  background: #fff4d6;
  color: #a16207;
}
.chip-s.bad {
  background: #fde8e8;
  color: var(--danger);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
table.board td:first-child a {
  font-weight: 700;
  text-decoration: none;
}
@media (max-width: 899px) {
  /* カード全体を押すと案件が開く（リンクの当たりの範囲をカードに広げる） */
  table.board tr {
    position: relative;
  }
  table.board td:first-child a::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
  }
  table.board td:first-child {
    font-size: 1.05rem;
  }
  table.board tr:active {
    transform: scale(.99);
  }
}
table.cards-sm td > .chip-s {
  justify-self: start;
  align-self: center;
}
@media (min-width: 900px) {
  .shell:not(.guest) main {
    margin: 0;
    max-width: 1100px;
  }
}
