/* ========================================
   Seoul Mayor Chatbot — Design System
   ======================================== */

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-hover: #f3f5f7;
  --surface-active: #edf0f3;

  --ink: #1a1d23;
  --ink-secondary: #4a5060;
  --ink-muted: #8b92a0;
  --ink-faint: #b4bac6;

  --border: #e2e5ea;
  --border-light: #eef0f3;
  --border-focus: #5b8def;

  --primary: #2563eb;
  --primary-hover: #1d4fd8;
  --primary-soft: #eff4ff;
  --primary-muted: #93b4f6;
  --msg-user-bg: #1a1d23;
  --msg-user-text: #ffffff;

  --accent: #e85d3a;
  --accent-soft: #fef3f0;

  --success: #16a34a;
  --warning: #d97706;
  --error: #dc2626;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.14);

  --topbar-h: 56px;
  --sidebar-w: 300px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ========== Dark Mode ========== */

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d25;
  --surface-hover: #22252e;
  --surface-active: #2a2d37;

  --ink: #e4e6eb;
  --ink-secondary: #b0b5c0;
  --ink-muted: #7a8194;
  --ink-faint: #4e5568;

  --border: #2e3240;
  --border-light: #2e3240;
  --border-focus: #5b8def;

  --primary: #5b8def;
  --primary-hover: #4a7de0;
  --primary-soft: #1a2540;
  --primary-muted: #3a5a9e;
  --msg-user-bg: #2f6fed;
  --msg-user-text: #ffffff;
  --msg-assistant-bg: #242730;
  --msg-assistant-text: #e4e6eb;

  --accent: #e85d3a;
  --accent-soft: #2a1a15;

  --success: #22c55e;
  --warning: #eab308;
  --error: #ef4444;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.4);
}

/* ========== Reset ========== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: "Pretendard", "Noto Sans KR", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

input,
select,
textarea,
button {
  font: inherit;
  color: inherit;
}

/* ========== Utilities ========== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.label-optional {
  font-size: 0.75em;
  font-weight: 400;
  color: var(--ink-muted);
  margin-left: 4px;
}

/* ========== App Shell ========== */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ========== Topbar ========== */

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

.topbar__inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar__brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
}

.topbar__brand:hover {
  text-decoration: none;
  opacity: 0.85;
}

.topbar__title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.topbar__sub {
  font-size: 0.75rem;
  color: var(--ink-muted);
  line-height: 1.2;
  margin-top: 1px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ========== Buttons ========== */

.btn-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}

.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

/* Theme toggle icon visibility */
#themeToggle .icon-moon { display: none; }
#themeToggle .icon-sun  { display: block; }
[data-theme="dark"] #themeToggle .icon-moon { display: block; }
[data-theme="dark"] #themeToggle .icon-sun  { display: none; }

.btn-icon--sm {
  width: 28px;
  height: 28px;
}

.btn-icon--sm svg {
  width: 14px;
  height: 14px;
}

.btn-text {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s var(--ease);
}

.btn-text:hover {
  color: var(--error);
  background: rgba(220, 38, 38, 0.06);
}

.btn-text svg {
  width: 14px;
  height: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  border: 1px solid transparent;
}

.btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn--primary:hover {
  background: var(--primary-hover);
}

.btn--ghost {
  background: transparent;
  color: var(--ink-secondary);
  border-color: var(--border);
}

.btn--ghost:hover {
  background: var(--surface-hover);
}

/* ========== Main Layout ========== */

.main {
  flex: 1;
  display: flex;
  overflow: hidden;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ========== Sidebar ========== */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar__section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar__label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

/* ========== Candidate Cards ========== */

.candidate-cards {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.candidate-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  position: relative;
}

.candidate-card:hover {
  border-color: var(--primary-muted);
  background: var(--primary-soft);
}

.candidate-card--active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.candidate-card__avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--surface-hover);
  flex-shrink: 0;
}

.candidate-card__info {
  min-width: 0;
}

.candidate-card__name {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}

.candidate-card__party {
  font-size: 0.76rem;
  color: var(--ink-muted);
  margin-top: 1px;
}

.candidate-card__check {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--primary);
  display: none;
  place-items: center;
}

.candidate-card--active .candidate-card__check {
  display: grid;
}

.candidate-card__check svg {
  width: 12px;
  height: 12px;
  color: #fff;
}

/* ========== Profile Form ========== */

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-secondary);
  margin-bottom: 4px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  font-size: 0.85rem;
  transition: border-color 0.15s var(--ease);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.12);
}

.field input::placeholder {
  color: var(--ink-faint);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ========== Sidebar Disclaimer ========== */

.sidebar__disclaimer {
  margin-top: auto;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: var(--radius-md);
  font-size: 0.73rem;
  line-height: 1.5;
  color: var(--ink-secondary);
}

.sidebar__disclaimer svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--accent);
}

.sidebar__disclaimer strong {
  color: var(--accent);
}

/* ========== Chat Area ========== */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ========== Chat Header ========== */

.chat-header {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header__info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header__avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--surface-hover);
  transition: transform 0.3s var(--ease-bounce);
}

.chat-header__avatar--switching {
  animation: avatarPop 0.3s var(--ease-bounce);
}

.chat-header__name {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
}

