/* AICC 公司版 · StarStageJapan theme (DESIGN.md「Backstage Ledger / 舞台裏の明細帳」): Simple Light by default, Stage Dark on request.
   Semantic tokens only; components never use literal colours. */
:root {
  --bg: #F7F4EF; --surface: #FFFFFF; --surface-2: #F0EDF1; --surface-3: #E8E4E9;
  --text: #18151C; --muted: #625B68; --faint: #827A87; --border: #DED8E0; --border-strong: #BDB5C0;
  --primary: #C30765; --primary-strong: #A60055; --on-primary: #FFFFFF;
  --success: #08794F; --warning: #8A6518; --danger: #B42336; --info: #087D91; --gold: #8A6518;
  --shadow: 0 12px 32px rgba(24, 21, 28, .14);
  --r-sm: 4px; --r: 8px; --r-lg: 12px;
  --font: "Noto Sans JP", "Noto Sans SC", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  --serif: "Noto Serif JP", "Noto Serif SC", "Hiragino Mincho ProN", "Yu Mincho", "Songti SC", serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #05040B; --surface: #0F1020; --surface-2: #12142D; --surface-3: #191A33;
  --text: #F7F0E9; --muted: #BBB4C3; --faint: #858092; --border: #343448; --border-strong: #56566D;
  --primary: #FF73B1; --primary-strong: #EE5DA5; --on-primary: #18151C;
  --success: #2BD993; --warning: #D7B45A; --danger: #FF5C6C; --info: #58E7FF; --gold: #D7B45A;
  --shadow: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.65 var(--font); -webkit-font-smoothing: antialiased; line-break: strict; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: var(--r); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600; font-size: 15px; text-decoration: none; white-space: nowrap; transition: background .09s, border-color .09s; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 14px; }
.btn.icon { width: 40px; padding: 0; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--muted); }
.field small { color: var(--faint); font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); }
textarea { resize: vertical; min-height: 88px; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-size: 15px; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 14px; }
.mono { font-family: var(--mono); font-size: 13px; }
.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 8px; border-radius: var(--r-sm); border: 1px solid var(--border); font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; background: currentColor; border-radius: 1px; }
.badge.success { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }
.badge.warning { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); }
.badge.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.badge.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, var(--border)); }
.badge.plain::before { display: none; }
.alert { border: 1px solid var(--border); border-left: 4px solid var(--info); background: var(--surface); padding: 12px 16px; border-radius: var(--r); margin: 12px 0; }
.alert.warning { border-left-color: var(--warning); }
.alert.danger { border-left-color: var(--danger); }
.alert.success { border-left-color: var(--success); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 20px; }
.card + .card { margin-top: 12px; }
.card h3 { margin: 0 0 4px; font-size: 18px; line-height: 1.4; }
.toast-box { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--r); box-shadow: var(--shadow); font-size: 15px; max-width: min(560px, 90vw); }
.toast.bad { background: var(--danger); color: #fff; }
.star { display: inline-block; width: 22px; height: 22px; background: var(--primary); clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%); flex: 0 0 auto; }

/* ---------- auth pages */
.auth { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; background:
  linear-gradient(120deg, transparent 0 62%, color-mix(in srgb, var(--primary) 6%, transparent) 62% 63%, transparent 63%), var(--bg); }
.auth-box { width: min(420px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.auth-brand b { font-family: var(--serif); font-size: 26px; letter-spacing: .02em; }
.auth-brand span { color: var(--muted); font-size: 14px; }
.auth h1 { font-family: var(--serif); font-size: 26px; line-height: 1.35; margin: 0 0 8px; }
.auth .lead { color: var(--muted); margin: 0 0 20px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 14px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ---------- app shell */
.shell { display: grid; grid-template-columns: 288px 1fr; height: 100%; }
.scrim { display: none; }
.side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); display: grid; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { font-family: var(--serif); font-size: 20px; letter-spacing: .02em; }
.brand small { color: var(--faint); font-size: 12px; display: block; line-height: 1.2; }
.side-list { flex: 1; overflow: auto; padding: 8px; min-height: 0; }
.side-label { font-size: 12px; font-weight: 700; color: var(--faint); letter-spacing: .08em; padding: 12px 8px 4px; text-transform: uppercase; }
.conv { display: block; padding: 8px 10px; border-radius: var(--r); color: var(--text); text-decoration: none; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: color-mix(in srgb, var(--primary) 10%, var(--surface)); color: var(--primary); font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); }
.side-nav { border-top: 1px solid var(--border); padding: 8px; display: grid; gap: 2px; }
.nav-link { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border-radius: var(--r); color: var(--text); text-decoration: none; font-size: 15px; }
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--surface-3); font-weight: 600; }
.nav-link .count { margin-left: auto; background: var(--primary); color: var(--on-primary); border-radius: 999px; font-size: 12px; min-width: 20px; height: 20px; display: grid; place-items: center; padding: 0 6px; font-weight: 700; }
.side-user { border-top: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 999px; background: var(--surface-3); display: grid; place-items: center; font-weight: 700; color: var(--primary); flex: 0 0 auto; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.page { flex: 1; overflow: auto; padding: 28px 32px 48px; min-height: 0; }
.page-inner { max-width: 1040px; margin: 0 auto; }
.page h1 { font-family: var(--serif); font-size: 30px; line-height: 1.35; margin: 0 0 6px; font-weight: 600; }
.page .lead { color: var(--muted); margin: 0 0 20px; max-width: 72ch; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 0 20px; overflow-x: auto; }
.tab { border: none; background: none; text-decoration: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.list-empty { padding: 32px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--r-lg); }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
table.data th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border-strong); background: var(--surface-2); position: sticky; top: 0; }
table.data td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.modal-wrap { position: fixed; inset: 0; background: rgba(5, 4, 11, .45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 24px; }
.modal h2 { margin: 0 0 12px; font-size: 20px; }
.copybox { display: flex; gap: 8px; align-items: stretch; margin: 8px 0 16px; }
.copybox code { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface-2); font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }

