/* 알레프 폰 화면 — 토큰은 scripts/dashboard_assets/style.css의 :root 복사 */
:root {
  --paper: #14110c;
  --paper-2: #1c1712;
  --paper-3: #2a231a;
  --card: #1a1510;
  --ink: #efe8d8;
  --ink-2: #cfc6b2;
  --ink-3: #a3977f;
  --rule: #2e2720;
  --rule-2: #4a4033;
  --wood: #b08f66;
  --wood-2: #8d6f4b;
  --gold: #e8b86d;

  --accent: #2a9d87;
  --accent-deep: #7fd6c5;
  --accent-soft: #163b35;
  --accent-light: #3fae9a;

  --fam-thesis: #2a9d87;
  --fam-bible: #c9682a;
  --fam-know: #8c78d4;
  --fam-bible-soft: #3b2415;
  --fam-know-soft: #2a2347;

  --ev-none: #c9682a;  --ev-none-soft: #3b2415;
  --ev-web: #3f8cc4;   --ev-web-soft: #162f45;
  --ev-lib: #6fa83b;   --ev-lib-soft: #1f3312;
  --ev-mix: #8c78d4;   --ev-mix-soft: #2a2347;
  --ev-text: #a3977f;  --ev-text-soft: #262019;

  --warn: #e8a35c;
  --mark: #5a4612;

  --serif: "KoPubWorld Batang", "Noto Serif KR", "AppleMyungjo", "Nanum Myeongjo", Georgia, serif;
  --sans: "Pretendard", "Apple SD Gothic Neo", -apple-system, BlinkMacSystemFont, "Noto Sans KR", "Segoe UI", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --rail: 232px;
  --radius: 10px;
  --dur: 220ms;
  --ease: cubic-bezier(.2,.7,.2,1);
  color-scheme: dark;

  /* 이 화면 전용 */
  --danger: #e07a6a;
  --danger-soft: #3a1c16;
  --gutter: 16px;
  --touch: 44px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--accent-deep); }
:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  min-height: 100dvh;
}
.view { padding-bottom: 32px; }
.section-title { font-family: var(--sans); font-size: 13px; font-weight: 600; letter-spacing: .08em; color: var(--ink-3); margin: 28px 0 10px; padding: 0; }

/* ── 브랜드 ── */
.brand { display: flex; align-items: center; gap: 14px; padding: calc(20px + env(safe-area-inset-top)) 0 18px; }
.aleph { font-family: var(--serif); font-size: 34px; line-height: 1; color: var(--gold); width: 52px; height: 52px; display: grid; place-items: center; border: 1px solid var(--rule-2); border-radius: 12px; background: var(--card); box-shadow: inset 0 0 0 4px var(--paper), 0 0 24px -8px rgba(232,184,109,.35); }
.brand-text h1 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; line-height: 1.2; letter-spacing: -.01em; }
.brand-text small { color: var(--ink-3); font-size: 13px; font-family: var(--serif); }

/* ── 계기판 ── */
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; color: var(--ink-2); }
.gauge-label { color: var(--ink-3); }
.gauge-num { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.bar { position: relative; height: 8px; border-radius: 99px; background: var(--paper-3); overflow: hidden; margin-top: 6px; box-shadow: inset 0 0 0 1px var(--rule); }
.bar .fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-light)); transition: width var(--dur) var(--ease), background var(--dur) var(--ease); }
.credit { padding: 14px 16px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); }
.credit .fill { background: linear-gradient(90deg, var(--wood-2), var(--gold)); }
.credit.low .fill { background: var(--danger); }
.credit.low .gauge-num { color: var(--danger); }
.credit.off .gauge-num { color: var(--ink-3); font-weight: 400; }

/* ── 버튼 ── */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--touch); padding: 10px 16px; border: 1px solid var(--rule-2); border-radius: var(--radius); background: var(--paper-2); color: var(--ink); font-size: 16px; cursor: pointer; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease); -webkit-tap-highlight-color: transparent; }
.btn:hover { border-color: var(--wood); }
.btn:active { background: var(--paper-3); }
.btn.primary { background: var(--accent-soft); border-color: var(--accent); color: #e8fbf6; font-weight: 600; }
.btn.primary:hover { border-color: var(--accent-deep); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wide { width: 100%; margin-top: 20px; }
.icon-btn { display: grid; place-items: center; width: var(--touch); height: var(--touch); margin-left: -10px; border: 0; border-radius: var(--radius); background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn svg { width: 24px; height: 24px; }

/* ── 세션 카드 ── */
.sessions { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.s-card { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: start; width: 100%; min-height: var(--touch); padding: 14px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); text-align: left; cursor: pointer; transition: border-color var(--dur) var(--ease); }
.s-card:hover { border-color: var(--rule-2); }
.s-card.ended { opacity: .72; }
.s-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--paper-3); color: var(--gold); }
.s-icon svg { width: 22px; height: 22px; }
.s-title { font-family: var(--serif); font-size: 17px; line-height: 1.4; color: var(--ink); display: block; }
.s-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; padding: 0 8px; border-radius: 99px; border: 1px solid var(--rule-2); color: var(--ink-3); }
.note { color: var(--ink-3); font-size: 15px; margin: 14px 0; }
.note.error { color: var(--danger); }
.empty { padding: 28px 18px; border: 1px dashed var(--rule-2); border-radius: var(--radius); color: var(--ink-3); text-align: center; font-family: var(--serif); }

