* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: Arial, "Noto Sans KR", sans-serif; background: #f8fafc; color: #111827; }
body { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
.app { display: flex; height: 100vh; width: 100%; position: relative; }
.sidebar { width: 300px; min-width: 300px; background: #111827; color: #f9fafb; display: flex; flex-direction: column; border-right: 1px solid #1f2937; }
.sidebar-mobile { position: fixed; top: 0; left: 0; width: 320px; max-width: 85vw; height: 100vh; z-index: 1000; transition: transform .25s ease; }
.sidebar-hidden { transform: translateX(-100%); }
.sidebar-open { transform: translateX(0); }
.sidebar-desktop { position: relative; transform: none !important; height: 100vh; z-index: auto; }
.sidebar-header { padding: 16px; border-bottom: 1px solid #1f2937; }
.brand { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.new-chat-btn { width: 100%; border: 1px solid #374151; background: #1f2937; color: #fff; padding: 12px 14px; border-radius: 12px; cursor: pointer; }
.new-chat-btn:hover { background: #374151; }
.chat-list { flex: 1; overflow-y: auto; padding: 12px; }
.chat-list-empty { color: #cbd5e1; font-size: 14px; line-height: 1.5; padding: 10px 6px; }
.chat-item-row { display: flex; align-items: stretch; gap: 6px; margin-bottom: 8px; }
.chat-item-row .chat-item { flex: 1; margin-bottom: 0; }
.chat-item { width: 100%; text-align: left; background: transparent; color: #f9fafb; border: 1px solid transparent; border-radius: 12px; padding: 12px; cursor: pointer; min-width: 0; }
.chat-item:hover { background: #1f2937; border-color: #374151; }
.chat-item.active { background: #2563eb; border-color: #2563eb; }
.chat-item-title, .chat-item-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-title { font-size: 14px; font-weight: 600; line-height: 1.4; margin-bottom: 4px; }
.chat-item-meta { font-size: 12px; opacity: .8; }
.chat-delete-btn { border: 1px solid #374151; background: #1f2937; color: #fca5a5; min-width: 40px; width: 40px; border-radius: 12px; cursor: pointer; font-size: 16px; flex-shrink: 0; }
.chat-delete-btn:hover { background: #7f1d1d; border-color: #7f1d1d; color: #fff; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid #1f2937; font-size: 14px; color: #d1d5db; }
.user-line { margin-bottom: 10px; }
.footer-link { display: block; margin-bottom: 8px; color: #93c5fd; }
.footer-link.logout { color: #fca5a5; }
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 900; display: none; }
.sidebar-overlay.show { display: block; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f8fafc; width: 100%; height: 100vh; }
.main-header { height: 64px; min-height: 64px; display: flex; align-items: center; padding: 0 16px; border-bottom: 1px solid #e5e7eb; background: #fff; }
.main-header-left { display: flex; align-items: center; gap: 12px; min-width: 0; width: 100%; }
.menu-toggle-btn { border: 1px solid #d1d5db; background: #fff; color: #111827; width: 42px; height: 42px; border-radius: 12px; cursor: pointer; flex-shrink: 0; font-size: 20px; display: none; }
.main-title { font-size: 18px; font-weight: 700; color: #111827; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.attachments-bar { display: none; padding: 10px 16px 0; gap: 8px; overflow-x: auto; flex-wrap: nowrap; }
.attachments-bar.has-items { display: flex; }
.attach-chip { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #e5e7eb; border-radius: 14px; padding: 8px 10px; min-width: 170px; max-width: 260px; flex: 0 0 auto; }
.attach-thumb-link { display: flex; }
.attach-thumb { width: 38px; height: 38px; object-fit: cover; border-radius: 10px; }
.attach-file-icon { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; background: #eef2ff; border-radius: 10px; }
.attach-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; color: #111827; }
.attach-del { border: none; background: #ef4444; color: #fff; cursor: pointer; font-size: 13px; font-weight: 700; width: 28px; height: 28px; min-width: 28px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.attach-del:hover { background: #dc2626; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.empty-state { margin: auto; text-align: center; color: #6b7280; padding: 20px; }
.empty-state-title { font-size: 24px; font-weight: 700; color: #111827; margin-bottom: 8px; }
.empty-state-desc { font-size: 15px; line-height: 1.6; }
.message { display: flex; width: 100%; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }
.bubble { max-width: min(85%,760px); padding: 13px 15px; border-radius: 18px; line-height: 1.65; word-break: break-word; white-space: pre-wrap; box-shadow: 0 1px 3px rgba(0,0,0,.08); font-size: 15px; }
.message.user .bubble { background: #2563eb; color: #fff; border-bottom-right-radius: 6px; }
.message.assistant .bubble { background: #fff; color: #111827; border: 1px solid #e5e7eb; border-bottom-left-radius: 6px; }
.image-bubble { padding: 10px; }
.chat-inline-image { max-width: 220px; max-height: 220px; display: block; border-radius: 10px; object-fit: cover; }
.image-caption { margin-top: 6px; font-size: 12px; opacity: .9; }
.typing-bubble { display: inline-flex; align-items: center; gap: 6px; min-width: 68px; }
.typing-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; animation: blink 1.2s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%,80%,100% { opacity:.3; transform:translateY(0);} 40% { opacity:1; transform:translateY(-2px);} }
.chat-input-wrap { border-top: 1px solid #e5e7eb; background: #fff; padding: 14px 18px 18px; position: sticky; bottom: 0; }
.chat-input-box { max-width: 980px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 18px; padding: 10px; }
.attach-btn { width: 42px; height: 42px; border: 1px solid #d1d5db; background: #fff; border-radius: 12px; cursor: pointer; flex-shrink: 0; font-size: 22px; line-height: 1; }
.attach-btn:hover { background: #f3f4f6; }
.hidden-file-input { display: none; }
.chat-input { flex: 1; min-height: 48px; max-height: 160px; resize: none; border: none; outline: none; background: transparent; padding: 8px 10px; color: #111827; line-height: 1.5; }
.send-btn { border: none; background: #2563eb; color: #fff; padding: 12px 16px; border-radius: 14px; cursor: pointer; white-space: nowrap; }
.send-btn:hover { background: #1d4ed8; }
.send-btn:disabled, .attach-btn:disabled { opacity: .65; cursor: not-allowed; }
.input-help { max-width: 980px; margin: 6px auto 0; color: #6b7280; font-size: 12px; }
.auth-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f8fafc;
  padding: 20px;
}

.admin-page {
  min-height: 100vh;
  display: block;
  background: #f8fafc;
  padding: 20px;
  overflow-y: auto;
}
.admin-wrap {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}
.auth-card, .admin-card { width: 100%; max-width: 460px; background: #fff; border: 1px solid #e5e7eb; border-radius: 20px; padding: 28px; box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.auth-title { font-size: 24px; font-weight: 700; margin-bottom: 10px; }
.auth-desc { color: #6b7280; font-size: 14px; margin-bottom: 18px; line-height: 1.6; }
.auth-input { width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; outline: none; }
.auth-input:focus { border-color: #2563eb; }
.auth-btn { width: 100%; border: none; background: #2563eb; color: #fff; padding: 12px 16px; border-radius: 12px; cursor: pointer; }
.auth-btn:hover { background: #1d4ed8; }
.auth-links { margin-top: 16px; font-size: 14px; color: #6b7280; }
.auth-links a { color: #2563eb; }
.error-box { color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.admin-wrap { width: 100%; max-width: 1100px; }
.admin-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-card { max-width: none; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 10px; border-bottom: 1px solid #e5e7eb; text-align: left; font-size: 14px; vertical-align: top; }
.mini-btn { display: inline-block; border: none; background: #2563eb; color: #fff; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.mini-btn.danger { background: #dc2626; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: rgba(17,24,39,.94); color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s ease; z-index: 9999; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 768px) { body { overflow: hidden; } .sidebar { width: 320px; min-width: 0; } .menu-toggle-btn { display: inline-flex; align-items: center; justify-content: center; } .main { height: 100dvh; } .main-header { height: 56px; min-height: 56px; padding: 0 12px; } .attachments-bar { padding: 8px 12px 0; } .chat-messages { padding: 12px; gap: 10px; } .bubble { max-width: 94%; font-size: 14px; padding: 11px 13px; } .chat-input-wrap { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); } .chat-input-box { border-radius: 16px; padding: 8px; gap: 8px; } .chat-input { min-height: 42px; padding: 8px; } .send-btn { padding: 10px 14px; border-radius: 12px; } }
.pending-uploads {
  display: none;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 10px 0;
  margin-bottom: 8px;
}

.pending-file {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 8px 10px;
  min-width: 180px;
  max-width: 260px;
  flex: 0 0 auto;
}

.pending-thumb {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
}

.pending-file-icon {
  width: 40px;
  height: 40px;
  background: #eef2ff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pending-file-meta {
  flex: 1;
  min-width: 0;
}

.pending-file-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pending-file-size {
  font-size: 12px;
  color: #6b7280;
}

.pending-file-del {
  border: none;
  background: #ef4444;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}

.upload-progress {
  display: none;
  margin-bottom: 8px;
}

.upload-progress-text {
  font-size: 12px;
  color: #475569;
  margin-bottom: 6px;
}

.upload-progress-bar {
  width: 100%;
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.upload-progress-fill {
  width: 0%;
  height: 100%;
  background: #2563eb;
  transition: width 0.2s ease;
}

.drag-active {
  outline: 2px dashed #2563eb;
  outline-offset: -8px;
  background: rgba(37, 99, 235, 0.04);
}

@media (max-width: 768px) {
  .pending-uploads {
    padding-bottom: 8px;
  }

  .pending-file {
    min-width: 160px;
    max-width: 220px;
  }

  .chat-input-box {
    align-items: center;
  }

  .attach-btn {
    width: 40px;
    height: 40px;
  }
}