/* ---------- chat */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface); min-height: 60px; }
.chat-head h2 { margin: 0; font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-scroll { flex: 1; overflow: auto; min-height: 0; padding: 24px; }
.chat-inner { max-width: 820px; margin: 0 auto; display: grid; gap: 18px; }
.msg { display: grid; gap: 6px; }
.msg.user { justify-items: end; }
.msg.user .bubble { background: color-mix(in srgb, var(--primary) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border)); border-radius: var(--r-lg) var(--r-lg) var(--r-sm) var(--r-lg); padding: 10px 14px; max-width: min(640px, 92%); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .bubble { padding: 2px 0; max-width: 100%; overflow-wrap: anywhere; }
.msg .meta { font-size: 12px; color: var(--faint); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.msg.error .bubble { border-left: 3px solid var(--danger); padding-left: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--muted); text-decoration: none; max-width: 100%; }
.chip b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.chip:hover { border-color: var(--primary); }
.chip.err { color: var(--danger); }
.attach { display: flex; gap: 8px; flex-wrap: wrap; }
.attach img { max-width: 240px; max-height: 200px; border-radius: var(--r); border: 1px solid var(--border); display: block; }
.notice { text-align: center; font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.notice::before, .notice::after { content: ""; flex: 1; border-top: 1px dashed var(--border-strong); }
.md { line-height: 1.75; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { line-height: 1.4; margin: 1.1em 0 .4em; } .md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 15px; display: block; overflow-x: auto; font-variant-numeric: tabular-nums; }
.md th, .md td { border: 1px solid var(--border-strong); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface-2); }
.md code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: var(--r-sm); }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 12px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 10px 0; padding: 4px 14px; border-left: 3px solid var(--gold); color: var(--muted); background: color-mix(in srgb, var(--gold) 6%, transparent); }
.md img { max-width: 100%; border-radius: var(--r); }
.cursor::after { content: "▍"; color: var(--primary); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 12px 24px 16px; }
.composer-inner { max-width: 820px; margin: 0 auto; }
.composer-box { border: 1px solid var(--border-strong); border-radius: var(--r-lg); background: var(--surface); padding: 8px; display: grid; gap: 6px; }
.composer-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent); }
.composer textarea { border: none; min-height: 48px; max-height: 240px; resize: none; padding: 6px 8px; box-shadow: none !important; }
.composer .pending { display: flex; gap: 6px; flex-wrap: wrap; }
.chat.dragging .composer-box { border-style: dashed; border-color: var(--primary); }
.empty-chat { text-align: center; padding: 8vh 12px 0; }
.empty-chat h2 { font-family: var(--serif); font-size: 28px; margin: 12px 0 8px; font-weight: 600; }
.empty-chat p { color: var(--muted); max-width: 60ch; margin: 0 auto 20px; }
.examples { display: grid; gap: 8px; max-width: 560px; margin: 0 auto; }
.example { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: var(--r); padding: 12px 14px; cursor: pointer; }
.example:hover { border-color: var(--primary); }
.case-card { border: 1px solid var(--border); border-left: 4px solid var(--info); background: var(--surface); border-radius: var(--r); padding: 12px 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; text-decoration: none; color: var(--text); }
.case-card:hover { border-color: var(--primary); }

/* ---------- lists */
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px 18px; }
.item + .item { margin-top: 10px; }
.item-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.item h3 { margin: 0; font-size: 17px; line-height: 1.45; }
.item .body { margin-top: 8px; display: grid; gap: 4px; font-size: 15px; }
.item .body b { color: var(--muted); font-weight: 600; margin-right: 6px; }
.item .foot { margin-top: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--faint); }
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { max-width: 360px; }
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.timeline li { display: grid; grid-template-columns: 92px 1fr; gap: 12px; font-size: 14px; }
.timeline time { color: var(--faint); font-family: var(--mono); font-size: 12px; padding-top: 2px; }

/* ---------- phone / tablet */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 30; transform: translateX(-102%); transition: transform .24s ease-out; box-shadow: var(--shadow); }
  .shell.menu-open .side { transform: none; }
  .scrim { display: none; }
  .shell.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(5, 4, 11, .4); z-index: 20; }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); min-height: 56px; }
  .topbar .brand b { font-size: 18px; }
  .page { padding: 20px 16px 40px; }
  .page h1 { font-size: 24px; }
  .chat-head { padding: 10px 16px; }
  .chat-scroll { padding: 16px; }
  .composer { padding: 10px 12px 12px; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }
}
