/* =============================================================================
   OSCA - Global Styles
   ============================================================================= */

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

body {
    font-family: "Source Sans 3", "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f9fafb;
    color: #1f2937;
    height: 100vh;
    overflow: hidden;
}

hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 12px 0;
}

/* =============================================================================
   LAYOUT
   ============================================================================= */

.app-layout {
    display: flex;
    height: 100vh;
}

/* =============================================================================
   SIDEBAR
   ============================================================================= */

.sidebar {
    width: 280px;
    min-width: 280px;
    background: #f7f4f0;
    border-right: 1px solid #e8e3dd;
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow-y: auto;
}

.sidebar-brand {
    text-align: left;
}

.sidebar-logo {
    width: 120px;
    margin-bottom: 6px;
}

.sidebar-cover {
    width: 170px;
    border-radius: 8px;
}

.sidebar-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.sidebar-footer {
    margin-top: auto;
}

.tip {
    font-size: 0.75rem;
    color: #9ca3af;
    text-align: center;
    margin: 8px 0;
}

/* =============================================================================
   BUTTONS
   ============================================================================= */

.btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
    color: #374151;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
    margin-bottom: 6px;
}

.btn:hover {
    background: #f3f4f6;
}

.btn-full {
    text-align: center;
}

.btn-quickstart {
    font-weight: 700;
}

.btn-primary {
    background: #1faf9a;
    color: #ffffff;
    border-color: #1faf9a;
    font-weight: 600;
}

.btn-primary:hover {
    background: #17a08b;
}

.btn-footer {
    font-weight: 700;
}

.btn-logout {
    color: #9ca3af;
    border-color: #e5e7eb;
    font-size: 0.8rem;
}

.btn-logout:hover {
    color: #ef4444;
    border-color: #fca5a5;
    background: #fef2f2;
}

/* =============================================================================
   SEARCH INPUT
   ============================================================================= */

.search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.85rem;
    outline: none;
    margin-bottom: 8px;
}

.search-input:focus {
    border-color: #1faf9a;
    box-shadow: 0 0 0 2px rgba(31, 175, 154, 0.15);
}

/* =============================================================================
   CONVERSATION HISTORY
   ============================================================================= */

#conversation-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
}

.history-title {
    flex: 1;
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    background: none;
    color: #374151;
    font-size: 0.82rem;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-title:hover {
    background: #f3f4f6;
}

.history-item.active .history-title {
    background: #e8f5f2;
    color: #1f2937;
    font-weight: 600;
}

.history-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border: none;
    border-radius: 4px;
    background: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0.4;
    transition: opacity 0.15s;
}

.history-delete:hover {
    opacity: 1;
    color: #ef4444;
    background: #fef2f2;
}

.history-delete svg {
    display: block;
}

.no-history {
    font-size: 0.8rem;
    color: #9ca3af;
    text-align: center;
    padding: 12px 0;
}

/* =============================================================================
   MAIN CHAT AREA
   ============================================================================= */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.staging-banner {
    background: #fbbf24;
    color: #1f2937;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px;
    letter-spacing: 0.1em;
}

/* =============================================================================
   MESSAGES
   ============================================================================= */

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    padding-top: 12px;
}

.message + .message {
    border-top: 1px solid #f0f0f0;
}

.message-content {
    padding: 12px 8px;
    font-size: 0.95rem;
    line-height: 1.7;
    color: #1f2937;
}

.message.user .message-content {
    background: #f3f4f6;
    border-radius: 10px;
    padding: 14px 20px;
    color: #374151;
}

.message.assistant .message-content {
    background: transparent;
    border: none;
    padding-left: 14px;
    border-left: 3px solid #1faf9a;
}

/* ---------------------------------------------------------------------------
   Markdown typography inside messages (matches Streamlit output style)
   --------------------------------------------------------------------------- */

/* Headings */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    color: #111827;
    font-weight: 700;
    margin-top: 24px;
    margin-bottom: 12px;
    line-height: 1.3;
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child,
.message-content h4:first-child {
    margin-top: 0;
}

.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.3rem; }
.message-content h3 { font-size: 1.1rem; }
.message-content h4 { font-size: 1rem; }

/* Paragraphs */
.message-content p {
    margin-bottom: 12px;
}

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

/* Lists */
.message-content ul,
.message-content ol {
    margin: 10px 0;
    padding-left: 28px;
}

.message-content li {
    margin-bottom: 6px;
    line-height: 1.6;
}

.message-content li > ul,
.message-content li > ol {
    margin-top: 6px;
    margin-bottom: 2px;
}

.message-content ul { list-style-type: disc; }
.message-content ul ul { list-style-type: circle; }
.message-content ul ul ul { list-style-type: square; }

/* Inline code (green-tinted like Streamlit) */
.message-content code {
    background: #e8f5e9;
    color: #2e7d32;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.87rem;
    font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', 'Menlo', monospace;
}

/* Code blocks */
.message-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 16px 20px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 14px 0;
    font-size: 0.87rem;
    line-height: 1.5;
}

.message-content pre code {
    background: none;
    color: inherit;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

/* Bold / italic / emphasis */
.message-content strong {
    font-weight: 700;
    color: #111827;
}

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

/* Horizontal rules */
.message-content hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 20px 0;
}

/* Block quotes */
.message-content blockquote {
    border-left: 4px solid #1faf9a;
    margin: 14px 0;
    padding: 10px 16px;
    background: #f9fafb;
    color: #374151;
    border-radius: 0 8px 8px 0;
}

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

/* Links */
.message-content a {
    color: #1faf9a;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message-content a:hover {
    color: #17a08b;
}

