/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --user-message: #dbeafe;
    --assistant-message: #f1f5f9;
    --error-message: #fee2e2;
    --danger: #dc2626;
    --radius: 12px;
    --radius-sm: 8px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--background);
    -webkit-font-smoothing: antialiased;
}

/* App container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 800px;
    margin: 0 auto;
    background: var(--surface);
}

/* Header */
.header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 6px 0;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Mode toggle — second row */
.mode-toggle {
    order: 3;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--background);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.mode-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.mode-btn.active {
    background: var(--surface);
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

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

/* Chat container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.welcome-message p {
    margin-bottom: 8px;
}

.welcome-message .hint {
    font-size: 0.875rem;
}

/* Messages */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--radius);
    word-wrap: break-word;
}

.user-message {
    align-self: flex-end;
    background: var(--user-message);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.assistant-message {
    align-self: flex-start;
    background: var(--assistant-message);
    border-bottom-left-radius: 4px;
}

.error-message {
    align-self: center;
    background: var(--error-message);
    color: var(--danger);
    text-align: center;
}

.message-content {
    font-size: 0.9375rem;
}

/* Markdown rendering in assistant messages */
.assistant-message .message-content p {
    margin: 0 0 8px 0;
}

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

.assistant-message .message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

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

.assistant-message .message-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.875em;
}

.assistant-message .message-content strong {
    font-weight: 600;
}

/* IAP Reminder */
.iap-reminder {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: #fef3c7;
    border-top: 1px solid #fcd34d;
    font-size: 0.875rem;
    color: #92400e;
}

.iap-reminder.hidden {
    display: none;
}

.dismiss-btn {
    padding: 4px 12px;
    border: none;
    border-radius: 4px;
    background: #fcd34d;
    color: #92400e;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
}

.dismiss-btn:hover {
    background: #fbbf24;
}

/* Input area */
.input-area {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.prompt-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.prompt-select {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
}

.small-btn {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.2s;
}

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

/* File upload */
.file-row {
    margin-bottom: 10px;
}

.file-label {
    display: inline-block;
    cursor: pointer;
}

.file-label input[type="file"] {
    display: none;
}

.file-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: border-color 0.2s, color 0.2s;
}

.file-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.file-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.file-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--background);
    border-radius: 4px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.remove-file {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    line-height: 1;
}

.remove-file:hover {
    background: var(--border);
    color: var(--danger);
}

/* Message input row */
.message-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.message-row textarea {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    min-height: 44px;
    max-height: 150px;
}

.message-row textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

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

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

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

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

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

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-body label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.modal-body textarea,
.modal-body input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: inherit;
    margin-bottom: 16px;
}

.modal-body textarea:focus,
.modal-body input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-body h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.modal-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Buttons */
.primary-btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-color);
    color: white;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

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

.secondary-btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.9375rem;
    cursor: pointer;
    transition: background 0.2s;
}

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

/* Prompts list */
.prompts-list {
    max-height: 250px;
    overflow-y: auto;
}

.prompt-item {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.prompt-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.prompt-preview {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.delete-btn {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
}

.delete-btn:hover {
    background: var(--error-message);
    color: var(--danger);
}

/* Loading overlay */
.loading {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 200;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Utility classes */
.full-width {
    width: 100%;
}

.hidden {
    display: none !important;
}

/* Mobile responsiveness */
@media (max-width: 600px) {
    .header {
        padding: 10px 12px 6px;
    }

    .header h1 {
        font-size: 1rem;
    }

    .mode-btn {
        padding: 6px 8px;
        font-size: 0.8rem;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
    }

    .chat-container {
        padding: 12px;
    }

    .message {
        max-width: 90%;
        padding: 10px 14px;
    }

    .input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .prompt-row {
        flex-direction: column;
        gap: 6px;
    }

    .small-btn {
        align-self: flex-start;
    }

    .modal-content {
        max-height: 85vh;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .modal-actions button {
        width: 100%;
    }

    .iap-reminder {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
}

/* Dark mode support (optional, follows system preference) */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #0f172a;
        --surface: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border: #334155;
        --user-message: #1e3a5f;
        --assistant-message: #334155;
        --error-message: #7f1d1d;
    }

    .loading {
        background: rgba(15, 23, 42, 0.95);
    }

    .iap-reminder {
        background: #78350f;
        border-color: #b45309;
        color: #fef3c7;
    }

    .dismiss-btn {
        background: #b45309;
        color: #fef3c7;
    }

    .dismiss-btn:hover {
        background: #d97706;
    }
}

/* ============================================
   Shared Chat Styles
   Used on Meetings, Action Items, Projects pages
   ============================================ */

.chat-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
}

.chat-header {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.chat-header:hover {
    background: var(--background);
}

.chat-content {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.chat-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--background);
    color: var(--text-primary);
    font-size: 0.9375rem;
}

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

.chat-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.chat-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: chat-spin 1s linear infinite;
}

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

.chat-response {
    padding: 16px;
    background: var(--background);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    line-height: 1.6;
    font-size: 0.9375rem;
}

.chat-response p {
    margin: 0 0 12px 0;
}

.chat-response p:last-child {
    margin-bottom: 0;
}

.chat-response ul {
    margin: 0 0 12px 0;
    padding-left: 24px;
}

.chat-response li {
    margin-bottom: 8px;
}

.chat-response li:last-child {
    margin-bottom: 0;
}

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

.chat-sources-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.chat-source {
    display: inline-block;
    padding: 4px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    margin-right: 6px;
    margin-bottom: 6px;
    color: var(--text-primary);
    text-decoration: none;
}

.chat-source:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.chat-source-meeting {
    border-left: 3px solid #3b82f6;
}

.chat-source-action {
    border-left: 3px solid #f59e0b;
}

.chat-source-project {
    border-left: 3px solid #10b981;
}

.chat-examples {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-example {
    padding: 6px 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 16px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.chat-example:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.chat-error {
    color: var(--danger);
    padding: 12px;
    background: var(--error-message);
    border-radius: var(--radius-sm);
}


/* ============================================
   CRISP Dashboard Styles
   Concern badges, shared across overview & detail
   ============================================ */

.concern-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.concern-badge-high {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.concern-badge-moderate {
    background: #fff7ed;
    color: #ea580c;
    border: 1px solid #fed7aa;
}

.concern-badge-low {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

.concern-badge-none {
    background: var(--background);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

@media (prefers-color-scheme: dark) {
    .concern-badge-high {
        background: #450a0a;
        border-color: #7f1d1d;
    }
    .concern-badge-moderate {
        background: #431407;
        border-color: #7c2d12;
    }
    .concern-badge-low {
        background: #052e16;
        border-color: #14532d;
    }
    .concern-badge-none {
        background: var(--surface);
    }
}
