/* =====================================================================
   Chat — center column, composer, popovers, side-panel widgets
   Loaded after chat-sessions.css so same-specificity rules here win.
   ===================================================================== */

/* ---------------------------------------------------------------------
   Center column
   --------------------------------------------------------------------- */
.chat-sessions-container {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    background: transparent;
}

.chat-messages-container {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
    -webkit-overflow-scrolling: touch;
}

.chat-messages-container::-webkit-scrollbar { width: 6px; }
.chat-messages-container::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }

/* Everything inside the messages column is centred to a readable measure */
.chat-messages-container > * {
    width: 100%;
    max-width: 780px;
    margin-left: auto;
    margin-right: auto;
}

/* ---------------------------------------------------------------------
   Messages
   --------------------------------------------------------------------- */
.chat-message {
    display: flex;
    gap: 10px;
    align-self: auto;
    max-width: 780px;
    margin-bottom: 18px;
    animation: fadeInUp 0.2s ease;
}

.chat-message .message-avatar {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin-top: 1px;
}

.chat-message .message-content {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    padding: 0;
    background: transparent;
    border-radius: 0;
    color: var(--ink);
    line-height: 1.6;
}

/* Bulma ships a .message-header component (grey band); neutralise it here */
.chat-message .message-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
    padding: 0;
    background: transparent;
    border-radius: 0;
    color: inherit;
    font-weight: normal;
    line-height: 1.25;
}

.chat-message .message-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
}

.chat-message .message-time {
    font-size: 11.5px;
    color: var(--ink-3);
    margin: 0;
}

.chat-message .message-text {
    font-size: 15px;
    line-height: 1.65;
    color: var(--ink);
    background: transparent;
    border: 0;
    padding: 0;
    border-radius: 0;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

/* User: right-aligned bubble, no avatar */
.chat-message.user {
    flex-direction: row-reverse;
    justify-content: flex-start;
    align-self: auto;
}

.chat-message.user .message-avatar { display: none; }

.chat-message.user .message-content {
    flex: 0 1 auto;
    max-width: min(78%, 620px);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    background: transparent;
    padding: 0;
    border-radius: 0;
}

.chat-message.user .message-header { margin-bottom: 4px; padding-right: 4px; }

.chat-message.user .message-header { flex-direction: row-reverse; }
.chat-message.user .message-name { display: none; }

.chat-message.user .message-text {
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 10px 14px;
    border-radius: 16px 16px 4px 16px;
    font-size: 14.5px;
    white-space: pre-wrap;
}

/* Error */
.chat-message.error .message-avatar { background: linear-gradient(135deg, #f87171, #ef4444); }
.chat-message.error .message-text {
    background: rgba(248, 113, 113, 0.10);
    border: 1px solid rgba(248, 113, 113, 0.30);
    color: #fca5a5;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 500;
}
.chat-message.error .message-text strong { color: inherit; font-weight: 600; }

/* Model badge under assistant messages */
.chat-message .message-model-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-1);
    border: 1px solid var(--line);
    font-size: 11px;
    color: var(--ink-3);
    font-weight: 500;
    width: fit-content;
}

/* Streaming */
.chat-message.streaming-message .message-text::after {
    content: '';
    display: inline-block;
    width: 8px;
    height: 15px;
    margin-left: 3px;
    vertical-align: text-bottom;
    background: var(--accent);
    border-radius: 2px;
    animation: blink 1s infinite;
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 8px 2px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-3);
    animation: typing 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* System notice (inline) */
.chat-message.system-notice {
    display: block;
    margin: 6px auto 16px;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--accent-bg);
    border-left: 3px solid var(--accent);
    font-size: 13px;
    color: var(--ink-2);
    text-align: center;
}

/* ---------------------------------------------------------------------
   Markdown inside assistant messages (ported from chat-interface.css)
   --------------------------------------------------------------------- */
