/* ===================================
   VARIABLES & RESET
   =================================== */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --border: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    --sidebar-width: 280px;
    --header-height: 60px;
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ===================================
   MOBILE HEADER
   =================================== */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
}

.hamburger {
    background: none;
    border: none;
    width: 30px;
    height: 30px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    cursor: pointer;
    padding: 0;
}

.hamburger span {
    display: block;
    width: 100%;
    height: 3px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: var(--transition);
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-display {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: none;
}

.btn-icon {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

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

/* ===================================
   SIDEBAR
   =================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    z-index: 1001;
    transition: var(--transition);
    overflow-y: auto;
    padding-bottom: 2rem;
}

.sidebar.active {
    left: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.close-sidebar {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0;
}

.nav-section {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.nav-section.chat-conversations-section {
    padding-top: 0;
}

.nav-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 1rem;
    margin-bottom: 0.5rem;
}

.nav-list {
    list-style: none;
}

.nav-link {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
}

.nav-link:hover,
.nav-link.active {
    background: var(--bg-tertiary);
    color: var(--primary);
}

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

.overlay.active {
    display: block;
}

/* ===================================
   MAIN CONTAINER
   =================================== */
.main-container {
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
    padding: 1rem;
}

/* ===================================
   VIEWS
   =================================== */
.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.view-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ===================================
   AUTH VIEW
   =================================== */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--header-height) - 2rem);
}

