/* ===== Design Tokens ===== */
:root {
  /* Colors - Dark Theme */
  --bg-primary: #0a0a0f;
  --bg-secondary: #111118;
  --bg-tertiary: #1a1a24;
  --bg-surface: #16161f;
  --bg-hover: #1f1f2e;
  --bg-active: #252538;

  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-tertiary: #6868820;
  --text-muted: #505068;

  --accent-primary: #6366f1;
  --accent-secondary: #a855f7;
  --accent-gradient: linear-gradient(135deg, #6366f1, #a855f7);
  --accent-glow: rgba(99, 102, 241, 0.15);

  --user-bg: #1a1a3a;
  --user-border: #3b3b8a;
  --char-bg: #1a2420;
  --char-border: #2a5a3a;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font-sans: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;

  --sidebar-width: 320px;
  --header-height: 64px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100dvh;
  width: 100vw;
}

#app {
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ===== Landing Page ===== */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

.landing-bg {
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(168, 85, 247, 0.1), transparent),
    radial-gradient(ellipse 40% 30% at 20% 60%, rgba(99, 102, 241, 0.08), transparent);
  animation: bgPulse 8s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  0% { opacity: 0.8; }
  100% { opacity: 1; }
}

.landing-content {
  position: relative;
  z-index: 1;
  text-align: center;
  max-width: 520px;
  padding: 2rem;
  animation: fadeInUp 0.6s ease-out;
}

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

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.logo-icon {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 0 12px rgba(99, 102, 241, 0.4));
}

.logo h1 {
  font-size: 2rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.landing-desc {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 2.5rem;
}

/* ===== Drop Zone ===== */
.drop-zone {
  position: relative;
  border: 2px dashed rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-xl);
  padding: 3px;
  transition: var(--transition-normal);
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

.drop-zone.dragover {
  transform: scale(1.02);
}

.drop-zone-inner {
  background: var(--bg-surface);
  border-radius: calc(var(--radius-xl) - 3px);
  padding: 3rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.drop-icon {
  width: 56px;
  height: 56px;
  color: var(--accent-primary);
  opacity: 0.7;
  margin-bottom: 8px;
}

.drop-text {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-primary);
}

.drop-subtext {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 28px;
  background: var(--accent-gradient);
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}

.file-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.privacy-note {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Viewer Layout ===== */
.viewer {
  display: flex;
  height: 100dvh;
  width: 100vw;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  min-height: var(--header-height);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.new-file-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.new-file-btn:hover {
  background: var(--bg-hover);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* Sidebar Search */
.sidebar-search {
  padding: 12px 16px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
  transition: var(--transition-fast);
}

.search-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* Sidebar Stats */
.sidebar-stats {
  padding: 8px 16px 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.stat-badge .stat-val {
  font-weight: 600;
  color: var(--accent-primary);
}

/* Chat List */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin: 2px 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
  border: 1px solid transparent;
}

.chat-item:hover {
  background: var(--bg-hover);
}

.chat-item.active {
  background: var(--bg-active);
  border-color: rgba(99, 102, 241, 0.2);
  box-shadow: inset 3px 0 0 var(--accent-primary);
}

.chat-item-icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  opacity: 0.9;
}

.chat-item-info {
  flex: 1;
  min-width: 0;
}

.chat-item-name {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-item-badge {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
}

/* ===== Sidebar Toggle (Mobile) ===== */
.sidebar-toggle {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  width: 42px;
  height: 42px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: var(--transition-fast);
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-normal);
}

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

/* ===== Chat Area ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-width: 0;
  background: var(--bg-primary);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  min-height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  gap: 16px;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-title {
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.chat-header-actions {
  display: flex;
  gap: 6px;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.header-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.header-btn.active {
  background: var(--accent-glow);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* ===== Messages ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.message {
  max-width: 820px;
  margin: 0 auto 20px;
  animation: msgFadeIn 0.3s ease-out;
}

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

.message-bubble {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  position: relative;
  line-height: 1.75;
  font-size: 0.92rem;
}

.message-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
}

.message-role {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.message-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* User Message */
.message.user .message-bubble {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-left: 3px solid #6366f1;
}

.message.user .message-role {
  color: #818cf8;
}

.message.user .role-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6366f1;
}

/* Char Message */
.message.char .message-bubble {
  background: var(--char-bg);
  border: 1px solid var(--char-border);
  border-left: 3px solid #34d399;
}

.message.char .message-role {
  color: #6ee7b7;
}

.message.char .role-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
}

/* Message Content */
.message-content {
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.message-content em,
.message-content .action-text {
  color: #c4b5fd;
  font-style: italic;
}

.message.char .message-content em,
.message.char .message-content .action-text {
  color: #86efac;
}

/* Think Block */
.think-block {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.65;
  position: relative;
  overflow: hidden;
}

.think-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-primary);
  margin-bottom: 6px;
}

.think-label svg {
  width: 14px;
  height: 14px;
}

/* Generation Info */
.message-gen-info {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.gen-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 0.68rem;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.gen-tag .gen-label {
  opacity: 0.7;
}

.gen-tag .gen-value {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===== Date Separator ===== */
.date-separator {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 820px;
  margin: 24px auto;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-lg);
  }

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

  .sidebar-toggle {
    display: flex;
  }

  .chat-header {
    padding-left: 64px;
  }

  .messages {
    padding: 16px;
  }

  .message-bubble {
    padding: 14px 16px;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: 100%;
    min-width: 100%;
  }

  .logo h1 {
    font-size: 1.5rem;
  }

  .drop-zone-inner {
    padding: 2rem 1.5rem;
  }
}

/* ===== Loading Spinner ===== */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

