/* Address Timeline Bot — Gemini-inspired minimal UI */

/* ============================================================
   Variables & Reset
   ============================================================ */

:root {
    --bg: #1a1a2e;
    --bg-chat: #131321;
    --surface: #232340;
    --surface-hover: #2d2d4a;
    --border: rgba(255, 255, 255, 0.06);
    --text: #e8e8f0;
    --text-secondary: #9494b8;
    --text-muted: #6b6b8a;
    --accent: #7c6cf0;
    --accent-hover: #9488f7;
    --accent-subtle: rgba(124, 108, 240, 0.12);
    --user-bg: #2a2a4a;
    --assistant-bg: transparent;
    --danger: #f06c6c;
    --success: #6cf0a8;
    --warning: #f0d06c;

    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;

    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --transition: 150ms ease;
    --max-width: 800px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

ul, ol { list-style: none; }

code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85em;
    background: var(--surface);
    padding: 2px 7px;
    border-radius: 4px;
    color: var(--accent);
}

/* ============================================================
   App Layout
   ============================================================ */

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================================
   Top Bar
   ============================================================ */

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-logo {
    font-size: 22px;
}

.app-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.3px;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mode-switcher {
    display: flex;
    background: var(--surface);
    border-radius: var(--radius-full);
    padding: 3px;
}

.mode-btn {
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.mode-btn:hover {
    color: var(--text);
}

.mode-btn.active {
    background: var(--accent);
    color: #fff;
}

/* ============================================================
   Chat Main Area
   ============================================================ */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-chat);
}

/* ============================================================
   Messages Container
   ============================================================ */

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ============================================================
   Welcome State (Gemini-style centered)
   ============================================================ */

.welcome-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    gap: 16px;
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 8px;
}

.welcome-title {
    font-size: 32px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.5px;
}

.welcome-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    max-width: 400px;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 24px;
}

.chip {
    padding: 10px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 14px;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.chip:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--accent);
}

/* ============================================================
   Messages
   ============================================================ */

