/* ---------------------------------------------------------------
   Patnavis – ChatGPT/Claude-inspired patent search UI
   --------------------------------------------------------------- */

/* ---------------------------------------------------------------
   Theme tokens (light mode defaults)
   --------------------------------------------------------------- */
:root {
    --color-bg:             #ffffff;
    --color-text:           #1a1a1a;
    --color-text-secondary: #666666;
    --color-text-muted:     #888888;
    --color-placeholder:    #aaaaaa;
    --color-border:         #d0d0d0;
    --color-border-light:   #e5e5e5;
    --color-surface:        #fafafa;
    --color-bubble:         #f0f0f0;
    --color-input-bg:       #ffffff;
    --color-btn-bg:         #1a1a1a;
    --color-btn-bg-hover:   #333333;
    --color-btn-text:       #ffffff;
    --color-patent-bg:      #e8f4e8;
    --color-patent-border:  #b0d4b0;
    --color-patent-text:    #2a6d2a;
    --color-overlay:        rgba(255, 255, 255, 0.85);
    --color-spinner-track:  #e0e0e0;
    --color-shadow:         rgba(0, 0, 0, 0.06);
    --color-shadow-strong:  rgba(0, 0, 0, 0.12);
    --color-error-bg:       #fee;
    --color-error-border:   #fcc;
    --color-error-text:     #a33;
    --color-menu-hover:     #f5f5f5;
    --color-source-text:    #444444;
    --gradient-bottom:      linear-gradient(transparent, #fff 20%);
}

/* ---------------------------------------------------------------
   Dark mode overrides
   --------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg:             #1a1a1a;
        --color-text:           #e4e4e4;
        --color-text-secondary: #a0a0a0;
        --color-text-muted:     #888888;
        --color-placeholder:    #666666;
        --color-border:         #3a3a3a;
        --color-border-light:   #2e2e2e;
        --color-surface:        #252525;
        --color-bubble:         #2a2a2a;
        --color-input-bg:       #252525;
        --color-btn-bg:         #e4e4e4;
        --color-btn-bg-hover:   #cccccc;
        --color-btn-text:       #1a1a1a;
        --color-patent-bg:      #1e3a1e;
        --color-patent-border:  #2d5a2d;
        --color-patent-text:    #7bc97b;
        --color-overlay:        rgba(26, 26, 26, 0.85);
        --color-spinner-track:  #3a3a3a;
        --color-shadow:         rgba(0, 0, 0, 0.2);
        --color-shadow-strong:  rgba(0, 0, 0, 0.4);
        --color-error-bg:       #3a1a1a;
        --color-error-border:   #5a2a2a;
        --color-error-text:     #f88;
        --color-menu-hover:     #333333;
        --color-source-text:    #b0b0b0;
        --gradient-bottom:      linear-gradient(transparent, #1a1a1a 20%);
    }
}

/* ---------------------------------------------------------------
   Reset & base
   --------------------------------------------------------------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Helvetica, Arial, sans-serif;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------
   Header
   --------------------------------------------------------------- */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 92px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 24px;
    z-index: 100;
    background: var(--color-bg);
}

.brand-logo {
    height: clamp(48px, 6vw, 83px);
    width: auto;
}

.brand {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--color-text);
}

/* ---------------------------------------------------------------
   Chat area
   --------------------------------------------------------------- */
#chat-area {
    padding: 108px 0 160px;   /* header clearance + input clearance */
    overflow-y: auto;
    height: 100%;
}

#chat-area.hidden {
    display: none;
}

#messages {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 24px;
}

/* User message – right-aligned bubble */
.message-user {
    display: flex;
    justify-content: flex-end;
    margin: 20px 0;
}