/* 화면당 모션 한 번: 홈 카드·새 세션 타일이 올라옴 */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.rise { animation: rise 420ms var(--ease) both; animation-delay: calc(var(--i, 0) * 45ms); }

/* ── 상단 바 ── */
.topbar { display: flex; align-items: center; gap: 6px; min-height: 56px; padding-top: env(safe-area-inset-top); }
.topbar-title { flex: 1; min-width: 0; margin: 0; font-family: var(--serif); font-weight: 600; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── 새 세션 ── */
.types { border: 0; margin: 0; padding: 0; min-width: 0; }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-tile { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 14px; min-height: 128px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); cursor: pointer; transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease); }
.type-tile input { position: absolute; opacity: 0; pointer-events: none; }
.type-tile .s-icon { width: 36px; height: 36px; margin-bottom: 4px; }
.type-name { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.type-desc { font-size: 14px; color: var(--ink-2); line-height: 1.5; }
.type-model { margin-top: auto; padding-top: 6px; font-size: 12px; color: var(--accent-deep); letter-spacing: .02em; }
.type-tile:has(input:checked) { border-color: var(--gold); background: linear-gradient(180deg, rgba(232,184,109,.08), transparent 70%), var(--card); }
.type-tile:has(input:focus-visible) { outline: 2px solid var(--accent-deep); outline-offset: 2px; }
.field input, textarea { width: 100%; min-height: var(--touch); padding: 10px 14px; border: 1px solid var(--rule-2); border-radius: var(--radius); background: var(--paper-2); font-size: 16px; line-height: 1.5; }
.field input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(42,157,135,.25); }
.field input:disabled { color: var(--ink-3); }
.help { font-size: 14px; color: var(--ink-3); margin: 6px 0 0; }
.field label.section-title { display: block; }

