:root {
  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;
  --bg-surface: #f0f0f0;
  --bg-surface-alt: #e0e0e0;
  --bg-tab-bar: #222222;
  --bg-tab-active: #444444;
  --bg-fab: #6200ee;
  --text-primary: #000000;
  --text-secondary: #666666;
  --text-inverse: #ffffff;
  --border-color: #dddddd;
  --border-color-strong: #333333;
  --shadow: rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", "Noto Color Emoji", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background 0.2s ease, color 0.2s ease;
}

body.dark {
  --bg-primary: #111111;
  --bg-secondary: #1e1e1e;
  --bg-surface: #2d2d2d;
  --bg-surface-alt: #333333;
  --bg-tab-bar: #1a1a1a;
  --bg-tab-active: #333333;
  --bg-fab: #6200ee;
  --text-primary: #ffffff;
  --text-secondary: #aaaaaa;
  --text-inverse: #ffffff;
  --border-color: #444444;
  --border-color-strong: #333333;
  --shadow: rgba(0, 0, 0, 0.6);
}

.app-shell {
  height: 100%;
}

.spa-container {
  height: calc(100vh - 60px);
  height: calc(100dvh - 60px);
  overflow: hidden;
  padding: 0;
  padding-bottom: calc(0rem + env(safe-area-inset-bottom));
  background: var(--bg-primary);
}

.spa-container > .spa {
  display: none;
  height: 100%;
}

.spa-container > .spa.active {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

.spa {
  display: none;
  height: 100%;
}

.spa.active {
  display: flex !important;
  flex-direction: column;
  height: 100%;
}

.page-title {
  text-align: center;
  font-size: 2rem;
  font-weight: bold;
  margin: 0;
  padding-top: 1rem;
  padding-bottom: 1rem;
  line-height: 1.2;
  padding-left: 1rem;
  padding-right: 1rem;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 10;
  color: var(--text-primary);
}

.page-container {
  padding: 0 1rem 1rem 1rem;
  width: 100%;
  box-sizing: border-box;
  height: 100%;
  overflow-y: auto;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.home-container {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0 1rem 1rem 1rem;
  box-sizing: border-box;
  overflow-y: auto;
  background: var(--bg-primary);
}

.document-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0 0;
}

.document-item {
  padding: 0.75rem 0;
  font-weight: bold;
  font-size: 1.25rem;
  text-align: left;
  line-height: 1.2;
  color: var(--text-primary);
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-surface);
  border: none;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
  color: var(--text-primary);
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-fab);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.chat-info {
  display: flex;
  flex-direction: column;
}

.chat-name {
  font-weight: bold;
  font-size: 1rem;
}

.chat-preview {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.chat-window {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  height: calc(100dvh - 200px);
  background: var(--bg-primary);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.chat-back {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-primary);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message-bubble {
  max-width: 70%;
  padding: 0.75rem 1rem;
  border-radius: 18px;
  font-size: 0.95rem;
}

.message-left {
  align-self: flex-start;
  background: var(--bg-surface-alt);
  color: var(--text-primary);
}

.message-right {
  align-self: flex-end;
  background: var(--bg-fab);
  color: var(--text-inverse);
}

.fab {
  position: fixed;
  bottom: calc(70px + 1rem);
  right: 1rem;
  left: auto;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-fab);
  color: var(--text-inverse);
  border: none;
  font-size: 2rem;
  box-shadow: 0 3px 6px var(--shadow);
  cursor: pointer;
  z-index: 100;
}

.search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  margin-bottom: 1rem;
  background: var(--bg-surface-alt);
  color: var(--text-primary);
}

.search-history {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.search-history-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-surface-alt);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
}

.search-icon {
  font-size: 1rem;
}

.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.dialog {
  background: var(--bg-secondary);
  padding: 1.5rem;
  border-radius: 8px;
  width: 90%;
  max-width: 320px;
  box-shadow: 0 4px 12px var(--shadow);
  color: var(--text-primary);
}

.dialog h2 {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
}

.dialog input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem;
  font-size: 1rem;
  margin-bottom: 1rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.dialog-actions button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0;
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-fab);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.profile-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.profile-username {
  font-weight: bold;
  font-size: 1.25rem;
}

.profile-bio {
  margin: 0;
  color: var(--text-secondary);
}

.settings-title {
  font-size: 1.25rem;
  font-weight: bold;
  margin: 1rem 0 0.5rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.settings-item {
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--bg-surface-alt);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text-primary);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  margin-top: 0.75rem;
}

.setting-label {
  font-size: 1rem;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 32px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.2s;
  border-radius: 32px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 24px;
  width: 24px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: #6200ee;
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

body.dark .settings-title {
  border-bottom: 1px solid var(--border-color);
}

body.dark .settings-item {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  background: var(--bg-tab-bar);
  border-top: 1px solid var(--border-color-strong);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: #bbbbbb;
  font-size: 1.5rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.tab:active {
  background: var(--bg-surface-alt);
}

.tab.active {
  color: var(--text-inverse);
  background: var(--bg-tab-active);
}

.tab-middle {
  font-size: 1.5rem;
  font-weight: 700;
}

body.dark .tab {
  color: #aaaaaa;
}

body.dark .tab.active {
  color: var(--text-inverse);
  background: var(--bg-tab-active);
}