.message-user .bubble {
    background: var(--color-bubble);
    border-radius: 20px;
    padding: 12px 18px;
    max-width: 75%;
    line-height: 1.5;
    font-size: 15px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Agent message – full width, no bubble */
.message-agent {
    margin: 20px 0;
    line-height: 1.7;
    font-size: 15px;
}

.message-agent p {
    margin-bottom: 12px;
}

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

/* Thinking indicator */
.thinking {
    color: var(--color-text-muted);
}

.dots span {
    animation: blink 1.4s infinite both;
    font-size: 24px;
    line-height: 1;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 80%, 100% { opacity: 0.2; }
    40% { opacity: 1; }
}

/* Reasoning metadata */
.reasoning-meta {
    margin-top: 8px;
    font-size: 13px;
    color: var(--color-text-muted);
}

/* Sources expander */
.sources-expander {
    margin-top: 12px;
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    overflow: hidden;
}

.sources-expander summary {
    padding: 10px 14px;
    font-size: 13px;
    color: var(--color-text-secondary);
    cursor: pointer;
    background: var(--color-surface);
    user-select: none;
}

.source-item {
    padding: 12px 14px;
    border-top: 1px solid var(--color-border-light);
    font-size: 13px;
    line-height: 1.5;
}

.source-content {
    margin-top: 6px;
    color: var(--color-source-text);
    max-height: 200px;
    overflow-y: auto;
}

/* ---------------------------------------------------------------
   Input container – two modes
   --------------------------------------------------------------- */

/* START MODE: centered vertically */
#input-container.start-mode {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 680px;
}

/* CHAT MODE: pinned to bottom */
#input-container.chat-mode {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px calc((100% - 720px) / 2);
    padding-bottom: 24px;
    background: var(--gradient-bottom);
}

@media (max-width: 780px) {
    #input-container.chat-mode {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* Input box (textarea + actions) */
#input-box {
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 14px 16px 10px;
    background: var(--color-input-bg);
    box-shadow: 0 1px 6px var(--color-shadow);
    transition: border-color 0.15s;
}

#input-box:focus-within {
    border-color: var(--color-text-muted);
}

#query-input {
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text);
    background: transparent;
    max-height: 200px;
    overflow-y: auto;
}

#query-input::placeholder {
    color: var(--color-placeholder);
}

/* Actions row (dropdown + send) */
#input-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

/* ---------------------------------------------------------------
   Patent dropdown
   --------------------------------------------------------------- */
#patent-dropdown-wrapper {
    position: relative;
}

#patent-btn {
    padding: 6px 14px;
    font-size: 13px;
    font-family: inherit;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

#patent-btn:hover {
    background: var(--color-bubble);
}

#patent-btn.has-patent {
    background: var(--color-patent-bg);
    border-color: var(--color-patent-border);
    color: var(--color-patent-text);
}

/* Dropdown menu */
#patent-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    width: 280px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 4px 16px var(--color-shadow-strong);
    padding: 16px;
    z-index: 200;
}

#patent-menu.hidden {
    display: none;
}

#patent-menu label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#patent-number-input {
    width: 100%;
    padding: 8px 10px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    outline: none;
    margin-bottom: 10px;
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.15s;
}

#patent-number-input:focus {
    border-color: var(--color-text-muted);
}

#patent-fetch-btn {
    width: 100%;
    padding: 8px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    background: var(--color-btn-bg);
    color: var(--color-btn-text);
    cursor: pointer;
    transition: background 0.15s;
}

#patent-fetch-btn:hover {
    background: var(--color-btn-bg-hover);
}

#patent-menu hr {
    border: none;
    border-top: 1px solid var(--color-border-light);
    margin: 12px 0;
}

.menu-action {
    width: 100%;
    padding: 8px;
    font-size: 13px;
    font-family: inherit;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.menu-action:hover {
    background: var(--color-menu-hover);
}

.menu-action.hidden {
    display: none;
}

/* ---------------------------------------------------------------
   Send button
   --------------------------------------------------------------- */
#send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--color-btn-bg);
    color: var(--color-btn-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

#send-btn:hover {
    background: var(--color-btn-bg-hover);
}

#send-btn.hidden {
    display: none;
}

/* ---------------------------------------------------------------
   Loading overlay
   --------------------------------------------------------------- */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

#loading-overlay.hidden {
    display: none;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--color-spinner-track);
    border-top-color: var(--color-btn-bg);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

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

.loading-content p {
    font-size: 14px;
    color: var(--color-text-secondary);
}

/* ---------------------------------------------------------------
   Error toast
   --------------------------------------------------------------- */
.error-toast {
    position: fixed;
    top: 108px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-error-bg);
    border: 1px solid var(--color-error-border);
    color: var(--color-error-text);
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 600;
    box-shadow: 0 2px 8px var(--color-shadow);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------------------------------------------------------------
   Utility
   --------------------------------------------------------------- */
.hidden {
    display: none !important;
}
