/* Claude SQL Assistant Styles */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.login-form h1 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: #333;
}

.subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.login-btn {
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s;
}

.login-btn:hover {
    transform: translateY(-2px);
}

.error-message {
    background: #fee;
    color: #c33;
    padding: 0.75rem;
    border-radius: 5px;
    margin-bottom: 1rem;
    border: 1px solid #fcc;
}

.success-message {
    background: #efe;
    color: #363;
    padding: 0.75rem;
    border-radius: 5px;
    margin-bottom: 1rem;
    border: 1px solid #cfc;
}

.demo-credentials {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
    font-size: 0.85rem;
    color: #666;
}

.demo-credentials h3 {
    margin-bottom: 0.5rem;
    color: #333;
}

/* Main Layout */
.main-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.header {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    color: #333;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-email {
    color: #666;
    font-size: 0.9rem;
}

.logout-btn, .admin-btn {
    padding: 0.5rem 1rem;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 0.9rem;
    transition: background 0.3s;
}

.logout-btn:hover, .admin-btn:hover {
    background: #5a6fd8;
}

.admin-btn {
    background: #764ba2;
}

.admin-btn:hover {
    background: #6a4190;
}

/* Chat Interface */
.chat-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1rem;
}

.chat-sidebar {
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.08);
    padding: 0.75rem;
    height: 70vh;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.sidebar-title {
    font-weight: 600;
    color: #333;
}

.new-thread-btn {
    padding: 0.35rem 0.75rem;
    border: none;
    border-radius: 6px;
    background: #667eea;
    color: white;
    font-weight: 500;
    cursor: pointer;
}

/* (Cleaned) old thread list styles removed to avoid duplication */

.chat-container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    height: 70vh;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    border-bottom: 1px solid #eee;
}

