/* 디자인 방향: 공급받는자 보관용 세금계산서(청색 양식). 남색 잉크, 옅은 청색 칸, 괘선.
   배치: 남색 목록 | 옅은 청회색 바탕 위의 흰 서류. 괘선 표는 서류 카드에만 쓴다.
   어르신 사용성을 위해 본문과 입력 글자는 16px, 주요 버튼 높이는 44px 아래로 줄이지 않는다
   (입력 글자가 16px보다 작으면 아이폰이 화면을 확대한다) */
:root {
  --ink: #1b2f6b;        /* 양식의 청색 잉크 */
  --ink-deep: #14234f;
  --ink-soft: #c9d3ee;   /* 남색 위의 보조 글자 */
  --cell: #e9eef9;       /* 양식의 이름 칸 */
  --rule: #b9c6e4;       /* 괘선 */
  --bg: #f3f5fa;
  --surface: #ffffff;
  --hover: #e6ebf6;
  --text: #141a2b;
  --muted: #454e66;
  --border: #d5dcea;
  --field: #7683a3;
  --focus: rgba(27, 47, 107, .16);
  --ok: #0c5530;
  --ok-bg: #e0f2e7;
  --warn: #6e3b00;
  --warn-bg: #fdefd5;
  --err: #8f1d16;
  --err-bg: #fce6e3;
  --radius: 8px;
  --shadow-doc: 0 1px 2px rgba(20, 35, 79, .08), 0 6px 20px rgba(20, 35, 79, .07);
  --shadow-lg: 0 20px 56px rgba(10, 18, 45, .35);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
h1, h2, h3 { letter-spacing: -.02em; }

.ic {
  width: 1.15em; height: 1.15em; flex-shrink: 0; vertical-align: -.2em;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn .ic { width: 22px; height: 22px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--err); min-height: 1.6em; margin: 0; }

/* ---------- 버튼 ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-weight: 600;
  transition: background-color .15s ease, border-color .15s ease;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn-primary:hover:not(:disabled) { background: var(--ink-deep); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-secondary { background: var(--surface); }
.btn-big { min-height: 48px; font-size: 17px; padding: 9px 20px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; height: 44px; border: 0; background: transparent;
  border-radius: var(--radius); font-size: 20px;
}
.icon-btn:hover { background: var(--hover); }
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 4px; }

/* ---------- 로그인 ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--ink); }
.login-card {
  width: 100%; max-width: 350px; background: var(--surface);
  border: 1px solid transparent; border-radius: 12px; padding: 30px 26px 18px; box-shadow: var(--shadow-doc);
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 2px; border-radius: 12px;
  display: grid; place-items: center; background: var(--ink); color: #fff;
}
.login-logo .ic { width: 28px; height: 28px; }
.login-card h1 { margin: 0; font-size: 23px; }
.login-card p { margin: 0; }
.login-card input {
  height: 50px; border: 1.5px solid var(--field); border-radius: var(--radius);
  padding: 0 16px; font-size: 18px; text-align: center; background: var(--surface);
}
.login-card input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 4px var(--focus); }

/* ---------- 레이아웃 ---------- */
.app { display: flex; height: 100%; height: 100dvh; }
.sidebar {
  width: 264px; flex-shrink: 0; background: var(--ink); color: #fff;
  display: flex; flex-direction: column; padding: 14px 12px;
  border-right: 1px solid var(--ink);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 10px; letter-spacing: -.02em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: var(--radius); display: grid; place-items: center;
  background: #fff; color: var(--ink);
}
.btn-new { width: 100%; min-height: 46px; font-size: 16px; text-align: left; padding-left: 16px; border-color: #fff; color: var(--ink); display: flex; align-items: center; gap: 10px; box-shadow: none; }
.conv-list { flex: 1; overflow-y: auto; margin: 14px 0; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  display: flex; align-items: center; gap: 4px; border-radius: var(--radius);
}
.conv-item.active { background: #fff; color: var(--ink); font-weight: 700; }
.conv-item:hover { background: var(--ink-deep); }
.conv-item.active:hover { background: #fff; }
.conv-link {
  flex: 1; min-width: 0; border: 0; background: none; text-align: left;
  padding: 10px 10px; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-del { min-width: 40px; height: 40px; font-size: 16px; opacity: .75; }
.conv-del .ic { width: 20px; height: 20px; }
.conv-del:hover { opacity: 1; }
.sidebar-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 6px 0; border-top: 1px solid rgba(255, 255, 255, .22); }
.sidebar .muted, .sidebar .link-btn { color: var(--ink-soft); }
.sidebar .link-btn:hover { color: #fff; }
.sidebar .icon-btn:hover { background: rgba(255, 255, 255, .14); }
.sidebar .conv-item.active .icon-btn:hover { background: var(--cell); }
.sidebar :focus-visible { outline-color: #fff; outline-offset: -3px; }
.sidebar .active :focus-visible { outline-color: var(--ink); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface); min-height: 56px;
}
.conv-title { flex: 1; margin: 0; font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 13px; padding: 4px 10px; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.badge-test { background: var(--warn-bg); color: var(--warn); }

.scroll { flex: 1; overflow-y: auto; }
.messages, .empty { max-width: 720px; margin: 0 auto; padding: 24px 16px; }
.messages { display: flex; flex-direction: column; gap: 15px; }

/* ---------- 빈 화면 ---------- */
.empty { text-align: center; padding-top: 12vh; }
.empty h3 { font-size: 23px; margin: 0 0 6px; color: var(--ink); text-wrap: balance; }
.demo-note {
  max-width: 420px; margin: 18px auto 0; padding: 12px 16px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn); font-size: 14px; text-align: left;
}
.examples { display: flex; flex-direction: column; gap: 10px; margin: 22px auto; max-width: 420px; }
.example {
  border: 1px solid var(--rule); background: var(--surface); border-radius: var(--radius);
  padding: 13px 16px; text-align: left; font-size: 16px; font-weight: 600; color: var(--ink);
  transition: border-color .15s ease;
}
.example:hover { border-color: var(--ink); background: var(--cell); }

/* ---------- 메시지 ---------- */
.msg { display: flex; flex-direction: column; }
.msg-user { align-items: flex-end; }
.bubble { max-width: 85%; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; }
.msg-user .bubble { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 14px 14px 2px 14px; }
.msg-assistant .bubble { padding: 2px 2px; max-width: 100%; }
.msg-user img.thumb { max-width: 200px; border-radius: var(--radius); margin-bottom: 6px; border: 1px solid var(--border); }
.msg-notice .bubble {
  max-width: 100%; background: var(--ok-bg); color: var(--ok); padding: 12px 16px;
  border-radius: var(--radius); font-weight: 600;
}
.msg-notice.notice-fail .bubble { background: var(--err-bg); color: var(--err); }
.thinking { color: var(--muted); }
.thinking .step { line-height: 1.7; }
.thinking .step-done { font-size: .9em; opacity: .75; }
.thinking .step-now { color: var(--text, inherit); }
.thinking .dot { animation: blink 1.4s infinite both; }
.thinking .dot:nth-of-type(2) { animation-delay: .2s; }
.thinking .dot:nth-of-type(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* ---------- 미리보기 카드 ---------- */
.invoice {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; max-width: 500px; width: 100%; box-shadow: var(--shadow-doc);
}
.invoice-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 16px 0; font-weight: 800; color: var(--ink);
}
.card-title { display: inline-flex; align-items: center; gap: 8px; }
.card-title .ic { color: var(--ink); }
.status { font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 6px; white-space: nowrap; }
.status-pending, .status-cancelled { background: var(--cell); color: var(--muted); }
.status-issuing, .status-requested { background: var(--cell); color: var(--ink); }
.status-issued { background: var(--ok-bg); color: var(--ok); }
.status-failed { background: var(--err-bg); color: var(--err); }
.status-unknown { background: var(--warn-bg); color: var(--warn); }
/* 세금계산서 양식: 청색 테두리 안에 이름 칸과 괘선 */
.invoice-body { margin: 10px 16px 14px; border: 2px solid var(--ink); }
.rows { display: grid; grid-template-columns: auto 1fr; margin: 0; }
.rows dt, .rows dd { padding: 3px 12px; border-bottom: 1px solid var(--rule); }
.rows dt { background: var(--cell); color: var(--ink); font-weight: 600; border-right: 1px solid var(--rule); }
.rows dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.rows:last-child dt:last-of-type, .rows:last-child dd:last-of-type { border-bottom: 0; }
.items { margin: 0; padding: 0; list-style: none; }
.items li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 12px; border-bottom: 1px solid var(--rule); }
.items li span:last-child, .totals div span:last-child { white-space: nowrap; }
.items, .totals, .rows dd { font-variant-numeric: tabular-nums; }
.totals { padding-top: 5px; }
.totals div { display: flex; justify-content: space-between; gap: 12px; padding: 0 12px; }
.totals .grand {
  font-size: 20px; font-weight: 800; margin-top: 5px; padding: 5px 12px;
  background: var(--cell); color: var(--ink); border-top: 2px solid var(--ink);
}
.invoice-note { padding: 10px 16px; border-top: 1px solid var(--border); font-weight: 600; white-space: pre-wrap; }
.invoice-note.note-err { background: var(--err-bg); color: var(--err); }
.invoice-note.note-info { background: var(--cell); color: var(--ink); }
.invoice-note.note-ok { background: var(--ok-bg); color: var(--ok); }
.invoice-note.note-warn { background: var(--warn-bg); color: var(--warn); }
.invoice-note a { color: inherit; }
.invoice-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* ---------- 입력창 ---------- */
.composer { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer-row, .attach-preview { max-width: 720px; margin: 0 auto; }
.composer-row {
  display: flex; align-items: flex-end; gap: 4px; background: var(--surface);
  border: 1.5px solid var(--field); border-radius: 14px; padding: 5px; box-shadow: var(--shadow-doc);
}
.composer-row:focus-within { border-color: var(--ink); box-shadow: 0 0 0 4px var(--focus); }
.tool-btn { color: var(--ink); }
.tool-btn { flex-shrink: 0; }
.tool-btn.recording { background: var(--err-bg); color: var(--err); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
#input::placeholder, .login-card input::placeholder { color: #5a6480; opacity: 1; }
#input {
  flex: 1; min-width: 0; border: 0; resize: none; outline: none; background: transparent;
  padding: 10px 6px; max-height: 180px; font-size: 16px; line-height: 1.45;
}
.send-btn {
  flex-shrink: 0; height: 44px; padding: 0 16px; border: 0; border-radius: var(--radius);
  background: var(--ink); color: #fff; font-weight: 700; font-size: 16px; transition: background-color .15s ease;
}
.send-btn:hover:not(:disabled) { background: var(--ink-deep); }
.send-btn:disabled { background: var(--hover); color: var(--muted); cursor: default; }
.attach-preview { position: relative; margin-bottom: 8px; }
.attach-preview img { height: 84px; border-radius: var(--radius); border: 1px solid var(--border); }
.attach-remove {
  position: absolute; top: -8px; left: 72px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: var(--text); color: #fff; font-size: 13px; padding: 0;
  display: grid; place-items: center;
}

/* ---------- 확인 창 ---------- */
.modal { position: fixed; inset: 0; background: rgba(13,22,54,.55); display: grid; place-items: center; padding: 16px; z-index: 30; }
.modal-card { background: var(--surface); border-radius: 12px; padding: 22px 20px 18px; box-shadow: var(--shadow-lg); max-width: 380px; width: 100%; }
.modal-text { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 18px; margin: 0 0 18px; white-space: pre-wrap; }
.modal-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

/* ---------- 휴대폰 ---------- */
.only-mobile { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(13,22,54,.5); z-index: 15; }
@media (max-width: 820px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(82vw, 296px);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .topbar { padding: 8px 8px; }
  .msg-user .bubble { max-width: 92%; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .composer-row .icon-btn { min-width: 44px; }
  .send-btn { padding: 0 14px; }
  .empty { padding-top: 6vh; }
}

.rows .changed { color: var(--warn); font-size: .85em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 0s !important; }
}
