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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --user-message-bg: #eff6ff;
    --assistant-message-bg: #ffffff;
    --sidebar-width: 280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    color: var(--text-primary);
    background: var(--bg-secondary);
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

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

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

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    padding: 12px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

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

.conversation-item.active {
    background: var(--bg-tertiary);
}

.conversation-item h4 {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-item p {
    font-size: 12px;
    color: var(--text-secondary);
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding: 16px;
}

.api-key-section label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.api-key-section input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 8px;
}

.save-btn {
    width: 100%;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.save-btn:hover {
    background: var(--border-color);
}

/* Main Content Styles */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    overflow: hidden;
}

.chat-header {
    padding: 16px 24px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.action-btn {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--border-color);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.welcome-message {
    max-width: 700px;
    margin: 80px auto;
    text-align: center;
}

.welcome-message h2 {
    font-size: 28px;
    margin-bottom: 16px;
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 32px;
}

.example-questions {
    text-align: left;
    background: var(--bg-primary);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.example-questions p {
    margin-bottom: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.example-questions ul {
    list-style: none;
}

.example-questions li {
    padding: 8px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.example-questions li:before {
    content: "→ ";
    margin-right: 8px;
}

.message {
    max-width: 800px;
    margin: 0 auto 24px auto;
    padding: 16px 20px;
    border-radius: 12px;
    line-height: 1.6;
}

.message.user {
    background: var(--user-message-bg);
    border: 1px solid #dbeafe;
}

.message.assistant {
    background: var(--assistant-message-bg);
    border: 1px solid var(--border-color);
}

.message-header {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}

.message-content {
    font-size: 15px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-content strong {
    font-weight: 700;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
    color: var(--text-primary);
}

.message-content code {
    background: var(--bg-tertiary);
    color: #dc2626;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.message-content a {
    color: var(--accent-color);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-color);
    transition: color 0.2s;
}

.message-content a:hover {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-hover);
}

.sources {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.sources h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.source-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.source-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

.source-link {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: #2563eb;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    transition: color 0.2s;
}

.source-link:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.source-link.no-url {
    color: var(--text-secondary);
    cursor: default;
}

.source-link.no-url:hover {
    text-decoration: none;
}

.source-icon {
    font-size: 14px;
}

.source-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.source-arrow {
    font-size: 12px;
    opacity: 0.7;
}

.source-details {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.source-type {
    font-weight: 500;
}

.source-relevance {
    background: #dcfce7;
    color: #166534;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.copy-link-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.copy-link-btn:hover {
    background: var(--bg-secondary);
    border-color: #3b82f6;
    color: #3b82f6;
}

.copy-link-btn.copied {
    background: #dcfce7;
    border-color: #16a34a;
    color: #166534;
}

.source-item {
    display: block;
    padding: 8px 12px;
    margin-bottom: 6px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 13px;
    transition: background 0.2s;
}

.source-item:hover {
    background: var(--border-color);
}

.source-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

.loading-message {
    display: flex;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
    padding: 16px 20px;
    color: var(--text-secondary);
}

.loading-dots {
    display: flex;
    gap: 4px;
    margin-left: 12px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Chat Input Styles */
.chat-input-container {
    padding: 16px 24px 24px 24px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

.chat-input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
}

#user-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.send-btn {
    width: 44px;
    height: 44px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.send-btn:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

.input-footer {
    max-width: 800px;
    margin: 8px auto 0 auto;
    text-align: center;
}

.status-message {
    font-size: 12px;
    color: var(--text-secondary);
}

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

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

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

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

/* ==================== AUTHENTICATION & USAGE TRACKING ==================== */

.usage-indicator {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.usage-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.tier-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}

.tier-anonymous {
    background: #fef3c7;
    color: #92400e;
}

.tier-community {
    background: #dbeafe;
    color: #1e40af;
}

.tier-engaged_citizen {
    background: #dcfce7;
    color: #166534;
}

.tier-pro {
    background: #fae8ff;
    color: #86198f;
}

.usage-count {
    font-size: 12px;
    color: var(--text-secondary);
}

.usage-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.usage-fill {
    height: 100%;
    background: var(--accent-color);
    transition: width 0.3s ease;
}

.upgrade-btn-inline, .register-btn-inline {
    width: 100%;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.upgrade-btn-inline {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.register-btn-inline {
    background: var(--accent-color);
    color: white;
}

.auth-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-primary, .btn-secondary {
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

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

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

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-size: 13px;
    padding: 8px;
}

.btn-link:hover {
    text-decoration: underline;
}

.user-menu-btn {
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

.empty-state {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-secondary);
    font-size: 13px;
}

.trial-info {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 8px;
    margin-top: 16px;
}

.trial-info p {
    margin: 8px 0;
    color: var(--text-primary);
}

/* ==================== MODALS ==================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    position: relative;
}

.modal-large {
    max-width: 700px;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--bg-tertiary);
}

.modal-header {
    padding: 32px 32px 16px;
    text-align: center;
}

.modal-header h2 {
    font-size: 24px;
    margin-bottom: 8px;
}

.modal-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.modal-body {
    padding: 16px 32px 32px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.form-error {
    color: #dc2626;
    font-size: 13px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: #fee2e2;
    border-radius: 6px;
    display: none;
}

.form-error:not(:empty) {
    display: block;
}

.btn-full {
    width: 100%;
}

.modal-footer-text {
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

.modal-footer-text a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

.modal-footer-text a:hover {
    text-decoration: underline;
}

/* ==================== PRICING TIERS ==================== */

.pricing-tiers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 24px 0;
}

.tier-card {
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    position: relative;
}

.tier-card.featured {
    border-color: var(--accent-color);
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.1);
}

.tier-card .badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-color);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 12px;
}

.tier-card h4 {
    font-size: 18px;
    margin-bottom: 8px;
}

.tier-card .price {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-color);
    margin-bottom: 16px;
}

.tier-card .price span {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
}

.tier-card ul {
    list-style: none;
    margin-bottom: 16px;
}

.tier-card ul li {
    padding: 6px 0;
    font-size: 14px;
    color: var(--text-primary);
}

.benefits-list {
    list-style: none;
    margin: 16px 0;
}

.benefits-list li {
    padding: 8px 0;
    font-size: 15px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.modal-actions button {
    flex: 1;
}

/* Reset Password Page */
.reset-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-secondary);
}

.reset-container {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    max-width: 450px;
    width: 100%;
}

.reset-container h2 {
    margin-bottom: 24px;
    font-size: 24px;
    color: var(--text-primary);
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.form-success {
    padding: 12px;
    background: #10b981;
    color: white;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
    display: none;
}

.form-success:not(:empty) {
    display: block;
}

/* ==================== MOBILE RESPONSIVE ==================== */
/* Breakpoints: Mobile ≤480px, Tablet 481-768px, Desktop >768px */

/* Mobile auth controls - hidden on desktop, shown on mobile */
.mobile-auth-controls {
  display: none; /* Hidden on desktop */
}

@media (max-width: 768px) {
  /* Show mobile auth controls */
  .mobile-auth-controls {
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .mobile-auth-btn {
    padding: 6px 12px;
    font-size: 13px;
    white-space: nowrap;
  }

  #mobile-user-menu-btn {
    min-width: 80px;
    font-size: 13px;
  }
  /* Hide sidebar completely on mobile */
  .sidebar {
    display: none;
  }

  .app-container {
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height */
  }

  /* Full-width chat with bottom nav padding */
  .main-content {
    flex: 1;
    width: 100%;
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
  }

  /* Compact header */
  .chat-header {
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .chat-header h1 {
    font-size: 16px;
  }

  .action-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  /* Optimized message list */
  .chat-messages {
    padding: 16px 12px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .message {
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 14px;
  }

  .welcome-message {
    margin: 40px auto;
    padding: 0 8px;
  }

  .welcome-message h2 {
    font-size: 22px;
  }

  /* Mobile input container */
  .chat-input-container {
    padding: 12px;
    position: sticky;
    bottom: 0;
  }

  .chat-input-wrapper {
    gap: 8px;
  }

  #user-input {
    font-size: 16px; /* Prevents iOS zoom */
    padding: 10px 12px;
    max-height: 120px;
  }

  .send-btn {
    width: 40px;
    height: 40px;
  }

  /* Mobile sources */
  .sources {
    margin-top: 12px;
    padding-top: 12px;
  }

  .source-card {
    padding: 10px;
    margin-bottom: 8px;
  }

  .source-link {
    font-size: 13px;
  }

  .copy-link-btn {
    width: 100%;
    margin-top: 8px;
  }

  /* Mobile modals - bottom sheet style */
  .modal {
    align-items: flex-end;
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal-large {
    max-width: 100%;
  }

  .modal-header {
    padding: 24px 20px 12px;
  }

  .modal-header h2 {
    font-size: 20px;
  }

  .modal-body {
    padding: 12px 20px 24px;
  }

  .modal-close {
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
  }

  /* Single column pricing */
  .pricing-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* Prevent iOS zoom on form inputs */
  .form-group input,
  .form-group textarea,
  .form-group select {
    font-size: 16px;
  }
}

/* Extra small mobile */
@media (max-width: 480px) {
  .modal-header h2 {
    font-size: 18px;
  }

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

/* ==================== BOTTOM NAVIGATION ==================== */

.bottom-nav {
  display: none; /* Hidden on desktop */
}

@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
  }

  .bottom-nav-items {
    display: flex;
    width: 100%;
    justify-content: space-around;
    align-items: center;
  }

  .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 60px;
    min-height: 44px; /* Touch target */
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
    border: none;
    background: transparent;
    font-family: inherit;
  }

  .nav-item.active {
    color: var(--accent-color);
  }

  .nav-item:active {
    background: var(--bg-tertiary);
  }

  .nav-item-icon {
    font-size: 22px;
    margin-bottom: 4px;
  }

  .nav-item-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }

  .nav-item.placeholder {
    display: none;
  }
}
