/* common.css — shared base styles across all Ray web pages */

:root {
    --bg-primary: #faf9f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0eeeb;
    --accent: #8b6f47;
    --accent-hover: #a6854f;
    --text-primary: #2c2c2c;
    --text-secondary: #7a7a7a;
    --text-muted: #999;
    --border: #e8e5e0;
    --card-bg: rgba(139, 111, 71, 0.03);
    --success-bg: rgba(102, 187, 106, 0.12);
    --success-text: #2e7d32;
    --danger: #c62828;
    --warning: #f0a500;
    /* Font scale factor: 1.0 = default reduced size (~12.5% smaller).
       Adjusted via Settings > Display > Font Size.
       All font-size values use rem so they scale with this root. */
    --font-scale: 1;
}

html {
    /* Base: 87.5% of browser default (14px instead of 16px).
       Combined with --font-scale for user-adjustable sizing.
       At --font-scale: 1.0  → 1rem = 14px (default, reduced)
       At --font-scale: 1.14 → 1rem ≈ 16px (original sizes)  */
    font-size: calc(87.5% * var(--font-scale, 1));
}

* { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
}

/* --- Login Screen --- */
.login-screen {
    position: fixed; inset: 0;
    background: var(--bg-primary);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    /* Must sit above every page-level overlay/modal:
       work.html:10000, index/plan toasts:9999, dashboard.search-overlay:4000,
       dashboard.login-overlay(dead):3000, mentions-popover:3000, conversation-rendering:2100. */
    z-index: 100000;
}
.login-screen.hidden { display: none; }
.login-logo {
    width: 120px; height: 120px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--bg-tertiary) 100%);
    border-radius: 24px;
    display: flex; align-items: center; justify-content: center;
    font-size: 3rem; font-weight: bold; color: white;
    margin-bottom: 24px;
}
.login-title { font-size: 2rem; font-weight: 600; margin-bottom: 8px; }
.login-subtitle { font-size: 1rem; color: var(--text-secondary); margin-bottom: 32px; }
.google-btn {
    display: flex; align-items: center; gap: 12px;
    background: white; color: #333; border: none;
    padding: 12px 24px; border-radius: 8px;
    font-size: 1rem; font-weight: 500; cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
.google-btn:hover { background: #f5f5f5; }
.google-btn:active { transform: scale(0.98); }
.google-btn svg { width: 20px; height: 20px; }
.login-error { color: var(--danger); margin-top: 16px; font-size: 0.875rem; }
.debug-login-btn { margin-top: 10px; background: var(--border) !important; display: none; }

/* --- Animations --- */
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- Nav Link (pill style) --- */
.nav-link {
    color: var(--text-secondary); text-decoration: none;
    font-size: 0.8125rem; padding: 6px 10px; border-radius: 6px;
    transition: all 0.15s;
}
.nav-link:hover { background: rgba(0,0,0,0.04); color: var(--text-primary); }
.nav-link.active { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }

/* --- Buttons --- */
.btn {
    padding: 8px 16px; border-radius: 8px; border: none;
    font-size: 0.8125rem; font-family: inherit; cursor: pointer;
    transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px;
}
/* Modifier selectors are doubled (.btn.btn-*) so they beat page-level
   .btn { background: ... } rules regardless of source order. */
.btn.btn-primary, .btn-primary { background: var(--accent); color: white; }
.btn.btn-primary:hover, .btn-primary:hover { opacity: 0.85; }
.btn.btn-secondary, .btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn.btn-secondary:hover, .btn-secondary:hover { background: rgba(0,0,0,0.04); }
.btn.btn-danger, .btn-danger { background: rgba(139,111,71,0.1); color: #b85c3a; }
.btn.btn-danger:hover, .btn-danger:hover { background: rgba(139,111,71,0.18); }
.btn.btn-danger-destructive, .btn-danger-destructive { background: #dc3545; border: 1px solid #dc3545; color: white; }
.btn.btn-danger-destructive:hover, .btn-danger-destructive:hover { background: #c82333; border-color: #bd2130; }
.btn.btn-danger-destructive:disabled, .btn-danger-destructive:disabled { background: #6c757d; border-color: #6c757d; opacity: 0.65; }
.btn-small { padding: 5px 12px; font-size: 0.75rem; }
.btn-icon {
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; padding: 6px; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.btn-icon:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }
.btn-icon svg { width: 16px; height: 16px; }

/* --- Loading & Empty States --- */
.loading {
    text-align: center; padding: 60px;
    color: var(--text-secondary); font-size: 1rem;
}
.empty {
    text-align: center; padding: 60px;
    color: var(--text-secondary);
}
.empty h3 { margin-bottom: 8px; color: var(--text-primary); }

/* --- Toast Notification --- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    max-width: calc(100vw - 48px);
    background: rgba(232, 245, 233, 0.96);
    color: #2e7d32;
    border: 1px solid rgba(102, 187, 106, 0.4);
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 0.875rem;
    z-index: 3000;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: toast-in 0.3s ease-out;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error {
    background: rgba(253, 237, 237, 0.96);
    color: #c62828;
    border-color: rgba(220, 53, 69, 0.4);
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.toast-undo {
    background: transparent; border: none;
    color: var(--accent); cursor: pointer;
    font-size: 0.875rem; font-weight: 600; padding: 4px 8px;
}
.toast-undo:hover { text-decoration: underline; }

/* --- Asana reconnect banner (409 asana_not_connected on task writes) --- */
.asana-reconnect-banner {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100vw - 32px);
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(253, 244, 227, 0.98);
    color: #8a5a00;
    border: 1px solid rgba(240, 180, 71, 0.55);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.875rem;
    z-index: 3200;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: toast-in 0.3s ease-out;
}
.asana-reconnect-msg { flex: 1 1 auto; }
.asana-reconnect-connect {
    flex: 0 0 auto;
    background: var(--accent); color: #fff; border: none;
    border-radius: 6px; cursor: pointer;
    font-size: 0.8125rem; font-weight: 600; padding: 6px 12px;
}
.asana-reconnect-connect:hover { filter: brightness(1.05); }
.asana-reconnect-close {
    flex: 0 0 auto;
    background: transparent; border: none;
    color: inherit; cursor: pointer; opacity: 0.7;
    font-size: 0.875rem; line-height: 1; padding: 4px 6px;
}
.asana-reconnect-close:hover { opacity: 1; }

/* --- Modal --- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
}
.modal-overlay.hidden { display: none; }
.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 90%; max-width: 440px;
}
.modal-content h3 {
    font-size: 1.125rem; font-weight: 600; margin-bottom: 16px;
}
.modal-input {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg-primary); color: var(--text-primary);
    font-size: 0.875rem; font-family: inherit; outline: none;
}
.modal-input:focus { border-color: var(--accent); }
.modal-actions {
    display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px;
}
.modal-btn {
    padding: 8px 16px; border-radius: 6px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text-secondary); cursor: pointer;
    font-size: 0.875rem; transition: all 0.2s;
}
.modal-btn:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.modal-btn.primary {
    background: var(--accent); border-color: var(--accent); color: white;
}
.modal-btn.primary:hover { opacity: 0.85; }

/* --- Modal (shared) --- */
.modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}
.modal h2 {
    font-size: 1.125rem;
    margin-bottom: 16px;
}
.modal-body { margin-bottom: 20px; }
.modal textarea {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    min-height: 120px;
    resize: vertical;
}
.modal textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* --- Draft conflict side-by-side diff (shared/draft-conflict-diff.js) --- */
.draft-conflict-diff-scroll {
    margin-bottom: 16px;
    overflow: auto;
    max-height: min(45vh, 360px);
    min-height: 120px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
}
.draft-conflict-diff-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
    font-size: 0.75rem;
    line-height: 1.45;
}
.draft-conflict-diff-table thead {
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 1;
}
.draft-conflict-diff-table th {
    text-align: left;
    padding: 6px 8px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    white-space: nowrap;
}
.draft-conflict-diff-table td {
    vertical-align: top;
    padding: 2px 8px;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.draft-conflict-diff-table .line-no {
    width: 28px;
    text-align: right;
    color: var(--text-secondary);
    opacity: 0.7;
    user-select: none;
    padding-right: 6px;
}
.draft-conflict-diff-table .col-local {
    border-right: 1px solid var(--border);
}
.draft-conflict-diff-table td.diff-del {
    background: rgba(239, 83, 80, 0.12);
    border-left: 3px solid #ef5350;
}
.draft-conflict-diff-table td.diff-ins {
    background: rgba(76, 175, 80, 0.12);
    border-left: 3px solid #66bb6a;
}
.draft-conflict-diff-table td.diff-change {
    background: rgba(255, 183, 77, 0.10);
}
.draft-conflict-diff-table td.col-local.diff-change,
.draft-conflict-diff-table td.col-server.diff-change {
    border-left: 3px solid #ffb74d;
}
.draft-conflict-diff-table .diff-inline-del {
    background: rgba(239, 83, 80, 0.30);
    text-decoration: line-through;
}
.draft-conflict-diff-table .diff-inline-ins {
    background: rgba(76, 175, 80, 0.35);
}

/* --- @ mention notify confirmation modal (shared/mention-notify.js) --- */
.mention-notify-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    cursor: pointer;
}
.mention-notify-row .mention-notify-checkbox {
    flex-shrink: 0;
}
.mention-notify-row .mention-notify-name {
    color: var(--text-primary);
    font-size: 0.875rem;
}
.mention-notify-row .mention-notify-email {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* --- Toolbar Buttons --- */
.btn-toolbar {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.btn-toolbar:hover { border-color: var(--accent); color: var(--accent); }
.btn-toolbar:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-toolbar svg { width: 14px; height: 14px; }
.btn-toolbar--accent { color: var(--accent); }
.btn-toolbar--accent:hover:not(:disabled) { border-color: var(--accent); background: rgba(139, 111, 71, 0.08); }
.btn-toolbar--success { color: #2e7d32; border-color: #1b4332; }
.btn-toolbar--success:hover:not(:disabled) { border-color: #2e7d32; background: rgba(102, 187, 106, 0.1); }
.btn-toolbar--danger { color: #b85c3a; }
.btn-toolbar--danger:hover:not(:disabled) { border-color: #b85c3a; background: rgba(184, 92, 58, 0.08); }
.btn-toolbar--gold { color: #d4a030; }
.btn-toolbar--gold:hover:not(:disabled) { border-color: #d4a030; background: rgba(212, 160, 48, 0.08); }

/* --- Help "?" button (shared across pages) --- */
.help-btn-shared {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: all 0.15s;
}
.help-btn-shared:hover { border-color: var(--accent); color: var(--accent); }

/* Progressive streaming markdown wrappers (conversation-embed.js +
   markdown-utils.js renderStreamingMarkdown). The streamed message body is
   split into per-block elements for memoized rendering; display:contents keeps
   those wrappers layout-transparent so the streamed bubble lays out identically
   to the flat, finalized render — no spacing change when the turn finalizes.
   .prep-stream-root (the whole segmented message), .streaming-prep-segment
   (wraps each prep .prep-wrapper) and .streaming-block-group (wraps a body
   segment's own .streaming-block children) are the prep-aware streaming
   path's equivalents — layout-transparent for the same reason, so a message
   with a ray:prep section lays out identically whether it's mid-stream or
   finalized/history (renderContentWithPrep has none of these wrapper divs -
   it emits .prep-wrapper / block markup directly). Note: .prep-wrapper itself
   is intentionally NOT display:contents — it renders as a real bordered box. */
.streaming-chips,
.streaming-markdown,
.streaming-blocks,
.streaming-block,
.streaming-trailing,
.prep-stream-root,
.streaming-prep-segment,
.streaming-block-group {
    display: contents;
}

/* --- Dark mode (follows the OS setting) ---
   Ray's web client is token-driven: almost every color comes from the CSS
   custom properties in :root above, so redefining that ~15-token set here
   flips every page that consumes them. The extra rules below patch the handful
   of SHARED components that hardcode a light-assuming literal (a black hover
   overlay that would be invisible on dark, a pastel notification chip, dark-on-
   dark accent text). Page-local hardcoded colors are handled in each page's own
   dark block. Only dark styling lives here — light mode is untouched.
   --accent stays a mid warm tan so button text (white) and accent-as-text both
   stay legible on the dark surfaces. */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1b1a18;
        --bg-secondary: #262420;
        --bg-tertiary: #322f29;
        /* --accent / --accent-hover deliberately inherit the light values:
           accent doubles as a button FILL (white text) and as text/borders. A
           lighter dark-accent reads nicer as text but drops white-on-accent
           below WCAG AA (4.5:1) on the primary buttons ("New Project", "Create")
           — and that fill+white pattern recurs in un-audited page-local buttons
           across the client, which a lighter shared accent would silently worsen.
           Keeping #8b6f47 holds white-on-accent at 4.71:1 (AA) everywhere; the
           few accent-COLORED small texts read at ~3.3:1 (AA-large/UI) — a
           cosmetic follow-up, not a regression. */
        --text-primary: #ece8e1;
        --text-secondary: #a7a199;
        --text-muted: #7c766d;
        --border: #3b372f;
        --card-bg: rgba(200, 168, 118, 0.05);
        --success-bg: rgba(102, 187, 106, 0.16);
        --success-text: #82cf92;
        --danger: #ef7b7d;
        --warning: #f0b429;
    }

    /* Black hover overlays are invisible on a dark surface — flip to a faint
       light overlay so hover feedback survives. */
    .nav-link:hover { background: rgba(255, 255, 255, 0.06); }
    .btn.btn-secondary:hover, .btn-secondary:hover { background: rgba(255, 255, 255, 0.06); }
    .btn-icon:hover { background: rgba(255, 255, 255, 0.07); }

    /* A stronger scrim reads better over a dark page. */
    .modal-overlay { background: rgba(0, 0, 0, 0.6); }

    /* Semantic button text tuned for legibility on dark. */
    .btn.btn-danger, .btn-danger { color: #e0906f; }
    .btn.btn-danger:hover, .btn-danger:hover { background: rgba(224, 144, 111, 0.16); }
    .btn-toolbar--success { color: #82cf92; border-color: #3a5a44; }
    .btn-toolbar--danger { color: #e0906f; }

    /* Notification chips: swap the pale pastel fills for deep translucent tints
       so they read as chips on a dark page instead of glaring bright blocks. */
    .toast {
        background: rgba(30, 51, 33, 0.94);
        color: #a5d6a7;
        border-color: rgba(102, 187, 106, 0.35);
    }
    .toast.error {
        background: rgba(58, 28, 30, 0.94);
        color: #ef9a9a;
        border-color: rgba(220, 53, 69, 0.4);
    }
    .asana-reconnect-banner {
        background: rgba(58, 46, 24, 0.96);
        color: #e6c98a;
        border-color: rgba(240, 180, 71, 0.45);
    }
}
