/* Custom animations for HTMX transitions */
.htmx-swapping { opacity: 0; transition: opacity 200ms ease-out; }
.htmx-settling { opacity: 1; }
.htmx-added { opacity: 0; }
.htmx-added.htmx-settling { opacity: 1; transition: opacity 300ms ease-in; }

/* Inline "working…" label for an htmx button (hx-indicator points at it, so
   htmx toggles .htmx-request on the label itself). htmx's own indicator CSS
   only animates opacity, which leaves the label reserving its full width in a
   flex row and pushing the controls beside it sideways forever. Toggling
   display instead means it costs nothing until its request is in flight. */
.htmx-inline-indicator { display: none; }
.htmx-inline-indicator.htmx-request { display: inline; }

/* Smooth hover transitions */
.hover-lift { transition: all 200ms ease; }
.hover-lift:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

/* Custom scrollbar. Was 6px with no minimum thumb: on a long page — PE Signals
   runs to a thousand-odd signals — the thumb shrank to a few pixels and the
   6px gutter was a hard target to hit. The gutter is now 12px for grabbing;
   the thumb sits 2px inside it so it still reads as a control rather than a
   filled channel, and min-height keeps it usable however long the page gets. */
.custom-scrollbar::-webkit-scrollbar { width: 12px; height: 12px; }
.custom-scrollbar::-webkit-scrollbar-track { background: #f1f5f9; }
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 6px;
    min-height: 48px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
    background-clip: padding-box;
}
/* Firefox has no ::-webkit pseudo-elements; these two properties are the whole
   API it exposes, and without them it falls back to the OS default. */
.custom-scrollbar { scrollbar-width: auto; scrollbar-color: #cbd5e1 #f1f5f9; }

/* Table row hover */
tbody tr { transition: background-color 150ms ease; }
tbody tr:hover { background-color: #f8fafc; cursor: pointer; }
tbody tr.selected { background-color: #ecfdf5; }

/* Badge animations */
.badge-appear { animation: slideIn 200ms ease-out; }
@keyframes slideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Loading spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin 1s linear infinite; }

/* Typing dots */
@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}
.typing-dot { animation: bounce 1.2s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Range slider — emerald */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #059669;
    cursor: pointer;
    transition: all 150ms;
}
input[type="range"]::-webkit-slider-thumb:hover {
    background: #047857;
    transform: scale(1.1);
}
input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #059669;
    cursor: pointer;
    border: none;
}

/* Optimized for 14" MacBook (1272x700) */
:root {
    /* Height of the legal bar in base.html. Every page's scroll container
       subtracts it alongside the 52px nav, so the two always add up to the
       fixed shell — change it here, not in a page. */
    --legal-bar-h: 22px;
}
body {
    min-height: 700px;
    max-height: 700px;
    overflow: hidden;
    /* border-box (Tailwind preflight) keeps this inside the 700px, so the bar
       is reserved space rather than an overlay that clips the last row. */
    padding-bottom: var(--legal-bar-h);
}

/* One muted line on every screen; pinned so short pages carry it at the
   bottom edge too. Sits in the padding the body reserves above. */
.legal-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    height: var(--legal-bar-h);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0 0.75rem;
    background: #f9fafb;
    border-top: 1px solid #f3f4f6;
    font-size: 10px;
    line-height: 1;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
}
.legal-bar-link {
    color: #9ca3af;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.legal-bar-link:hover { color: #059669; }

/* Layout */
.chat-page {
    height: calc(700px - 52px - var(--legal-bar-h));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.app-shell {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 272px;
    min-width: 272px;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e5e7eb;
    background: #f9fafb;
    overflow: hidden;
    transition: width 200ms ease, min-width 200ms ease;
}
.sidebar-collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}
.sidebar-history {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.history-item-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 24px;
    align-items: center;
    column-gap: 2px;
    padding: 2px 2px 2px 4px;
    border-radius: 0.375rem;
    transition: background-color 150ms;
}
.history-item-row:hover { background-color: #d1fae5; }
.history-item-row.active { background-color: #d1fae5; }
.history-item-main {
    min-width: 0;
    overflow: hidden;
}
.history-item-title {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    text-align: left;
    padding: 6px 2px 6px 4px;
    font-size: 0.75rem;
    color: #374151;
    border: none;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-item-row.active .history-item-title { color: #065f46; font-weight: 600; }
.history-item-edit {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 5px 4px;
    font-size: 0.75rem;
    color: #374151;
    border: 1px solid #059669;
    border-radius: 0.25rem;
    background: white;
    outline: none;
    box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.15);
}
.history-item-menu {
    position: relative;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}
.history-item-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #9ca3af;
    border-radius: 0.25rem;
    transition: color 150ms, background-color 150ms;
}
.history-item-icon:hover { color: #059669; background: rgba(255, 255, 255, 0.6); }
.history-item-dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 2px;
    width: 7.5rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 30;
    padding: 4px 0;
}
.history-item-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 12px;
    font-size: 0.75rem;
    color: #374151;
    border: none;
    background: transparent;
    cursor: pointer;
}
.history-item-dropdown button:hover { background: #f9fafb; }
.history-item-dropdown-danger { color: #dc2626 !important; }
.history-item-dropdown-danger:hover { background: #fef2f2 !important; }
[x-cloak] { display: none !important; }

/* Chat area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.chat-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}
.sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border: none;
    background: transparent;
    color: #6b7280;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: color 150ms, background-color 150ms;
}
.sidebar-toggle:hover {
    color: #059669;
    background: #f3f4f6;
}
.chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

/* Message bubbles */
.message-user {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}
.message-user .bubble {
    background: #059669;
    color: white;
    padding: 8px 14px;
    border-radius: 18px 18px 4px 18px;
    max-width: 70%;
    font-size: 0.875rem;
    line-height: 1.5;
}
.message-assistant {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 16px;
}
.message-assistant .bubble {
    background: white;
    border: 1px solid #e5e7eb;
    padding: 10px 14px;
    border-radius: 18px 18px 18px 4px;
    max-width: 85%;
    font-size: 0.875rem;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Scalar response */
.response-scalar {
    font-size: 2rem;
    font-weight: 700;
    color: #059669;
    line-height: 1.2;
}
.response-scalar-label {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 2px;
}

/* Response table */
.response-table-wrap {
    overflow-x: auto;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    margin-top: 4px;
}
.response-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}
.response-table thead th {
    background: #ecfdf5;
    color: #065f46;
    font-weight: 600;
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid #d1fae5;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
.response-table thead th:hover { background: #d1fae5; }
.response-table tbody td {
    padding: 5px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
}
.response-table tbody tr:last-child td { border-bottom: none; }

/* CSV download button */
.csv-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 4px 10px;
    font-size: 0.7rem;
    font-weight: 500;
    color: #059669;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 150ms;
}
.csv-btn:hover { background: #d1fae5; }

/* Input bar */
.input-bar {
    flex-shrink: 0;
    width: 100%;
    border-top: 1px solid #e5e7eb;
    padding: 10px 16px;
    background: white;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}
.input-bar textarea {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    padding: 8px 12px;
    font-size: 0.875rem;
    line-height: 1.5;
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    transition: border-color 150ms, box-shadow 150ms;
    font-family: inherit;
}
.input-bar textarea:focus {
    border-color: #059669;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}
.send-btn {
    padding: 8px 16px;
    background: #059669;
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 150ms;
    white-space: nowrap;
}
.send-btn:hover { background: #047857; }
.send-btn:disabled { background: #9ca3af; cursor: not-allowed; }

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    text-align: center;
    padding: 32px;
}
