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

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2333;
  --bg-chat-user: #1a3a5c;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --border-color: #30363d;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --code-bg: #0d1117;
  --success: #3fb950;
  --error: #f85149;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

/* ===== OVERLAY ===== */
.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
}

.overlay.open {
  display: block;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.sidebar-header {
  padding: 14px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.new-chat-btn {
  width: 100%;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.2s;
}

.new-chat-btn:hover {
  background: var(--accent-hover);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.chat-item {
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background 0.15s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

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

.chat-item.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.chat-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.chat-item .delete-btn {
  display: none;
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 18px;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}

.chat-item:hover .delete-btn {
  display: flex;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

/* ===== MAIN ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
}

.main-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.main-header .model-badge {
  background: var(--bg-tertiary);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--accent);
  border: 1px solid var(--border-color);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}

/* ===== CHAT AREA ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  scroll-behavior: smooth;
}

.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-secondary);
  padding: 20px;
}

.welcome-screen h2 {
  font-size: 24px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-screen p {
  font-size: 14px;
  margin-bottom: 24px;
  max-width: 500px;
}

.welcome-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 500px;
  width: 100%;
}

.welcome-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s;
  font-size: 13px;
  color: var(--text-secondary);
}

.welcome-card:hover {
  border-color: var(--accent);
}

.welcome-card .icon {
  font-size: 18px;
  margin-bottom: 6px;
}

/* ===== MESSAGE ===== */
.message {
  max-width: 850px;
  margin: 0 auto 20px;
  display: flex;
  gap: 12px;
}

.message .avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message.user .avatar {
  background: var(--bg-chat-user);
}

.message.assistant .avatar {
  background: var(--accent);
}

.message .content {
  flex: 1;
  line-height: 1.7;
  font-size: 14px;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message .content p {
  margin-bottom: 10px;
}

.message .content p:last-child {
  margin-bottom: 0;
}

/* Code blocks */
.message .content pre {
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0;
  margin: 10px 0;
  overflow: hidden;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  color: var(--text-muted);
}

.copy-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.2s;
}

.copy-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.message .content pre code {
  display: block;
  padding: 12px;
  overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
}

.message .content code {
  background: var(--bg-tertiary);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 12px;
}

.message .content pre code {
  background: none;
  padding: 0;
}

.message .content ul,
.message .content ol {
  padding-left: 20px;
  margin-bottom: 10px;
}

.message .content li {
  margin-bottom: 4px;
}

.message .content table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.message .content th,
.message .content td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

.message .content th {
  background: var(--bg-tertiary);
}

.message .content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin: 10px 0;
  color: var(--text-secondary);
}

.message .content img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

/* File attachment preview */
.file-preview {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.file-preview .remove-file {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 16px;
}

/* Typing indicator */
.typing-indicator span {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  margin-right: 4px;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

/* ===== INPUT AREA ===== */
.input-area {
  padding: 12px 16px 16px;
  background: var(--bg-primary);
  flex-shrink: 0;
}

.input-container {
  max-width: 850px;
  margin: 0 auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 10px;
  transition: border-color 0.2s;
}

.input-container:focus-within {
  border-color: var(--accent);
}

#attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 0;
}

#attachments:not(:empty) {
  margin-bottom: 8px;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 150px;
  min-height: 22px;
  line-height: 1.5;
}

#message-input::placeholder {
  color: var(--text-muted);
}

.input-actions {
  display: flex;
  gap: 2px;
  align-items: center;
}

.input-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  font-size: 18px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-actions button:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

#send-btn {
  background: var(--accent) !important;
  color: #fff !important;
  border-radius: 8px;
  width: 34px;
  height: 34px;
}

#send-btn:hover {
  background: var(--accent-hover) !important;
}

#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.input-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  max-width: 850px;
  margin-left: auto;
  margin-right: auto;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    z-index: 100;
    transition: left 0.3s ease;
    width: 260px;
  }

  .sidebar.open {
    left: 0;
  }

  .menu-toggle {
    display: block;
  }

  .chat-area {
    padding: 12px 10px;
  }

  .input-area {
    padding: 8px 10px 12px;
  }

  .welcome-cards {
    grid-template-columns: 1fr;
  }

  .welcome-screen h2 {
    font-size: 20px;
  }

  .message {
    gap: 8px;
  }

  .message .avatar {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .message .content {
    font-size: 13px;
  }

  .message .content pre code {
    font-size: 11px;
    padding: 10px;
  }
}

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

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

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== ACCESS CODE SCREEN ===== */
.lock-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.lock-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 32px;
  width: 90%;
  max-width: 360px;
  text-align: center;
}

.lock-box .lock-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.lock-box h2 {
  font-size: 20px;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.lock-box p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.lock-box input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 16px;
  text-align: center;
  outline: none;
  letter-spacing: 2px;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.lock-box input:focus {
  border-color: var(--accent);
}

.lock-box input::placeholder {
  color: var(--text-muted);
  letter-spacing: normal;
}

.lock-box button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.lock-box button:hover {
  background: var(--accent-hover);
}

.lock-box button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.lock-error {
  color: var(--error);
  font-size: 13px;
  margin-top: 10px;
  display: none;
}

.lock-error.show {
  display: block;
}

.app-container {
  display: none;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

.app-container.unlocked {
  display: flex;
}