/* Tables (in case the agent outputs them) */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 0.9rem;
}

.message-content th,
.message-content td {
    border: 1px solid #e5e7eb;
    padding: 8px 12px;
    text-align: left;
}

.message-content th {
    background: #f9fafb;
    font-weight: 600;
}

/* =============================================================================
   WELCOME CARD
   ============================================================================= */

.welcome-card {
    background: #f2efea !important;
    border-left: 4px solid #1faf9a !important;
    border-radius: 12px;
}

.welcome-headline {
    font-size: 1.3rem;
    font-weight: 500;
    line-height: 1.5;
    color: #1f2937;
}

.welcome-sub {
    margin-top: 12px;
    font-size: 0.88rem;
    color: #374151;
}

/* =============================================================================
   EPHEMERAL INLINE THINKING (renders inside #messages, removed on response)
   ============================================================================= */

.thinking-message {
    transition: opacity 0.25s ease;
    border-top: none !important;
}

.thinking-inline {
    padding: 8px 14px;
}

.thinking-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #9ca3af;
    letter-spacing: 0.02em;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.thinking-label::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #1faf9a;
    animation: thinkingPulse 1.2s ease-in-out infinite;
}

@keyframes thinkingPulse {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1); }
}

.thinking-steps {
    padding-left: 14px;
    border-left: 2px solid #e5e7eb;
}

.thinking-step {
    font-size: 0.78rem;
    color: #9ca3af;
    padding: 2px 0;
    line-height: 1.45;
    font-style: italic;
    transition: opacity 0.3s ease, color 0.3s ease;
}

.thinking-step-active {
    opacity: 0.7;
}

.thinking-step-faded {
    opacity: 0.4;
}

/* =============================================================================
   CHAT INPUT
   ============================================================================= */

.chat-input-area {
    padding: 12px 16px 20px;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

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

#chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
    resize: none;
    overflow-y: hidden;
    min-height: 44px;
    max-height: 160px;
    transition: border-color 0.15s;
}

#chat-input:focus {
    border-color: #1faf9a;
    box-shadow: 0 0 0 2px rgba(31, 175, 154, 0.15);
}

#chat-input:disabled {
    background: #f9fafb;
    color: #9ca3af;
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: #1faf9a;
    color: #ffffff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.send-btn:hover {
    background: #17a08b;
}

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

.stop-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: #ef4444;
    color: #ffffff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

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

/* =============================================================================
   FEEDBACK
   ============================================================================= */

.feedback-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
}

.feedback-label {
    font-size: 0.82rem;
    color: #9ca3af;
    margin-right: 2px;
}

.feedback-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.feedback-btn:hover {
    background: #f3f4f6;
    color: #4b5563;
}

.feedback-btn svg {
    display: block;
}

.feedback-thanks {
    font-size: 0.82rem;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* =============================================================================
   SMART CHIPS
   ============================================================================= */

.smart-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    animation: chipsIn 0.35s ease-out;
}

.smart-chip {
    padding: 6px 14px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    background: #f9fafb;
    color: #374151;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.smart-chip:hover {
    background: #e8f5f2;
    border-color: #1faf9a;
    color: #1f2937;
}

@keyframes chipsIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
   TEMPLATE CARDS (actionable drafts lifted from agent responses)
   ============================================================================= */

.template-card {
    position: relative;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    margin: 16px 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    animation: cardIn 0.3s ease-out;
}

.template-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #f0fdf9;
    border-bottom: 1px solid #e5e7eb;
}

.template-card-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #1faf9a;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 6px;
}

.template-card-label::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #1faf9a;
}

.template-card-actions {
    display: flex;
    gap: 4px;
}

.template-card-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #ffffff;
    color: #6b7280;
    font-size: 0.72rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.template-card-btn:hover {
    background: #f3f4f6;
    color: #374151;
    border-color: #9ca3af;
}

.template-card-btn svg {
    width: 13px;
    height: 13px;
}

.template-card-body {
    padding: 14px 16px;
    font-size: 0.9rem;
    line-height: 1.65;
    color: #1f2937;
}

.template-card-body p {
    margin-bottom: 8px;
}

.template-card-body p:last-child {
    margin-bottom: 0;
}

.template-card-subject {
    padding: 10px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    color: #1f2937;
    background: #fafafa;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.template-card-subject-label {
    font-size: 0.72rem;
    font-weight: 500;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.template-card-footer {
    display: flex;
    justify-content: flex-end;
    padding: 6px 16px 8px;
    border-top: 1px solid #f0f0f0;
}

.template-card-wordcount {
    font-size: 0.7rem;
    color: #9ca3af;
}

.template-card-wordcount-warn {
    color: #f59e0b;
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
   LOGIN PAGE
   ============================================================================= */

.login-page {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f9fafb 0%, #ecfdf5 100%);
}

.login-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #ffffff;
    padding: 48px 24px 24px;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    text-align: center;
    max-width: 500px;
    width: 100%;
}

#clerk-sign-in {
    width: 100%;
    display: flex;
    justify-content: center;
}

.login-logo {
    width: 160px;
    margin-bottom: 24px;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 8px;
}

.login-subtitle {
    font-size: 0.9rem;
    color: #6b7280;
    margin-bottom: 32px;
}

/* =============================================================================
   MESSAGE ANIMATIONS
   ============================================================================= */

.message {
    animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================================================
   STREAMING CURSOR
   ============================================================================= */

.streaming-cursor::after {
    content: "▌";
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* =============================================================================
   RESPONSIVE
   ============================================================================= */

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .chat-input-area,
    .messages {
        padding-left: 12px;
        padding-right: 12px;
    }
}
