/*
  SOLE AI — Chat (mobile-optimized renewal)
  Palette: Navy / Cream / Gold accent
*/

:root {
  --navy: #0a0e1a;
  --navy-2: #141a2c;
  --cream: #f5f0e8;
  --cream-2: #fbf8f1;
  --gold: #c9a96e;
  --gold-2: #e0c285;
  --border: rgba(10, 14, 26, 0.1);
  --shadow: 0 4px 16px rgba(10, 14, 26, 0.08);
  --shadow-lg: 0 8px 32px rgba(10, 14, 26, 0.18);
  --top-bar-height: 56px;
  --input-area-height: 80px;
  --sidebar-width: 280px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  color: var(--navy);
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

@supports (height: 100dvh) {
  body { height: 100dvh; }
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(10,14,26,0.16); border-radius: 2px; }

/* ========== TOP BAR ========== */
#top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--top-bar-height) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--navy);
  color: var(--cream);
  z-index: 200;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
#hamburger-btn {
  width: 40px;
  height: 40px;
  color: var(--cream);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
}
#hamburger-btn:active { background: rgba(255, 255, 255, 0.08); }
#logo {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.08em;
  color: var(--gold-2);
}
#inference-wrap { display: flex; align-items: center; }
#inference-select {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 28px 7px 12px;
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--cream);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 100px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 4l3 3 3-3' fill='none' stroke='%23f5f0e8' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
  outline: none;
}
#inference-select option { color: var(--navy); background: var(--cream); }

/* ========== SIDEBAR ========== */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  max-width: 86vw;
  background: var(--navy-2);
  color: var(--cream);
  z-index: 300;
  transform: translateX(-100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 16px) 0 calc(var(--safe-bottom) + 12px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  box-shadow: var(--shadow-lg);
}
#sidebar.open { transform: translateX(0); }

#new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 14px 14px;
  padding: 11px 14px;
  background: var(--gold);
  color: var(--navy);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  min-height: 44px;
}
#new-chat-btn:active { background: var(--gold-2); }

.sidebar-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(245, 240, 232, 0.4);
  padding: 4px 18px 8px;
}
#history-list {
  flex: 1;
  min-height: 80px;
  padding: 0 8px;
}
.history-empty {
  font-size: 13px;
  color: rgba(245, 240, 232, 0.4);
  text-align: center;
  padding: 24px 12px;
  line-height: 1.7;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--cream);
  font-size: 13px;
  text-align: left;
  min-height: 40px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item:active { background: rgba(255, 255, 255, 0.06); }
.history-item.active { background: rgba(201, 169, 110, 0.16); color: var(--gold-2); }

.sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 12px 14px;
  flex-shrink: 0;
}

#gdrive-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 14px;
  padding: 9px 14px;
  background: var(--cream);
  color: #3c4043;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  min-height: 40px;
  flex-shrink: 0;
}
#gdrive-btn:active { background: var(--cream-2); }
#gdrive-btn[data-connected="true"] {
  background: #e6f4ea;
  color: #1e8e3e;
  cursor: default;
}

#token-meter {
  margin: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  flex-shrink: 0;
}
.token-meter-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: rgba(245, 240, 232, 0.6);
  margin-bottom: 6px;
}
.token-plan {
  font-weight: 700;
  color: var(--gold-2);
  letter-spacing: 0.06em;
}
.token-meter-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}
.token-meter-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  transition: width var(--transition);
}
.token-meter-text {
  font-size: 11px;
  color: rgba(245, 240, 232, 0.5);
}