.message {
    display: flex;
    gap: 12px;
    max-width: var(--max-width);
    width: 100%;
    margin: 0 auto;
    padding: 16px 0;
    animation: fadeIn 250ms ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user-message {
    padding: 12px 0;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    background: var(--surface);
}

.user-message .message-avatar {
    background: var(--accent-subtle);
}

.message-content {
    flex: 1;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
    min-width: 0;
}

.user-message .message-content {
    background: var(--user-bg);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    border-top-left-radius: var(--radius-sm);
}

.message-content p {
    margin-bottom: 10px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Loading dots */
.message-loading {
    display: flex;
    gap: 6px;
    padding: 8px 0;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) { animation-delay: 0s; }
.loading-dot:nth-child(2) { animation-delay: 0.16s; }
.loading-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Loading status text */
.loading-status {
    font-size: 13px;
    color: var(--text-muted);
    animation: pulse 1.5s infinite;
    margin-top: 6px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Error state */
.message-error .message-content {
    background: rgba(240, 108, 108, 0.08);
    border: 1px solid rgba(240, 108, 108, 0.2);
    padding: 12px 18px;
    border-radius: var(--radius-md);
}

.error-content {
    color: var(--danger);
    font-weight: 500;
}

.retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 7px 16px;
    background: var(--danger);
    color: #fff;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    transition: background var(--transition);
}

.retry-btn:hover {
    background: #e05555;
}

/* ============================================================
   Data Results Table
   ============================================================ */

.results-table-wrapper {
    overflow-x: auto;
    margin-top: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.results-table th {
    padding: 8px 12px;
    text-align: left;
    background: var(--surface);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

.results-table td {
    padding: 8px 12px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.results-table tr:last-child td {
    border-bottom: none;
}

.results-table tr:hover td {
    background: var(--surface-hover);
}

.results-meta {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================================
   Timeline Events (inline in messages)
   ============================================================ */

.timeline-inline {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.timeline-event {
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}

.timeline-event-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.timeline-event-icon { font-size: 14px; }

.timeline-event-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.timeline-event-date {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: auto;
}

.timeline-event-details {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Category border colors */
.timeline-event[data-category="DEFECT"] { border-left-color: #f06c6c; }
.timeline-event[data-category="RDR_ENTRY"] { border-left-color: #fd7e14; }
.timeline-event[data-category="LMAQ_ENTRY"] { border-left-color: #6c9cf0; }
.timeline-event[data-category="FQA_VISIT"] { border-left-color: #6cf0a8; }
.timeline-event[data-category="SHIPMENT"] { border-left-color: #9494b8; }
.timeline-event[data-category="CONTACT"] { border-left-color: #b06cf0; }
.timeline-event[data-category="PIPELINE_ROUTING"] { border-left-color: #6cf0d0; }
.timeline-event[data-category="CORRECTION"] { border-left-color: #f0d06c; }

/* ============================================================
   Input Area
   ============================================================ */

.input-area {
    padding: 12px 24px 20px;
    background: var(--bg-chat);
    flex-shrink: 0;
}

.input-form {
    max-width: var(--max-width);
    margin: 0 auto;
}

.input-container {
    display: flex;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 20px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.input-field {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    padding: 10px 0;
    resize: none;
    outline: none;
    max-height: 300px;
    min-height: 24px;
}

.input-field::placeholder {
    color: var(--text-muted);
}

.submit-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background var(--transition), transform var(--transition);
}

.submit-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.submit-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    padding: 6px 4px 0;
}

.char-count {
    font-size: 11px;
    color: var(--text-muted);
}

.char-count.near-limit { color: var(--warning); }
.char-count.at-limit { color: var(--danger); font-weight: 600; }

.input-hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* ============================================================
   Scrollbar
   ============================================================ */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
    .top-bar { padding: 10px 16px; }
    .messages-container { padding: 16px; }
    .input-area { padding: 10px 16px 16px; }
    .welcome-title { font-size: 24px; }
    .suggestion-chips { gap: 6px; }
    .chip { padding: 8px 14px; font-size: 13px; }
}


/* ============================================================
   Progress Panel (live investigation status)
   ============================================================ */

.progress-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

.progress-icon {
    font-size: 16px;
    width: 24px;
    text-align: center;
}

.progress-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    min-width: 130px;
}

.progress-status {
    font-size: 12px;
    margin-left: auto;
}

.status-pending { color: var(--text-muted); }
.status-running { color: var(--accent); animation: pulse 1.5s infinite; }
.status-done { color: var(--success); }
.status-error { color: var(--danger); }

/* Hierarchy display */
.hierarchy-display {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.hier-chip {
    display: inline-block;
    padding: 4px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 12px;
    color: var(--text-secondary);
}


/* ============================================================
   Summary Stats & Defect Breakdown
   ============================================================ */

.summary-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.stat-chip {
    display: inline-block;
    padding: 5px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-success { color: var(--success); border-color: rgba(108, 240, 168, 0.3); }
.stat-defect { color: var(--danger); border-color: rgba(240, 108, 108, 0.3); }
.stat-channel { color: var(--accent); border-color: rgba(124, 108, 240, 0.2); }

.section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 14px 0 6px;
}

.defect-breakdown {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.defect-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
}

.defect-badge {
    display: inline-block;
    padding: 2px 10px;
    background: rgba(240, 108, 108, 0.12);
    border: 1px solid rgba(240, 108, 108, 0.25);
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    color: var(--danger);
    min-width: 60px;
    text-align: center;
}

.defect-count {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    min-width: 24px;
}

.defect-pct {
    font-size: 12px;
    color: var(--text-muted);
}


/* ============================================================
   Auth Badge
   ============================================================ */

.auth-badge {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    margin-left: 8px;
}

.auth-badge.auth-ok {
    color: var(--success);
    border-color: rgba(108, 240, 168, 0.3);
}

.auth-badge.auth-expired {
    color: var(--danger);
    border-color: rgba(240, 108, 108, 0.3);
}


/* ============================================================
   Cancel Button
   ============================================================ */

.progress-actions {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.cancel-all-btn {
    padding: 6px 14px;
    background: rgba(240, 108, 108, 0.12);
    border: 1px solid rgba(240, 108, 108, 0.3);
    border-radius: var(--radius-full);
    color: var(--danger);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.cancel-all-btn:hover {
    background: rgba(240, 108, 108, 0.25);
}


.skip-btn {
    margin-left: auto;
    padding: 2px 8px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition);
    opacity: 0.6;
}

.skip-btn:hover {
    opacity: 1;
    color: var(--warning);
    border-color: var(--warning);
}

.progress-row .status-done ~ .skip-btn,
.progress-row .status-error ~ .skip-btn {
    display: none;
}


.download-link {
    display: inline-block;
    padding: 4px 12px;
    background: var(--accent-subtle);
    border: 1px solid var(--accent);
    border-radius: var(--radius-full);
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.download-link:hover {
    background: var(--accent);
    color: #fff;
}


.progress-timer {
    font-size: 11px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    min-width: 45px;
    text-align: right;
}


/* ============================================================
   Identifier Type Selector
   ============================================================ */

.identifier-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    max-width: var(--max-width);
    margin-left: auto;
    margin-right: auto;
}

.id-type-btn {
    padding: 5px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.id-type-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

.id-type-btn.active {
    background: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent);
}


/* Expandable source data */
.progress-label.expandable {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.progress-label.expandable:hover {
    color: var(--accent);
}

.source-data-panel {
    padding: 8px 12px 12px 36px;
    max-height: 300px;
    overflow-y: auto;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
}