/* ── 채팅 ── */
.chat-top { position: sticky; top: 0; z-index: 5; background: var(--paper); margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter) 10px; border-bottom: 1px solid var(--rule); }
.chat-cost { font-size: 14px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.meters { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; align-items: start; }
.meter.small .gauge-head { font-size: 13px; }
.meter.credit.small { padding: 0; border: 0; background: none; }
.kind-tag { font-size: 13px; color: var(--accent-deep); white-space: nowrap; }
.ctx-bar .tick { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink-3); opacity: .8; }
.ctx-bar .t100 { left: 10%; }
.ctx-bar .t150 { left: 15%; background: var(--warn); }
.ctx.over .fill { background: linear-gradient(90deg, var(--accent), var(--warn)); }
.ctx.over2 .fill { background: linear-gradient(90deg, var(--warn), var(--danger)); }
.ticks-legend { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 4px; font-size: 12px; color: var(--ink-3); }
.ticks-legend .tk { display: inline-block; width: 2px; height: 10px; margin-right: 5px; vertical-align: -1px; background: var(--ink-3); }
.ticks-legend .tk.t150 { background: var(--warn); }
.band { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.band.warn { background: var(--mark); color: #f6dfae; border: 1px solid rgba(232,184,109,.4); }

.messages { display: flex; flex-direction: column; gap: 14px; padding: 18px 0 12px; min-height: 40vh; }
.msg { max-width: 92%; padding: 12px 14px; border-radius: 14px; line-height: 1.75; }
.msg.user { align-self: flex-end; border: 1px solid var(--gold); background: rgba(232,184,109,.06); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.user.pending { border-style: dashed; }
.msg.user.failed { border-color: var(--danger); }
.msg.user .fail { display: block; margin-top: 4px; font-size: 13px; color: var(--danger); white-space: normal; }
.msg.agent { align-self: flex-start; max-width: 100%; font-family: var(--serif); font-size: 17px; border: 1px solid var(--rule); background: var(--card); border-bottom-left-radius: 4px; }
.msg.agent.streaming { border-color: var(--accent-soft); }
.msg .who { font-family: var(--sans); font-size: 12px; color: var(--ink-3); display: block; margin-bottom: 2px; }
.empty-chat { color: var(--ink-3); text-align: center; font-family: var(--serif); margin: 24px 0; }

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .8em; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; line-height: 1.35; margin: 1.1em 0 .45em; color: var(--ink); }
.md h1 { font-size: 21px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; color: var(--gold); } .md h4 { font-size: 16px; font-family: var(--sans); }
.md ul, .md ol { margin: 0 0 .8em; padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md li > ul, .md li > ol { margin: .2em 0; }
.md blockquote { margin: 0 0 .8em; padding: 4px 0 4px 14px; border-left: 3px solid var(--wood-2); color: var(--ink-2); }
.md code { font-family: var(--mono); font-size: .84em; background: var(--paper-3); padding: 1px 5px; border-radius: 4px; }
.md pre { margin: 0 0 .8em; padding: 12px 14px; background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; overflow-x: auto; font-size: 14px; line-height: 1.55; }
.md pre code { background: none; padding: 0; font-size: inherit; white-space: pre; }
.md hr { border: 0; border-top: 1px solid var(--rule-2); margin: 1em 0; }
.md strong { font-weight: 600; color: var(--ink); }
.md a { text-underline-offset: 3px; overflow-wrap: anywhere; }
.md-table { overflow-x: auto; margin: 0 0 .8em; border: 1px solid var(--rule); border-radius: 8px; }
.md table { border-collapse: collapse; font-family: var(--sans); font-size: 14px; min-width: 100%; }
.md th, .md td { padding: 7px 10px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; word-break: keep-all; }
.md th { background: var(--paper-2); color: var(--ink-2); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }

/* 도구 호출: 접힌 한 줄 */
.tool { align-self: stretch; font-family: var(--mono); font-size: 13px; color: var(--ink-3); }
.tool summary { list-style: none; cursor: pointer; min-height: 32px; display: flex; align-items: center; padding: 4px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary span { overflow: hidden; text-overflow: ellipsis; }
.tool[open] summary { color: var(--ink-2); }
.tool pre { margin: 2px 0 0; padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--paper-2); border-radius: 6px; color: var(--ink-2); }

/* 하단: 상태 띠 + 입력 */
.chat-bottom { position: sticky; bottom: 0; z-index: 5; background: var(--paper); margin: 0 calc(var(--gutter) * -1); padding: 8px var(--gutter) calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--rule); }
.view[data-view="chat"] { padding-bottom: 0; }
.status { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 14px; color: var(--ink-2); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.status[data-kind="running"] .dot { background: var(--accent-light); box-shadow: 0 0 0 3px var(--accent-soft); }
.status[data-kind="running"] { color: var(--accent-deep); }
.status[data-kind="budget"], .status[data-kind="action"] { color: var(--warn); }
.status[data-kind="budget"] .dot, .status[data-kind="action"] .dot { background: var(--warn); }
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="error"] .dot { background: var(--danger); }
.status[data-kind="ended"] .dot { background: var(--rule-2); }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 48px; max-height: 40vh; resize: none; }
.composer .send { flex: none; min-height: 48px; }
.chat-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.chat-actions .btn { font-size: 15px; padding: 8px 6px; }

/* 모달 */
.sheet { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 20px; border: 1px solid var(--rule-2); border-radius: 14px; background: var(--paper-2); color: var(--ink); }
.sheet::backdrop { background: rgba(8,6,4,.72); }
.sheet h2 { font-family: var(--serif); font-weight: 600; font-size: 19px; margin: 0 0 4px; }
.sheet textarea { margin-top: 14px; resize: vertical; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* 토스트 */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; width: max-content; max-width: calc(100vw - 32px); padding: 12px 16px; border: 1px solid var(--accent); border-radius: var(--radius); background: var(--accent-soft); color: #e8fbf6; font-size: 15px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.6); overflow-wrap: anywhere; }
.toast.error { border-color: var(--danger); background: var(--danger-soft); color: #fbe3de; }

@media (min-width: 900px) {
  .brand { padding-top: 40px; }
  .type-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 360px) {
  .meters { grid-template-columns: 1fr; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 폰 폭에서 채팅 상단 크레딧 게이지: 라벨 줄바꿈 방지, 숫자만 한 줄로 */
.meter.small .gauge-head { flex-wrap: nowrap; white-space: nowrap; }
.meter.small .gauge-label { flex: 0 0 auto; }
.meter.small .gauge-num { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: right; font-size: 12px; }
@media (max-width: 420px) { .meter.small .gauge-label { display: none; } }