#user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 14px 12px;
  flex-shrink: 0;
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.user-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sidebar-actions {
  display: flex;
  gap: 4px;
  padding: 0 14px;
  flex-shrink: 0;
}
.sidebar-action {
  flex: 1;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  color: var(--cream);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sidebar-action:active { background: rgba(255, 255, 255, 0.08); }

#sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.5);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 250;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
#sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* ========== CHAT MAIN ========== */
#chat-main {
  position: fixed;
  top: calc(var(--top-bar-height) + var(--safe-top));
  bottom: var(--input-area-height);
  left: 0;
  right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

/* Welcome */
#welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 14px;
  color: var(--navy);
  text-align: center;
}
.welcome-mark {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--gold-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.welcome-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--navy);
}
.welcome-sub {
  font-size: 14px;
  color: rgba(10, 14, 26, 0.65);
  line-height: 1.8;
}

/* Messages */
#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 100%;
  align-items: flex-start;
}
.user-message { flex-direction: row-reverse; }
.ai-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--gold-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.75;
  max-width: 85%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow);
}
.user-message .bubble {
  background: var(--navy);
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
}
.ai-message .bubble {
  background: #ffffff;
  color: var(--navy);
  border-radius: 4px 16px 16px 16px;
}
.bubble p + p { margin-top: 8px; }
.bubble strong { color: var(--gold); font-weight: 700; }
.bubble ul, .bubble ol { padding-left: 1.4em; margin: 4px 0; }
.bubble li + li { margin-top: 4px; }

/* Artifact card */
.artifact-card {
  margin: 4px 0 0 42px;
  background: var(--cream-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  max-width: calc(85% - 12px);
  box-shadow: var(--shadow);
}
.artifact-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(10, 14, 26, 0.04);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  -webkit-user-select: none;
  user-select: none;
  color: var(--navy);
  min-height: 44px;
}
.artifact-card-toggle {
  margin-left: auto;
  transition: transform var(--transition);
  flex-shrink: 0;
}
.artifact-card.collapsed .artifact-card-toggle { transform: rotate(-90deg); }
.artifact-card-body {
  padding: 14px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow-y: auto;
  color: var(--navy);
  transition: max-height var(--transition), padding var(--transition);
}
.artifact-card.collapsed .artifact-card-body {
  max-height: 0;
  padding: 0 14px;
  overflow: hidden;
}

/* Typing indicator */
#typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.typing-dots {
  display: inline-flex;
  gap: 5px;
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 4px 16px 16px 16px;
  box-shadow: var(--shadow);
}
.typing-dots span {
  width: 6px;
  height: 6px;
  background: rgba(10, 14, 26, 0.3);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes typing-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

/* ========== INPUT AREA ========== */
#input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: var(--input-area-height);
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--cream);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  z-index: 100;
  transition: bottom 0.2s ease;
}

#attach-btn,
#send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#attach-btn { color: rgba(10, 14, 26, 0.5); background: transparent; }
#attach-btn:active { background: rgba(10, 14, 26, 0.05); }
#send-btn {
  background: var(--navy);
  color: var(--cream);
  z-index: 101;
  pointer-events: auto;
}
#send-btn:disabled {
  background: rgba(10, 14, 26, 0.15);
  color: rgba(10, 14, 26, 0.45);
  cursor: not-allowed;
}
#send-btn:not(:disabled):active { background: var(--navy-2); }

#chat-input {
  flex: 1;
  font: inherit;
  font-size: 16px; /* iOS zoom prevention */
  padding: 9px 14px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 22px;
  color: var(--navy);
  outline: none;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.5;
  -webkit-appearance: none;
  appearance: none;
}
#chat-input::placeholder { color: rgba(10, 14, 26, 0.4); }
#chat-input:focus { border-color: var(--gold); }

/* ========== DESKTOP ENHANCEMENTS ========== */
@media (min-width: 900px) {
  #chat-main { padding: 24px 32px; }
  #messages, #welcome-screen { max-width: 760px; margin: 0 auto; width: 100%; }
  #input-area { padding: 12px 24px calc(12px + var(--safe-bottom)); }
  #input-area #chat-input { max-width: 720px; max-height: 160px; }
  .bubble { max-width: 70%; }
  .artifact-card { max-width: calc(70% - 12px); }
}
