/* 까치 웹 — 앱(Theme.kt)과 같은 청록. 카카오 노랑·갈색은 쓰지 않는다. */
:root {
  --magpie: #1F6F8B;
  --magpie-ink: #14202A;
  --bg: #ffffff;
  --surface: #f4f6f7;
  --surface-2: #e9eef1;
  --line: #e2e7ea;
  --text: #15191c;
  --muted: #66747c;
  --rail: #14202A;
  --rail-icon: #8fa3ae;
  --selected: #e6f1f5;
  --chat-bg: #D9E4EA;
  --my-bubble: #BFE4EF;
  --on-my-bubble: #0F2530;
  --other-bubble: #ffffff;
  --on-other-bubble: #15191C;
  --meta: #55646D;
  --unread: #1F6F8B;
  --badge: #E5533D;
  --link: #1F6F8B;
  --code-bg: #eef2f4;
  --shadow: 0 6px 24px rgba(0, 0, 0, .14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b2126;
    --surface: #20272c;
    --surface-2: #29323a;
    --line: #2d363d;
    --text: #e4e9ec;
    --muted: #93a2aa;
    --rail: #11171b;
    --rail-icon: #6f8590;
    --selected: #24343d;
    --chat-bg: #151B1F;
    --my-bubble: #28596B;
    --on-my-bubble: #EAF6FA;
    --other-bubble: #252D33;
    --on-other-bubble: #E4E9EC;
    --meta: #93A2AA;
    --unread: #7CC7DE;
    --link: #7CC7DE;
    --code-bg: #29323a;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--link); }
code { font-family: Consolas, "D2Coding", monospace; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 12px; margin: 4px 0 0; }
.error { color: var(--badge); min-height: 1.2em; margin: 0; }
svg { width: 22px; height: 22px; fill: currentColor; }

.primary, .danger, .sheet-actions button, .small-btn {
  border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600;
  background: var(--surface-2);
}
.primary, .sheet-actions .primary { background: var(--magpie); color: #fff; }
.primary:disabled { opacity: .45; cursor: default; }
.danger { background: transparent; color: var(--badge); border: 1px solid currentColor; }
.small-btn { padding: 6px 14px; flex: none; }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.text-btn { border: 0; background: transparent; color: var(--link); padding: 6px 10px; border-radius: 6px; font-weight: 600; text-decoration: none; cursor: pointer; }
.text-btn:hover { background: var(--surface-2); }
.text-btn.light { color: #fff; }
.text-btn.light:hover { background: rgba(255, 255, 255, .15); }

/* ── 로그인 ── */
.login { height: 100%; display: grid; place-items: center; background: var(--surface); padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--bg); border-radius: 16px; padding: 32px 28px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0; line-height: 1.6; }
#login-code {
  font: 600 22px/1 Consolas, monospace; letter-spacing: 4px; text-align: center; text-transform: uppercase;
  padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text);
}
#login-code:focus { outline: 2px solid var(--magpie); border-color: transparent; }
.login-card .primary { padding: 12px; font-size: 15px; }

/* ── 3단 레이아웃 ── */
/* 행을 창 높이에 묶는다 — 안 그러면 긴 대화가 격자 행을 밀어 올려 머리말이 화면 밖으로 나간다. */
.app { display: grid; grid-template-columns: 64px 300px 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; overflow: hidden; }
.app > * { min-height: 0; }
.rail { background: var(--rail); display: flex; flex-direction: column; align-items: center; padding: 18px 0 12px; gap: 6px; }
.rail-fill { flex: 1; }
.rail-btn { position: relative; border: 0; background: transparent; color: var(--rail-icon); width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; }
.rail-btn svg { width: 26px; height: 26px; }
.rail-btn:hover { color: #cfdde3; }
.rail-btn.active { color: #fff; }
.rail-badge {
  position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--badge); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px;
}

.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 22px 20px 12px; }
.pane-head h2 { margin: 0; font-size: 18px; }
.conn { font-size: 12px; color: var(--badge); }
.list { flex: 1; overflow-y: auto; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 10px 20px; cursor: pointer; }
.list-item:hover { background: var(--surface); }
.list-item.active { background: var(--selected); }
.list-item .body { flex: 1; min-width: 0; }
.list-item .top { display: flex; gap: 6px; align-items: baseline; }
.list-item .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .count { color: var(--muted); font-size: 12px; }
.list-item .mute-mark { width: 13px; height: 13px; color: var(--muted); flex: none; align-self: center; }
#mute .bell-off, #mute[aria-pressed="true"] .bell-on { display: none; }
#mute[aria-pressed="true"] .bell-off { display: block; }
.list-item .time { margin-left: auto; color: var(--muted); font-size: 11px; flex: none; }
.list-item .bottom { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.list-item .preview { flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { background: var(--badge); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; flex: none; }
.list-hint { padding: 20px; color: var(--muted); line-height: 1.6; }

.avatar {
  flex: none; display: grid; place-items: center; color: #fff; font-weight: 600;
  width: 44px; height: 44px; border-radius: 16px; font-size: 18px;
}
.avatar.sm { width: 38px; height: 38px; border-radius: 14px; font-size: 16px; }
.avatar svg { width: 60%; height: 60%; }

.main-pane { position: relative; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); }
.empty { flex: 1; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--meta); }
.empty img { width: 64px; height: 64px; border-radius: 18px; opacity: .55; }

/* ── 대화 ── */
.chat, .memo, .more { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; background: var(--chat-bg); border-bottom: 1px solid rgba(0, 0, 0, .06); }
.memo .chat-head, .more .chat-head { background: var(--bg); border-color: var(--line); }
.chat-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.chat-title strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 8px 16px 12px; outline: none; }
.loading-more { text-align: center; color: var(--meta); font-size: 12px; padding: 8px; }
.day { display: flex; justify-content: center; margin: 16px 0 8px; }
.day span { background: rgba(0, 0, 0, .12); color: #fff; font-size: 12px; padding: 4px 12px; border-radius: 12px; }
@media (prefers-color-scheme: dark) { .day span { background: rgba(255, 255, 255, .1); color: var(--meta); } }
.system { text-align: center; color: var(--meta); font-size: 12px; margin: 10px 0; }

.msg { display: flex; gap: 8px; margin-top: 2px; }
.msg.first { margin-top: 10px; }
.msg.mine { flex-direction: row-reverse; }
.msg .gutter { width: 38px; flex: none; }
.msg .col { display: flex; flex-direction: column; min-width: 0; max-width: min(70%, 560px); }
.msg.mine .col { align-items: flex-end; }
.msg .sender { font-size: 12px; color: var(--meta); margin: 2px 0 4px; }
.msg .line { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.msg.mine .line { flex-direction: row-reverse; }
.meta { display: flex; flex-direction: column; font-size: 11px; color: var(--meta); flex: none; line-height: 1.3; padding-bottom: 1px; }
.msg.mine .meta { align-items: flex-end; }
.meta .unread { color: var(--unread); font-weight: 700; }

.bubble {
  background: var(--other-bubble); color: var(--on-other-bubble); padding: 8px 11px; border-radius: 14px;
  line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; user-select: text;
}
.msg.first:not(.mine) .bubble.text { border-top-left-radius: 4px; }
.msg.mine .bubble { background: var(--my-bubble); color: var(--on-my-bubble); }
.msg.mine.first .bubble.text { border-top-right-radius: 4px; }
.bubble a { color: inherit; text-decoration: underline; }
.bubble.pending { opacity: .6; }
.bubble.failed { outline: 1px solid var(--badge); }

.stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg.mine .stack { align-items: flex-end; }

.link-card {
  display: block; width: 260px; max-width: 100%; border-radius: 12px; overflow: hidden; background: var(--other-bubble);
  color: var(--on-other-bubble); text-decoration: none; border: 1px solid rgba(0, 0, 0, .05);
}
.link-card img { display: block; width: 100%; aspect-ratio: 1.91; object-fit: cover; background: var(--surface-2); }
.link-card .lc-body { padding: 9px 11px; }
.link-card .lc-title { font-weight: 600; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-card .lc-desc { color: var(--meta); font-size: 12px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-card .lc-site { color: var(--meta); font-size: 11px; margin-top: 5px; }

.photo { display: block; border-radius: 12px; overflow: hidden; cursor: zoom-in; background: var(--surface-2); max-width: 100%; }
.photo img { display: block; max-width: 100%; height: auto; }

.file-card {
  display: flex; gap: 10px; align-items: center; width: 260px; max-width: 100%; padding: 12px; border-radius: 12px;
  background: var(--other-bubble); color: var(--on-other-bubble); text-decoration: none;
}
.msg.mine .file-card { background: var(--my-bubble); color: var(--on-my-bubble); }
.file-card .fi { width: 40px; height: 40px; border-radius: 10px; background: var(--magpie); color: #fff; display: grid; place-items: center; flex: none; font-size: 11px; font-weight: 700; }
.file-card .fn { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .fs { font-size: 12px; color: var(--meta); margin-top: 2px; }
.file-card .fb { flex: 1; min-width: 0; }
.progress { height: 4px; background: rgba(0, 0, 0, .1); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress div { height: 100%; background: var(--magpie); width: 0; transition: width .15s; }

.to-bottom {
  position: absolute; right: 20px; bottom: 84px; width: 40px; height: 40px; border-radius: 20px; border: 0;
  background: var(--bg); box-shadow: var(--shadow); color: var(--muted); display: grid; place-items: center;
}

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px; background: var(--bg); border-top: 1px solid var(--line); }
#input {
  flex: 1; resize: none; border: 0; outline: none; background: transparent; color: var(--text);
  font: inherit; font-size: 14px; line-height: 1.45; max-height: 160px; padding: 8px 4px;
}
.send { border: 0; border-radius: 8px; padding: 8px 14px; background: var(--magpie); color: #fff; font-weight: 600; }
.send:disabled { background: var(--surface-2); color: var(--muted); cursor: default; }

.drop {
  position: absolute; inset: 0; background: rgba(31, 111, 139, .18); display: grid; place-items: center;
  border: 3px dashed var(--magpie); z-index: 5; pointer-events: none;
}
.drop div { background: var(--magpie); color: #fff; padding: 14px 22px; border-radius: 12px; font-weight: 600; font-size: 15px; }

/* ── 메모 ── */
.memo-body { flex: 1; overflow-y: auto; background: var(--bg); padding: 16px 28px 32px; line-height: 1.6; font-size: 15px; user-select: text; }
.memo-body h1 { font-size: 20px; margin: 14px 0 4px; }
.memo-body h2 { font-size: 17px; margin: 12px 0 4px; }
.memo-body h3 { font-size: 15px; margin: 10px 0 2px; }
.memo-body p { margin: 0; }
.memo-body .gap { height: 8px; }
.memo-body hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.memo-body .li { display: flex; }
.memo-body .li::before { content: "•"; width: 16px; flex: none; }
.memo-body pre { background: var(--code-bg); border-radius: 8px; padding: 12px; overflow-x: auto; font: 13px/1.5 Consolas, monospace; margin: 4px 0; }
.memo-body figure { margin: 8px 0; max-width: 520px; }
.memo-body figure img { display: block; max-width: 100%; border-radius: 10px; cursor: zoom-in; background: var(--surface-2); }
.memo-body figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.memo-body .stamp { margin-top: 24px; font-size: 12px; color: var(--muted); }

/* ── 설정 ── */
.more-body { flex: 1; overflow-y: auto; background: var(--surface); padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--bg); border-radius: 12px; padding: 14px 16px; max-width: 560px; }
.card .row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

/* ── 확인 시트 ── */
.sheet { border: 0; border-radius: 14px; padding: 20px; width: min(420px, calc(100vw - 32px)); background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.sheet::backdrop { background: rgba(0, 0, 0, .35); }
.sheet h3 { margin: 0 0 12px; font-size: 16px; }
.confirm-files { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.confirm-files .cf { display: flex; gap: 10px; align-items: center; }
.confirm-files img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--surface-2); flex: none; }
.confirm-files .cf-icon { width: 64px; height: 64px; border-radius: 8px; background: var(--magpie); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.confirm-files .cf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ── 사진 보기 ── */
.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 20; display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; color: #fff; }
.viewer-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { display: flex; gap: 4px; }
.viewer img { margin: auto; max-width: calc(100% - 32px); max-height: calc(100% - 72px); object-fit: contain; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: rgba(20, 32, 42, .92); color: #fff;
  padding: 10px 18px; border-radius: 20px; z-index: 30; font-size: 13px; max-width: calc(100vw - 32px);
}

/* ── 좁은 창: 한 칸씩 ── */
@media (max-width: 760px) {
  .app { grid-template-columns: 56px 1fr; }
  .main-pane { display: none; }
  .app.detail .list-pane { display: none; }
  .app.detail .main-pane { display: flex; }
  .back { display: grid; }
  .pane-head { padding: 18px 16px 10px; }
  .list-item { padding: 10px 16px; }
  .messages { padding: 8px 10px 12px; }
  .memo-body { padding: 16px; }
  .msg .col { max-width: 78%; }
}