.message-text > :first-child { margin-top: 0; }
.message-text > :last-child { margin-bottom: 0; }
.message-text p { margin: 0 0 10px; }
.message-text h1, .message-text h2, .message-text h3, .message-text h4 {
    color: var(--ink);
    margin: 14px 0 6px;
    font-weight: 600;
    line-height: 1.3;
}
.message-text h1 { font-size: 1.15em; }
.message-text h2 { font-size: 1.08em; }
.message-text h3 { font-size: 1.02em; }
.message-text h4 { font-size: 1em; }
.message-text strong { color: var(--ink); font-weight: 600; }
.message-text em { color: var(--ink-2); }
.message-text a { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.message-text code {
    background: var(--surface-1);
    border: 1px solid var(--line);
    padding: 1px 6px;
    border-radius: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
    color: var(--accent-ink);
    white-space: pre-wrap;
    word-break: break-word;
}
.message-text pre {
    background: var(--surface-1);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 8px 0;
    overflow-x: auto;
}
.message-text pre code { background: transparent; border: 0; padding: 0; color: var(--ink); white-space: pre; }
.message-text blockquote {
    border-left: 3px solid var(--accent);
    background: var(--accent-bg);
    padding: 8px 12px;
    margin: 8px 0;
    border-radius: 0 8px 8px 0;
    color: var(--ink-2);
}
.message-text ul, .message-text ol { margin: 6px 0 10px; padding-left: 22px; }
.message-text li { margin: 3px 0; }
.message-text hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.message-text table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 8px 0 12px;
    font-size: 0.92em;
}
.message-text th, .message-text td {
    border: 1px solid var(--line);
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}
.message-text th { background: var(--surface-1); color: var(--ink); font-weight: 600; }
.message-text tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }

/* ---------------------------------------------------------------------
   Welcome / empty states
   --------------------------------------------------------------------- */
.welcome-card-msg {
    margin: 4px auto 22px;
    padding: 18px 20px;
    border-radius: 14px;
    background: var(--surface-1);
    border: 1px solid var(--line);
}

.welcome-card-msg h3 {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
}

.welcome-card-msg p {
    margin: 0 0 12px;
    color: var(--ink-2);
    font-size: 13.5px;
}

.welcome-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.welcome-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    font-size: 12.5px;
    color: var(--ink-2);
}

.welcome-chip i { color: var(--ink-3); font-size: 11px; }

.suggest-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.suggest-btn {
    height: auto;
    min-height: 44px;
    padding: 10px 12px;
    text-align: left;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--stage-bg);
    color: var(--ink);
    font-size: 13.5px;
    line-height: 1.35;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.suggest-btn:hover { background: var(--surface-2); border-color: var(--line-strong); }

.welcome-disclaimer {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    color: var(--ink-3);
    line-height: 1.45;
}

.chat-empty {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    gap: 8px;
}

.chat-empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-bg);
    color: var(--accent-ink);
    font-size: 22px;
    margin-bottom: 6px;
}

.chat-empty h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--ink);
}

.chat-empty p {
    margin: 0 0 12px;
    color: var(--ink-2);
    font-size: 14px;
    max-width: 420px;
}

.chat-empty-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

/* ---------------------------------------------------------------------
   Composer
   --------------------------------------------------------------------- */
.chat-composer {
    flex: 0 0 auto;
    padding: 6px 16px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, var(--stage-bg) 70%, transparent);
}

.chat-composer-inner {
    max-width: 780px;
    margin: 0 auto;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 8px 8px 8px;
    border-radius: 18px;
    background: var(--surface-1);
    border: 1px solid var(--line-strong);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-input-wrapper:focus-within {
    border-color: rgba(124, 127, 243, 0.6);
    box-shadow: 0 0 0 3px rgba(124, 127, 243, 0.15), 0 8px 30px rgba(0, 0, 0, 0.25);
}

.composer-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--ink-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background 0.12s ease, color 0.12s ease;
}

.composer-btn:hover { background: var(--surface-2); color: var(--ink); }

.chat-input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 34px;
    max-height: 200px;
    padding: 7px 6px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-family: var(--shell-font);
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    outline: none;
    box-shadow: none;
}

.chat-input::placeholder { color: var(--ink-3); }
.chat-input:disabled { opacity: 0.6; }

.chat-send-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--ink);
    color: var(--shell-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    flex: 0 0 auto;
    transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

.chat-send-btn:hover:not(:disabled) { transform: translateY(-1px); }
.chat-send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.composer-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px 0;
    font-size: 12px;
    color: var(--ink-3);
    flex-wrap: wrap;
}

.composer-meta .dot { opacity: 0.5; }
.composer-meta button {
    height: auto;
    min-height: 0;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink-2);
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}
.composer-meta button:hover { color: var(--ink); }
.composer-meta .quota-value { font-weight: 600; }

/* ---------------------------------------------------------------------
   Profile popover list
   --------------------------------------------------------------------- */