.message {
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 10px;
    max-width: 80%;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.message.user {
    background: #667eea;
    color: white;
    margin-left: auto;
}

.message.assistant {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}

.message-content {
    margin-bottom: 0.5rem;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.message-time {
    font-size: 0.8rem;
    opacity: 0.7;
}

.chat-input-container {
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 0 0 10px 10px;
}

.chat-input-form {
    display: flex;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #ddd;
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
}

.chat-input:focus {
    border-color: #667eea;
}

.send-btn {
    padding: 0.75rem 1.5rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.3s;
}

.send-btn:hover:not(:disabled) {
    background: #5a6fd8;
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Sidebar toggle button */
.sidebar-toggle {
    display: none;
    padding: 0.4rem 0.75rem;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}
.sidebar-toggle:hover { background: #5a6fd8; }

/* Mobile overlay for sidebar */
.sidebar-overlay {
    display: none;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .main-container { padding: 0.5rem; }
    .header { padding: 0.75rem 1rem; gap: 0.5rem; flex-wrap: wrap; }
    .sidebar-toggle { display: inline-block; }
    .chat-layout { display: block; }
    .chat-sidebar { display: none !important; }
    body.sidebar-open .chat-sidebar { display: block !important; position: fixed; top: 56px; left: 0; right: 0; max-height: 70vh; height: auto; overflow-y: auto; z-index: 1001; margin: 0 0 1rem 0; }
    .sidebar-overlay { display: none; }
    body.sidebar-open .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 1000; }
    .chat-container { display: flex; height: 70vh; min-height: 60vh; }
    .chat-messages { padding: 0.75rem; overflow-y: auto; max-height: none; padding-bottom: 6rem; }
    .message { max-width: 100%; padding: 0.75rem; }
    .chat-input-container { position: sticky; bottom: 0; z-index: 10; background: #f8f9fa; }
    .chat-input-form { flex-wrap: wrap; }
    .chat-input { flex: 1 1 100%; }
    .pin-input { flex: 1 1 100%; }
    .send-btn { width: 100%; }
    /* Removed duplicate mobile thread layout rules */
}

/* Explicit desktop rule to hide mobile Chats toggle */
@media (min-width: 769px) {
    .sidebar-toggle { display: none !important; }
}

/* PIN Modal */
.pin-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.pin-modal-content {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    width: 90%;
    max-width: 400px;
}

.pin-modal h3 {
    margin-bottom: 1rem;
    color: #333;
}

.pin-input {
    width: 130px;
    padding: 0.75rem;
    border: 2px solid #ddd;
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
}

.pin-input:focus {
    border-color: #667eea;
}

.pin-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.pin-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
}

.pin-btn.primary {
    background: #667eea;
    color: white;
}

.pin-btn.secondary {
    background: #6c757d;
    color: white;
}

/* Admin Panel */
.admin-section {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
}

.admin-section h2 {
    margin-bottom: 1rem;
    color: #333;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.5rem;
}

.admin-form {
    display: grid;
    gap: 1rem;
    max-width: 500px;
}

.admin-form input, .admin-form select {
    padding: 0.75rem;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
}

.admin-btn {
    padding: 0.75rem 1.5rem;
    background: #764ba2;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.3s;
}

.admin-btn:hover {
    background: #6a4190;
}

/* Admin UI improvements */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.btn-primary { background-color: #6366f1; color: #fff; }
.btn-primary:hover { background-color: #4f46e5; }

.btn-secondary { background-color: #6c757d; color: #fff; }
.btn-secondary:hover { background-color: #5c636a; }

.btn-danger { background-color: #dc3545; color: #fff; }
.btn-danger:hover { background-color: #c82333; }

.btn-small { padding: 0.35rem 0.75rem; font-size: 0.875rem; }

.admin-section {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.admin-section h2 {
  font-size: 1.125rem;
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #eef2f7;
  color: #111827;
}

.admin-form {
  display: grid;
  gap: 1rem;
  max-width: 600px;
}

.admin-form label {
  font-weight: 600;
}

.admin-form input,
.admin-form select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.admin-form input:focus,
.admin-form select:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}

.admin-section table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
}

.admin-section thead th {
  background-color: #f8fafc;
  color: #111827;
  font-weight: 600;
}

.admin-section th,
.admin-section td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #eef2f7;
}

.admin-section tbody tr:hover {
  background-color: #f9fafb;
}

.role-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background-color: #eef2ff;
  color: #4338ca;
}

.text-muted { color: #6b7280; }

/* Data table styles for assistant results */
.table-wrap {
  margin-top: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: auto;
  max-height: 50vh;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.data-table th,
.data-table td {
  border: 1px solid #e5e7eb;
  padding: 8px 10px;
  text-align: left;
}
.data-table th {
  background: #f8f9fa;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table tbody tr:nth-child(odd) {
  background: #ffffff;
}
.data-table tbody tr:nth-child(even) {
  background: #fafafa;
}
.data-table tr:hover {
    background: #f8f9fa;
}

.delete-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8rem;
}

.delete-btn:hover {
    background: #c82333;
}

/* Export Links */
.export-link {
    display: inline-block;
    background: #28a745;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    text-decoration: none;
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

.export-link:hover {
    background: #218838;
    color: white;
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-container {
        padding: 0.5rem;
    }
    
    .header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    
    .chat-container {
        height: 60vh;
    }
    
    .message {
        max-width: 95%;
    }
    
    .admin-form {
        max-width: 100%;
    }
}

/* Chat Layout with Sidebar */
.chat-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1rem;
    align-items: stretch;
}

.chat-sidebar {
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    height: 70vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #eee;
}

.sidebar-title {
    font-weight: 600;
    color: #333;
}

.new-thread-btn {
    padding: 0.4rem 0.75rem;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.new-thread-btn:hover {
    background: #5a6fd8;
}

.threads-list {
    flex: 1;
    overflow-y: auto;
}

.empty-threads {
    padding: 1rem;
    color: #666;
    font-size: 0.9rem;
}

.thread-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    position: relative;
}

.thread-item:hover {
    background: #f8f9fa;
}

/* (Cleaned) duplicate thread item text styles removed */

.delete-thread-btn {
    position: absolute;
    right: 8px;
    top: 8px;
    background: transparent;
    border: none;
    color: #999;
    cursor: pointer;
    display: none;
    font-size: 16px;
    line-height: 1;
}

.thread-item:hover .delete-thread-btn {
    display: inline;
}

.delete-thread-btn:hover {
    color: #c33;
}

/* (Cleaned) duplicate thread item text styles removed */

/* Rename button in thread list */
.rename-thread-btn {
    position: absolute;
    top: 8px;
    right: 40px;
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.thread-item:hover .rename-thread-btn {
    opacity: 1;
}

.rename-thread-btn:hover {
    color: #111;
}

.thread-item.active .rename-thread-btn {
    opacity: 1;
}

.thread-item.active {
    background: #eef0ff;
    border-left: 4px solid #667eea;
}

.thread-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.25rem;
    font-size: 14px;
    padding-right: 64px; /* avoid overlap with rename/delete buttons */
    white-space: normal;
    word-break: normal;
    overflow-wrap: anywhere;
    grid-column: 1 / -1; /* span full width of grid */
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* show up to 2 lines */
    -webkit-box-orient: vertical;
}

/* Inline rename input */
.thread-rename-input {
    position: absolute;
    left: 12px;
    right: 64px;
    top: 6px;
    height: 28px;
    padding: 4px 8px;
    font-size: 14px;
    border: 1px solid #c9d1d9;
    border-radius: 6px;
    outline: none;
    background: #fff;
    color: #111;
}

.thread-rename-input:focus {
    border-color: #4a90e2;
    box-shadow: 0 0 0 2px rgba(74,144,226,0.2);
}

.thread-preview {
    font-size: 0.9rem;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-time {
    font-size: 0.8rem;
    color: #999;
    margin-top: 0.25rem;
    white-space: nowrap;
}

/* Responsive (consolidated with mobile block above; do not force-hide sidebar)
   The sidebar visibility is controlled via body.sidebar-open in the earlier mobile rules. */
@media (max-width: 768px) {
    .chat-layout { grid-template-columns: 1fr; }
}