.chat-header__party {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

/* ========== Messages ========== */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 5px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.msg {
  max-width: min(85%, 580px);
  padding: 11px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 0.92rem;
  animation: msgIn 0.25s var(--ease);
  word-break: keep-all;
  overflow-wrap: break-word;
}

.msg p {
  margin: 0;
  white-space: pre-wrap;
}

.msg--system {
  align-self: flex-start;
  background: var(--primary-soft);
  color: var(--ink-secondary);
  border-bottom-left-radius: var(--radius-sm);
  border: 1px solid rgba(37, 99, 235, 0.1);
}

.msg--assistant {
  align-self: flex-start;
  background: var(--msg-assistant-bg, var(--surface));
  color: var(--msg-assistant-text, var(--ink));
  border: 1px solid var(--border-light);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.msg--user {
  align-self: flex-end;
  background: var(--msg-user-bg);
  color: var(--msg-user-text);
  border-bottom-right-radius: var(--radius-sm);
}

/* ========== Typing Indicator ========== */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  padding: 10px 16px;
  background: var(--msg-assistant-bg, var(--surface));
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  animation: msgIn 0.25s var(--ease);
}

.typing-indicator--hidden {
  display: none;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--ink-faint);
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

/* ========== Composer ========== */

.composer {
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border-light);
  background: var(--surface);
  flex-shrink: 0;
}

.composer__inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px 6px 6px 14px;
  transition: border-color 0.2s var(--ease);
}

.composer__inner:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.1);
}

.composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  font-size: 0.92rem;
  line-height: 1.5;
  padding: 6px 0;
  outline: none;
}

.composer textarea::placeholder {
  color: var(--ink-faint);
}

.composer__send {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.15s var(--ease);
}

.composer__send:hover {
  background: var(--primary-hover);
  transform: translateX(1px);
}

.composer__send:disabled {
  background: var(--ink-faint);
  cursor: not-allowed;
  transform: none;
}

.composer__send svg {
  width: 18px;
  height: 18px;
}

.composer__hint {
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--ink-faint);
  text-align: right;
}

/* ========== Inline Citations (under each assistant message) ========== */

.msg-citations {
  margin-top: 8px;
}

.msg-citations__toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}

.msg-citations__toggle:hover {
  color: var(--primary);
  border-color: var(--primary-muted);
  background: var(--primary-soft);
}

.msg-citations__toggle svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  transition: transform 0.2s var(--ease);
}

.msg-citations__toggle--open svg {
  transform: rotate(180deg);
}

.msg-citations__list {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  animation: msgIn 0.2s var(--ease);
}

.msg-citations__list--visible {
  display: flex;
}

.cite {
  padding: 9px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg);
  transition: border-color 0.15s var(--ease);
}

.cite:hover {
  border-color: var(--primary-muted);
}

.cite__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cite__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cite__tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-size: 0.68rem;
  font-weight: 500;
  background: var(--primary-soft);
  color: var(--primary);
}

.cite__tag--date {
  background: var(--surface-hover);
  color: var(--ink-muted);
}

.cite__link {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--primary);
  font-weight: 500;
  white-space: nowrap;
}

.cite__excerpt {
  margin: 5px 0 0;
  font-size: 0.78rem;
  color: var(--ink-secondary);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ========== Footer Survey Link ========== */

.site-footer__survey {
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.15s var(--ease);
}

.site-footer__survey:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ========== Modal ========== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal--hidden {
  display: none;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(3px);
}

.modal__card {
  position: relative;
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-xl);
  animation: modalIn 0.25s var(--ease);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.modal__head h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal__desc {
  font-size: 0.84rem;
  color: var(--ink-muted);
  margin-bottom: 16px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ========== Survey Form ========== */

.survey-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.survey-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-secondary);
  margin-bottom: 4px;
}

.survey-field select,
.survey-field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  font-size: 0.85rem;
}

.survey-field select:focus,
.survey-field textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.12);
}

.survey-field textarea {
  resize: vertical;
  min-height: 72px;
}

/* ========== Mobile Sidebar Toggle ========== */

.mobile-sidebar-toggle {
  display: none;
  position: fixed;
  left: 12px;
  bottom: 80px;
  z-index: 30;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  place-items: center;
}

.mobile-sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

/* ========== Animations ========== */

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@keyframes avatarPop {
  0% {
    transform: scale(0.85);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ========== Site Footer ========== */

.site-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 6px 24px 10px;
  font-size: 0.7rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

.site-footer__disclaimer {
  margin: 0 0 2px;
}

.site-footer__disclaimer strong {
  color: var(--ink-secondary);
  font-weight: 600;
}

.site-footer__copy {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.65rem;
}

/* ========== Desktop Sidebar Toggle ========== */

@media (min-width: 681px) {
  .sidebar--collapsed {
    display: none;
  }
}

/* ========== Responsive — Tablet ========== */

@media (max-width: 900px) {
  :root {
    --sidebar-w: 260px;
  }
}

/* ========== Responsive — Mobile ========== */

@media (max-width: 680px) {
  body {
    font-size: 14px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    bottom: 0;
    width: 300px;
    z-index: 35;
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease);
    box-shadow: var(--shadow-lg);
  }

  .sidebar--open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    top: var(--topbar-h);
    z-index: 34;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s var(--ease);
  }

  .sidebar-overlay--visible {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-sidebar-toggle {
    display: grid;
  }

  .chat-header {
    padding: 10px 16px;
  }

  .messages {
    padding: 16px;
  }

  .composer {
    padding: 10px 16px 14px;
  }

  .msg {
    max-width: 92%;
  }

  .site-footer {
    display: none;
  }

  .topbar__sub {
    display: none;
  }

  .modal__card {
    padding: 18px;
  }

  .composer__hint {
    display: none;
  }

}