.profile-pick-list {
    max-height: min(52vh, 420px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
}

.profile-pick {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--ink);
    transition: background 0.12s ease;
}

.profile-pick:hover { background: var(--surface-3); }
.profile-pick.is-selected { background: var(--accent-bg); }

.profile-pick .pick-avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.profile-pick .pick-avatar.family { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
.profile-pick .pick-avatar.partner { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); }
.profile-pick .pick-avatar.friend { background: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%); }
.profile-pick .pick-avatar.colleague { background: linear-gradient(135deg, #30cfd0 0%, #330867 100%); }

.profile-pick .pick-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.profile-pick .pick-name {
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-pick .pick-sub {
    font-size: 11.5px;
    color: var(--ink-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-pick .pick-check { color: var(--accent-ink); font-size: 12px; }
.profile-pick:not(.is-selected) .pick-check { visibility: hidden; }

.no-profiles {
    padding: 14px 10px;
    text-align: center;
    color: var(--ink-3);
    font-size: 13px;
}
.no-profiles i { font-size: 18px; margin-bottom: 6px; display: block; opacity: 0.6; }
.no-profiles p { margin: 0; color: var(--ink-2); }

/* ---------------------------------------------------------------------
   Side-panel widgets
   --------------------------------------------------------------------- */
.settings-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

.settings-row:last-child { border-bottom: 0; }

.settings-row label,
.settings-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.settings-row select,
.settings-row .aura-quick-dropdown,
.settings-row .model-dropdown {
    width: 100%;
    min-height: 36px;
    padding: 6px 30px 6px 10px;
    margin: 0;
    border-radius: 8px;
    background-color: var(--surface-1);
    border: 1px solid var(--line);
    color: var(--ink);
    font-size: 13.5px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.6)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
}

.settings-row select:hover { border-color: var(--line-strong); }
.settings-row select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(124, 127, 243, 0.2); }
.settings-row select option { background: #1f1f24; color: var(--ink); }

.settings-help {
    font-size: 12px;
    color: var(--ink-3);
    line-height: 1.4;
}

.quota-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--surface-2);
    overflow: hidden;
}

.quota-bar > span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--ok);
    border-radius: 3px;
    transition: width 0.3s ease, background 0.3s ease;
}

.quota-line {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--ink-2);
}

.quota-line .quota-value { font-weight: 600; }

.aura-quick-row { display: flex; gap: 6px; align-items: center; }
.aura-quick-row select { flex: 1 1 auto; }

.profile-facts {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.profile-fact {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
}

.profile-fact span:first-child { color: var(--ink-3); }
.profile-fact span:last-child { color: var(--ink); text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* Chart card body: reuse chart-sessions.css inner styles, drop the old frame */
.chart-display-panel {
    width: auto;
    height: auto;
    max-height: none;
    display: block;
    background: transparent;
    border: 0;
    border-radius: 0;
    backdrop-filter: none;
}

.chart-content {
    min-height: 0;
    max-height: none;
    padding: 0;
}

.no-chart { color: var(--ink-3); }

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 767px) {
    .chat-messages-container { padding: 14px 12px 6px; }
    .chat-message { margin-bottom: 14px; }
    .chat-message .message-text { font-size: 14.5px; }
    .chat-message.user .message-content { max-width: 88%; }
    .chat-composer { padding: 4px 10px 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
    .chat-input { font-size: 16px; } /* prevents iOS zoom */
    .composer-meta { padding: 6px 6px 0; }
    .suggest-grid { grid-template-columns: 1fr; }
}

@keyframes blink {
    0%, 50%, 100% { opacity: 0.25; }
    25%, 75% { opacity: 1; }
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

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

/* Old aura quick-selector rules in chat-sessions.css (amber, inline) — restate for the panel */
.settings-row.aura-quick-selector {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 8px 0;
}
.settings-row.aura-quick-selector label { font-size: 12px; color: var(--ink-3); }
.aura-quick-row { width: 100%; }
.aura-quick-row select.aura-quick-dropdown {
    width: 100%;
    flex: 1 1 auto;
    background-color: var(--surface-1);
    backdrop-filter: none;
    border: 1px solid var(--line);
    color: var(--ink);
    font-size: 13.5px;
    padding: 6px 30px 6px 10px;
}
.aura-quick-row select.aura-quick-dropdown:hover { background-color: var(--surface-1); border-color: var(--line-strong); }
.aura-quick-row select.aura-quick-dropdown:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(124, 127, 243, 0.2); }