.auth-card {
    background: var(--bg-primary);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.auth-card h2 {
    text-align: center;
    margin-bottom: 0.5rem;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.875rem;
}

.auth-form h3 {
    margin-bottom: 1.5rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 1rem;
}

.form-switch {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-switch a {
    color: var(--primary);
    text-decoration: none;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* ===================================
   BUTTONS
   =================================== */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

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

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

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

.btn-secondary:hover {
    background: #475569;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    width: auto;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-back {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
}

/* ===================================
   COMMENTARY VIEW
   =================================== */
.commentary-filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.commentary-filters input,
.commentary-filters select {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.commentary-list {
    display: grid;
    gap: 1rem;
}

.commentary-item {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

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

.commentary-reference {
    font-weight: 700;
    color: var(--primary);
}

.commentary-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.commentary-text {
    color: var(--text-secondary);
    line-height: 1.6;
}

.commentary-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.commentary-actions button {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--border);
    background: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* ===================================
   MODAL
   =================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.25rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

.modal form {
    padding: 1.5rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.form-actions .btn {
    flex: 1;
}

/* ===================================
   SEARCHABLE DROPDOWN STYLES
   =================================== */
.searchable-dropdown {
    position: relative;
    z-index: 1;
    width: 100%;
}

.form-row .searchable-dropdown {
    position: relative;
    width: 100%;
}

.dropdown-input {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.dropdown-input:focus {
    outline: none;
    border-color: var(--primary);
}

.dropdown-input:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

.dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    display: none;
}

.dropdown-list.active {
    display: block !important;
}

.dropdown-item {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s ease;
}

.dropdown-item:last-child {
    border-bottom: none;
}

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

.dropdown-no-results {
    padding: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
}

/* ===================================
   THEOLOGICAL DNA VIEW
   =================================== */
.dna-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.dna-sections {
    display: grid;
    gap: 1.5rem;
}

.dna-section {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.dna-section h3 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary);
}

.principle-item {
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.principle-text {
    font-weight: 500;
    margin-bottom: 0.5rem;
}

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

/* ===================================
   AI CHAT VIEW - MOBILE OPTIMIZED
   =================================== */
.chat-layout {
    display: block;
    height: calc(100vh - var(--header-height) - 2rem);
}

.thread-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.thread-header h3 {
    font-size: 1rem;
}

.thread-list {
    overflow-y: auto;
    max-height: 300px;
}

.thread-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background-color 0.2s;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

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

.thread-item.active {
    background-color: #e3f2fd;
    border-left: 3px solid var(--primary);
}

.thread-content {
    flex: 1;
    min-width: 0;
    padding: 0.75rem 1rem;
    position: relative;
    z-index: 1;
    background: inherit;
    will-change: transform;
}

.thread-title {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thread-preview {
    font-size: 0.8rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Swipe delete button */
.thread-swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ef4444;
    z-index: 0;
}

.swipe-delete-btn {
    background: none;
    border: none;
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    padding: 0.5rem;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.swipe-delete-btn:active {
    background: rgba(0, 0, 0, 0.1);
}

.thread-title-input {
    width: 100%;
    padding: 0.25rem 0.5rem;
    border: 2px solid var(--primary);
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    background: white;
    outline: none;
}

.thread-title-input:focus {
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.chat-area {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.chat-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* MOBILE-FIRST: Full-width messages with name/avatar above */
.message {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
}

.message.user {
    align-items: flex-end;
}

.message.assistant {
    align-items: flex-start;
}

/* Message header with avatar and name */
.message-header {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.25rem;
    padding: 0 0.375rem;
}

.message.user .message-header {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.625rem;
    flex-shrink: 0;
}

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

.message-sender {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Message bubble - compact Apple Messages style */
.message-content {
    background: var(--bg-tertiary);
    padding: 0.5rem 0.75rem;
    border-radius: 18px;
    width: 100%;
    max-width: 85%;
    font-size: 0.9375rem;
    line-height: 1.4;
}

.message.user .message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    border-bottom-left-radius: 4px;
}

.message-text {
    word-wrap: break-word;
}

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
    margin-top: 0.75em;
    margin-bottom: 0.375em;
    font-weight: 600;
    line-height: 1.3;
}

.message-text h1 { font-size: 1.3em; }
.message-text h2 { font-size: 1.2em; }
.message-text h3 { font-size: 1.1em; }
.message-text h4 { font-size: 1em; }

.message-text p {
    margin-bottom: 0.5em;
}

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

.message-text ul,
.message-text ol {
    margin-left: 1.25em;
    margin-bottom: 0.5em;
}

.message-text li {
    margin-bottom: 0.125em;
}

.message-text code {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.125em 0.3em;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.875em;
}

.message.user .message-text code {
    background-color: rgba(255, 255, 255, 0.2);
}

.message-text pre {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.75em;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 0.5em;
}

.message.user .message-text pre {
    background-color: rgba(255, 255, 255, 0.15);
}

.message-text pre code {
    background-color: transparent;
    padding: 0;
}

.message-text blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 0.75em;
    margin-left: 0;
    margin-bottom: 0.5em;
    color: var(--text-muted);
    font-style: italic;
}

.message.user .message-text blockquote {
    border-left-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.9);
}

.message-text a {
    color: var(--primary);
    text-decoration: none;
}

.message.user .message-text a {
    color: rgba(255, 255, 255, 0.95);
    text-decoration: underline;
}

.message-text a:hover {
    text-decoration: underline;
}

.message-text strong {
    font-weight: 600;
}

.message-text em {
    font-style: italic;
}

.message-text hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.75em 0;
}

.message-text table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 0.5em;
    font-size: 0.9em;
}

.message-text th,
.message-text td {
    border: 1px solid #ddd;
    padding: 0.375em;
    text-align: left;
}

.message-text th {
    background-color: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

.message-time {
    font-size: 0.625rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    padding: 0 0.375rem;
}

.message.user .message-time {
    text-align: right;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 0.5rem;
}

.empty-state .small {
    font-size: 0.875rem;
}

.chat-input-container {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
    flex-shrink: 0;
}

#chatForm {
    display: flex;
    gap: 0.5rem;
}

#chatInput {
    flex: 1;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    resize: none;
    font-family: inherit;
    font-size: 0.9375rem;
    max-height: 100px;
    line-height: 1.4;
}

#chatForm button {
    width: auto;
    align-self: flex-end;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
}

/* ===================================
   CHAT ROOMS VIEW
   =================================== */
.room-filters {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}

.filter-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    white-space: nowrap;
}

.filter-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.room-list {
    display: grid;
    gap: 1rem;
}

.room-card {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
}

.room-card:hover {
    border-color: var(--primary);
}

.room-name {
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.room-topic {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.room-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.active-room {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - 2rem);
}

.room-chat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

.room-info h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.room-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.room-messages {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 1rem;
    margin-bottom: 1rem;
}

.room-input-container {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 1rem;
}

#roomMessageForm {
    display: flex;
    gap: 0.5rem;
}

#roomMessageInput {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

/* ===================================
   DIRECT MESSAGES VIEW
   =================================== */
.dm-layout {
    display: grid;
    gap: 1rem;
    height: calc(100vh - var(--header-height) - 2rem);
}

.dm-list {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow-y: auto;
}

.dm-conversation {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
}

.dm-conversation:hover,
.dm-conversation.active {
    background: var(--bg-tertiary);
}

.dm-user {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.dm-last-message {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.dm-chat {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 1rem;
}

/* ===================================
   USERS LIST
   =================================== */
.users-list {
    display: grid;
    gap: 1rem;
}

.user-card {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
}

.user-info {
    flex: 1;
}

.user-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.user-status {
    font-size: 0.875rem;
    color: var(--success);
}

.user-status.away {
    color: var(--warning);
}

.user-status.offline {
    color: var(--text-muted);
}

/* ===================================
   SETTINGS FORM
   =================================== */
.settings-form {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.settings-form h3 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.settings-form h3:first-child {
    margin-top: 0;
}

.mt-3 {
    margin-top: 1.5rem;
}

/* ===================================
   TOAST NOTIFICATIONS
   =================================== */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + 1rem);
    right: 1rem;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary);
    min-width: 300px;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ===================================
   LOADING SPINNER
   =================================== */
.loading-spinner {
    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: 4000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ===================================
   RESPONSIVE - TABLET
   =================================== */
@media (min-width: 768px) {
    .main-container {
        padding: 2rem;
    }
    
    .thread-list {
        max-height: calc(100vh - var(--header-height) - 120px);
    }
    
    .dm-layout {
        grid-template-columns: 300px 1fr;
    }
    
    .user-display {
        display: block;
    }
    
    /* Tablet: Keep full-width bubbles but reduce max-width slightly */
    .message-content {
        max-width: 75%;
    }
}

/* ===================================
   RESPONSIVE - DESKTOP
   =================================== */
@media (min-width: 1024px) {
    .mobile-header {
        left: var(--sidebar-width);
    }
    
    .sidebar {
        left: 0;
    }
    
    .hamburger,
    .close-sidebar,
    .overlay {
        display: none !important;
    }
    
    .main-container {
        margin-left: var(--sidebar-width);
    }
    
    .commentary-list {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .dna-sections {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Desktop: Reduce max-width further for better readability */
    .message-content {
        max-width: 65%;
    }
}

@media (min-width: 1280px) {
    .commentary-list {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ===================================
   MOBILE RESPONSIVENESS
   =================================== */
@media (max-width: 768px) {
    .edit-thread-btn,
    .delete-thread-btn {
        padding: 0.5rem;
        font-size: 1.1rem;
    }
    
    /* Mobile: Ensure full-width experience */
    .message-content {
        max-width: 85%;
    }
}

/* ============================================
   SMART BIBLE INPUT - Mobile-Friendly
   ============================================ */
.smart-bible-input-container {
    position: relative;
    width: 100%;
}

.smart-bible-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    transition: var(--transition);
    font-family: inherit;
    background-color: white;
}

.smart-bible-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.smart-bible-input.valid {
    border-color: var(--success);
    background-color: #f0fff4;
}

.smart-bible-input.invalid {
    border-color: var(--danger);
    background-color: #fff5f5;
}

.smart-bible-input:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.6;
}

.smart-bible-input::placeholder {
    color: #999;
    font-style: italic;
}

.smart-bible-suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: white;
    border: 2px solid var(--primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: none;
    -webkit-overflow-scrolling: touch;
}

.smart-bible-suggestions.active {
    display: block;
}

.bible-suggestion {
    padding: 14px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.15s ease;
    font-size: 15px;
    min-height: 48px;
    display: flex;
    align-items: center;
}

.bible-suggestion:last-child {
    border-bottom: none;
}

.bible-suggestion:hover,
.bible-suggestion:active {
    background-color: #e8f4fd;
}

.bible-suggestion.suggestion-active {
    background-color: #e8f4fd;
    font-weight: 600;
}

.bible-suggestion-error {
    padding: 14px 16px;
    color: var(--danger);
    font-size: 14px;
    background-color: #fff5f5;
    border-radius: 6px;
    margin: 4px;
    min-height: 48px;
    display: flex;
    align-items: center;
}

.smart-bible-helper {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
    font-style: italic;
}

.smart-bible-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

@media (max-width: 768px) {
    .smart-bible-input {
        font-size: 16px;
        padding: 14px 16px;
    }
    
    .bible-suggestion {
        padding: 16px;
        min-height: 52px;
    }
    
    .smart-bible-suggestions {
        max-height: 250px;
    }
}

/* Thread menu styles */
.thread-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.thread-content {
    flex: 1;
    cursor: pointer;
    padding: 0.75rem 1rem;
    min-width: 0;
}

.thread-actions {
    position: relative;
    padding-right: 0.5rem;
}

.thread-menu-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
}

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

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

.thread-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;  /* <-- Much higher */
    min-width: 150px;
    padding: 0.5rem 0;
    margin-top: 0.25rem;
}

.thread-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.625rem 1rem;
    border: none;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.2s;
}

.thread-menu button:hover {
    background: var(--bg-secondary);
}

.thread-menu button.danger {
    color: #ef4444;
}

.thread-menu button.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Mobile - show menu button always */
@media (max-width: 1024px) {
    .thread-menu-btn {
        opacity: 1;
    }
}
/* iMessage-style Direct Messages - High Specificity */
/* iMessage-style Direct Messages - High Specificity */
#messageInput.message-input {
    flex: 1 !important;
    padding: 0.75rem 1rem !important;
    border: 1px solid #d1d1d6 !important;
    border-radius: 20px !important;
    resize: none !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    max-height: 150px !important;
    min-height: 44px !important;
    height: auto !important;
    font-size: 16px !important;
    line-height: 1.4 !important;
    background: #f2f2f7 !important;
}
/* iMessage-style Direct Messages */
.message-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid #d1d1d6;
    border-radius: 20px;
    resize: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-height: 150px;
    min-height: 44px;
    font-size: 16px;
    line-height: 1.4;
    background: #f2f2f7;
}

.message-input:focus {
    outline: none;
    border-color: #007AFF;
    background: white;
}

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: 18px;
    word-wrap: break-word;
    max-width: 100%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    font-size: 16px;
    line-height: 1.4;
}

.message.other .message-bubble {
    background: #E5E5EA;
    color: #000;
    border-bottom-left-radius: 4px;
}

.message.own .message-bubble {
    background: #007AFF;
    color: white;
    border-bottom-right-radius: 4px;
}

.message {
    margin-bottom: 0.5rem;
}

.message-avatar {
    display: none;
}

.message-header {
    display: none;
}

.messages-container {
    background: white;
    padding: 1rem;
}

.message-form {
    background: #f8f8f8;
    padding: 0.75rem 1rem;
    border-top: 1px solid #e5e5ea;
}

.send-btn {
    background: #007AFF;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 0.5rem 1.5rem;
    font-weight: 600;
    min-width: 70px;
}

.send-btn:hover {
    background: #0051D5;
}

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

