/* ==================== Reset & Base ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Brand */
  --violet:       #7C3AED;
  --violet-light: #A78BFA;
  --violet-dark:  #5B21B6;
  --violet-glow:  rgba(124, 58, 237, 0.35);

  /* Surface */
  --bg-deep:    #0D0D14;
  --bg-dark:    #13131F;
  --bg-card:    rgba(255,255,255,0.06);
  --bg-chat:    #F5F4FF;
  --surface:    #FFFFFF;

  /* Text */
  --text-primary:   #1A1A2E;
  --text-secondary: #6B7280;
  --text-muted:     #9CA3AF;
  --text-white:     #FFFFFF;
  --text-light:     rgba(255,255,255,0.7);

  /* Border */
  --border:       rgba(255,255,255,0.1);
  --border-light: #E5E7EB;

  /* Status */
  --green:  #10B981;
  --red:    #F43F5E;

  /* Shadow */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.25);
  --shadow-violet: 0 8px 32px rgba(124,58,237,.25);

  /* Radius */
  --r-sm: 10px;
  --r:    18px;
  --r-lg: 28px;
  --r-xl: 36px;

  /* Gradient */
  --grad-violet: linear-gradient(135deg, #7C3AED 0%, #A855F7 100%);
  --grad-login:  linear-gradient(160deg, #0D0D14 0%, #1A0A2E 50%, #0D1A2E 100%);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ==================== Login Screen ==================== */
#login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--grad-login);
  position: relative;
  overflow: hidden;
}

/* Ambient glow orbs */
#login-screen::before,
#login-screen::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
}
#login-screen::before {
  width: 400px; height: 400px;
  background: rgba(124,58,237,.18);
  top: -80px; left: -80px;
}
#login-screen::after {
  width: 300px; height: 300px;
  background: rgba(168,85,247,.12);
  bottom: -60px; right: -60px;
}

.login-card {
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: var(--r-xl);
  padding: 52px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.12);
  position: relative;
  z-index: 1;
}

.login-logo { margin-bottom: 24px; display: flex; justify-content: center; }

.avatar-circle {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--grad-violet);
  color: var(--text-white);
  font-size: 17px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-violet);
  letter-spacing: -0.5px;
}

.avatar-circle.large {
  width: 88px; height: 88px;
  font-size: 30px;
  box-shadow: 0 0 0 8px rgba(124,58,237,.15), var(--shadow-violet);
}

.login-title {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-white);
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}
.login-subtitle {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 36px;
  font-weight: 400;
}

#login-form { display: flex; flex-direction: column; gap: 12px; }

#password-input {
  width: 100%;
  padding: 14px 18px;
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: var(--r-sm);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .2s, background .2s;
  background: rgba(255,255,255,0.06);
  color: var(--text-white);
}
#password-input::placeholder { color: rgba(255,255,255,0.3); }
#password-input:focus {
  border-color: var(--violet-light);
  background: rgba(255,255,255,0.09);
}

#login-btn {
  width: 100%;
  padding: 14px;
  background: var(--grad-violet);
  color: var(--text-white);
  border: none;
  border-radius: var(--r-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .2s, transform .15s, box-shadow .2s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: var(--shadow-violet);
  letter-spacing: 0.2px;
}
#login-btn:hover { opacity: .92; transform: translateY(-1px); box-shadow: 0 12px 40px rgba(124,58,237,.4); }
#login-btn:active { transform: translateY(0); }
#login-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.error-msg { color: var(--red); font-size: 13px; }

/* ==================== Chat Screen ==================== */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 768px;
  margin: 0 auto;
  background: var(--bg-chat);
  box-shadow: 0 0 60px rgba(0,0,0,.12);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(124,58,237,.10);
  position: sticky; top: 0; z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 12px; }

.header-info { display: flex; flex-direction: column; }
.header-name { font-size: 15px; font-weight: 700; line-height: 1.2; color: var(--text-primary); }
.header-status { font-size: 11px; color: var(--green); font-weight: 500; }

.icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 8px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: rgba(124,58,237,.08); color: var(--violet); }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Subtle scrollbar */
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(124,58,237,.2); border-radius: 4px; }

.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 82%;
  animation: msgIn .22s cubic-bezier(.2,.8,.4,1);
}

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

.msg.user { margin-left: auto; flex-direction: row-reverse; }
.msg.aoi  { margin-right: auto; }

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--grad-violet);
  color: var(--text-white);
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(124,58,237,.30);
  letter-spacing: -0.3px;
}

.msg-bubble {
  padding: 11px 16px;
  border-radius: 20px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}

.msg.user .msg-bubble {
  background: var(--grad-violet);
  color: var(--text-white);
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 16px rgba(124,58,237,.25);
}

.msg.aoi .msg-bubble {
  background: var(--surface);
  color: var(--text-primary);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(124,58,237,.08);
}

/* Markdown inside bubbles */
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble strong { font-weight: 700; }
.msg-bubble code {
  background: rgba(0,0,0,.07);
  padding: 2px 6px;
  border-radius: 5px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px;
}
.msg.user .msg-bubble code { background: rgba(255,255,255,.18); }
.msg-bubble pre {
  background: rgba(0,0,0,.07);
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0;
}
.msg-bubble th, .msg-bubble td {
  padding: 7px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(0,0,0,.08);
}
.msg-bubble th { font-weight: 600; background: rgba(0,0,0,.04); }
.msg.user .msg-bubble table th,
.msg.user .msg-bubble table td { border-color: rgba(255,255,255,.18); }
.msg.user .msg-bubble table th { background: rgba(255,255,255,.12); }

/* Typing indicator */
.typing-indicator {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 16px;
}
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--violet-light);
  animation: bounce .85s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .18s; }
.typing-dot:nth-child(3) { animation-delay: .36s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-7px); opacity: 1; }
}

/* Input Area */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid rgba(124,58,237,.08);
  background: rgba(255,255,255,0.90);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

#message-input {
  flex: 1;
  padding: 11px 16px;
  border: 1.5px solid var(--border-light);
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.55;
  transition: border-color .2s, box-shadow .2s;
  background: #FAFAFF;
  color: var(--text-primary);
}
#message-input::placeholder { color: var(--text-muted); }
#message-input:focus {
  border-color: var(--violet-light);
  box-shadow: 0 0 0 3px rgba(124,58,237,.10);
  background: var(--surface);
}

.send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--grad-violet);
  color: var(--text-white);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity .2s, transform .15s, box-shadow .2s;
  box-shadow: var(--shadow-violet);
}
.send-btn:hover:not(:disabled) { opacity: .92; transform: scale(1.07); box-shadow: 0 6px 20px rgba(124,58,237,.4); }
.send-btn:active:not(:disabled) { transform: scale(.97); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }

/* ==================== Drawer ==================== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
  z-index: 50;
}

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 260px;
  background: var(--surface);
  z-index: 51;
  box-shadow: -8px 0 40px rgba(0,0,0,.14);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  border-left: 1px solid rgba(124,58,237,.08);
}

.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-light);
  font-size: 15px; font-weight: 700;
  color: var(--text-primary);
}

.drawer-list { list-style: none; padding: 10px 0; }

.drawer-item {
  width: 100%;
  background: none; border: none;
  padding: 14px 20px;
  text-align: left;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-primary);
  transition: background .15s, color .15s;
  border-radius: 0;
}
.drawer-item:hover { background: rgba(124,58,237,.06); color: var(--violet); }
.drawer-item[data-action="logout"] { color: var(--red); }
.drawer-item[data-action="logout"]:hover { background: rgba(244,63,94,.06); color: var(--red); }

/* ==================== Utilities ==================== */
.hidden { display: none !important; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: var(--text-white);
  border-radius: 50%;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
