:root {
  --bg: #0d0f14;
  --surface: #14171e;
  --surface-2: #1b1f28;
  --bubble-bot: #191d26;
  --text: #e7e9ee;
  --muted: #8b93a2;
  --accent: #4d7cfe;
  --accent-press: #3d6af0;
  --ok: #34d399;
  --danger: #f87171;
  --border: rgba(255, 255, 255, .07);
  --border-strong: rgba(255, 255, 255, .12);
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 9px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --bubble-bot: #ffffff;
    --text: #1a1d24;
    --muted: #6b7280;
    --border: rgba(0, 0, 0, .07);
    --border-strong: rgba(0, 0, 0, .12);
    --shadow: 0 8px 30px rgba(20, 30, 60, .10);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.screen { height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* 스크롤바 */
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

/* ── 로그인 ── */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 32px 24px; box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0 0 22px; text-align: center; font-size: 22px; font-weight: 700;
  letter-spacing: .06em;
}
#login-form { display: flex; flex-direction: column; gap: 10px; }

input {
  width: 100%; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text);
  border-radius: var(--r-md); padding: 13px 14px;
  font-size: 16px; outline: none;   /* 16px: iOS 자동 확대 방지 */
  transition: border-color .15s, background .15s;
}
input::placeholder { color: var(--muted); }
input:focus {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface-2));
}

button {
  border: none; border-radius: var(--r-md); padding: 13px;
  font-size: 15px; font-weight: 600; background: var(--accent); color: #fff;
  cursor: pointer; transition: background .15s, transform .06s, opacity .15s;
}
button:hover { background: var(--accent-press); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }
#login-btn { margin-top: 4px; }
.error { color: var(--danger); font-size: 12.5px; margin-top: 12px; text-align: center; }

/* ── 상단바 ── */
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar .title { font-weight: 700; font-size: 14px; letter-spacing: .04em; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent); }
.status-text { color: var(--muted); font-size: 11.5px; flex: 1; }
.ghost {
  background: transparent; color: var(--muted);
  width: 34px; height: 34px; padding: 0; border-radius: 9px;
  font-size: 16px; display: inline-flex; align-items: center; justify-content: center;
}
.ghost:hover { background: var(--surface-2); color: var(--text); }

/* ── 메시지 ── */
.messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 12px; display: flex; flex-direction: column; gap: 8px;
  scroll-behavior: smooth;
}
.row { display: flex; }
.row.me { justify-content: flex-end; }
.bubble {
  max-width: 82%; padding: 9px 12px; border-radius: 16px;
  font-size: 13.5px; line-height: 1.55; word-break: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}
.row.bot .bubble {
  background: var(--bubble-bot); border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.row.me .bubble {
  background: var(--accent); color: #fff; border-bottom-right-radius: 5px;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
}
.row.other .bubble {
  background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.row.sys { justify-content: center; margin: 2px 0; }
.row.sys .bubble {
  background: transparent; color: var(--muted); font-size: 11.5px;
  border: none; box-shadow: none; padding: 3px 8px; text-align: center;
}
.bubble .who {
  display: block; font-size: 11px; font-weight: 700;
  color: var(--accent); margin-bottom: 2px; opacity: .9;
}
.bubble strong { font-weight: 700; }
.bubble code {
  background: color-mix(in srgb, var(--text) 12%, transparent);
  padding: 1px 5px; border-radius: 5px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px;
}
.bubble pre {
  background: #0a0d13; color: #d7e0f2; border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 10px 12px; margin: 6px 0 0; overflow-x: auto;
}
.row.me .bubble pre { background: rgba(0, 0, 0, .28); border-color: rgba(255, 255, 255, .18); color: #eaf0ff; }
.bubble pre code { background: none; padding: 0; font-size: 11.5px; line-height: 1.5; }
.bubble img { max-width: 100%; border-radius: 10px; margin-top: 6px; display: block; cursor: zoom-in; }
.att-acts { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 7px; }
.img-dl, .att-share {
  display: inline-block; font-size: 12px; font-weight: 600;
  color: var(--accent); text-decoration: none; cursor: pointer;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 8px; padding: 5px 11px;
}
.att-share { font-family: inherit; }
.file-card {
  display: flex; align-items: center; gap: 10px; margin-top: 7px; text-decoration: none;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border: 1px solid var(--border); border-radius: 11px; padding: 9px 12px; color: inherit;
  transition: background .15s;
}
.file-card:hover { background: color-mix(in srgb, var(--text) 10%, transparent); }
.file-card .fi { font-size: 20px; }
.file-card .fn { font-size: 12.5px; font-weight: 600; }
.file-card .fs { font-size: 11px; color: var(--muted); }

/* ── 선택칩 ── */
.chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 4px 12px 0; }
.chips:empty { display: none; }
.chip {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  color: var(--accent); border-radius: 999px; padding: 7px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: background .15s;
}
.chip:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* ── 입력창 ── */
.composer {
  display: flex; gap: 8px; align-items: center; padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.composer input { flex: 1; border-radius: 999px; padding: 11px 16px; }
#send-btn {
  flex: none; width: 42px; height: 42px; padding: 0; border-radius: 50%;
  font-size: 18px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}

/* ── 라이트박스 ── */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, .94); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.lightbox img { max-width: 96vw; max-height: 84vh; object-fit: contain; border-radius: 10px; }
.lb-close {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255, 255, 255, .14); color: #fff; border: none; font-size: 18px;
}
.lb-close:hover { background: rgba(255, 255, 255, .24); }
.lb-acts { display: flex; gap: 10px; margin-top: 16px; }
.lb-dl {
  color: #fff; background: rgba(255, 255, 255, .14); cursor: pointer;
  padding: 9px 20px; border-radius: 11px; text-decoration: none; font-weight: 600; font-size: 13px;
  border: none; font-family: inherit;
}
