:root {
    --ink: #152620;
    --muted: #64736e;
    --line: #dfe7e3;
    --paper: #ffffff;
    --canvas: #f2f8f5;
    /* Cores extraídas da nova identidade visual da CENTÁURIA. */
    --brand: #006b58;
    --brand-deep: #004a3e;
    --brand-2: #087965;
    --accent: #d79b4a;
    --danger: #a94642;
    --shadow: 0 18px 50px rgba(27, 58, 49, .08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 85% 0%, #dcefe8 0, transparent 30%), var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
    height: 76px;
    padding: 0 max(24px, calc((100vw - 1240px) / 2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255,255,255,.88);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(23,61,53,.08);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border-radius: 14px;
    overflow: hidden;
    background: var(--brand);
    box-shadow: 0 6px 18px rgba(0, 74, 62, .18);
}
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: cover; }
.brand strong, .brand small { display: block; }
.brand strong { color: var(--brand-deep); letter-spacing: .12em; font-size: 15px; }
.brand small { color: var(--muted); margin-top: 2px; }
.horse-switcher {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 270px;
    padding: 7px 9px;
    border: 1px solid #cfe0d9;
    border-radius: 15px;
    background: #f6faf8;
}
.horse-avatar {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    color: white;
    background: var(--brand);
    font-family: Georgia, serif;
    font-size: 18px;
    overflow: hidden;
}
.horse-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.horse-switcher label { min-width: 0; flex: 1; }
.horse-switcher small { display: block; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.horse-switcher select { width: 100%; padding: 1px 24px 1px 0; border: 0; outline: 0; color: var(--brand-deep); background: transparent; font-weight: 800; }
.horse-add { width: 31px; height: 31px; border: 0; border-radius: 9px; color: var(--brand); background: #e2efea; font-size: 20px; line-height: 1; }
.system-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.system-state a { color: var(--brand-2); font-weight: 700; margin-left: 10px; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: #aeb9b5; }
.state-dot.ok { background: #43a276; box-shadow: 0 0 0 4px rgba(67,162,118,.12); }

.page-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 72px; }
.hero {
    display: grid;
    grid-template-columns: minmax(170px, 1fr) auto minmax(170px, 1fr);
    align-items: center;
    gap: 24px;
    margin-bottom: 26px;
}
.hero-balance { min-width: 0; }
.hero-horse { min-width: 210px; text-align: center; }
.hero-horse-photo {
    width: 132px;
    height: 132px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 5px solid rgba(255,255,255,.92);
    border-radius: 50%;
    color: white;
    background:
        linear-gradient(145deg, rgba(0,107,88,.86), rgba(0,74,62,.98));
    box-shadow:
        0 16px 36px rgba(0,74,62,.18),
        0 0 0 1px rgba(0,74,62,.08);
    font-family: Georgia, serif;
    font-size: 46px;
}
.hero-horse-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.hero h1 { margin: 4px 0 8px; font-family: Georgia, serif; font-size: clamp(32px, 4vw, 52px); font-weight: 500; letter-spacing: -.035em; }
.hero p:not(.eyebrow) { color: var(--muted); margin: 0; max-width: 650px; }
.hero-actions { display: flex; gap: 8px; align-items: center; justify-self: end; }
.eyebrow { margin: 0; color: var(--brand-2); font-weight: 800; font-size: 11px; letter-spacing: .16em; text-transform: uppercase; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric { background: var(--paper); padding: 18px 20px; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 8px 28px rgba(27,58,49,.04); }
.metric span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.metric strong { font-family: Georgia, serif; font-size: 30px; font-weight: 500; }
.metric.warning strong { color: #9b6720; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(290px, .75fr); gap: 18px; align-items: stretch; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.panel-heading { padding: 20px 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 3px 0 0; font-size: 19px; }
.mode-pill { border: 1px solid #c9ddd5; background: #eff7f3; color: var(--brand-2); padding: 6px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.chat-heading-actions { display: flex; align-items: center; gap: 8px; }
.speech-settings {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 5px 4px 8px;
    border: 1px solid #d6e4de;
    border-radius: 12px;
    background: #f7faf8;
}
.speech-auto-control {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--brand-deep);
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
}
.speech-auto-control input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--brand);
}
.speech-auto-control.unavailable { color: var(--muted); cursor: not-allowed; opacity: .65; }
.speech-voice-control select {
    width: min(190px, 24vw);
    min-width: 118px;
    height: 30px;
    padding: 0 26px 0 8px;
    border: 1px solid #c9ddd5;
    border-radius: 8px;
    background: white;
    color: var(--brand-deep);
    font: inherit;
    font-size: 11px;
    font-weight: 700;
}
.speech-voice-control select:disabled { cursor: not-allowed; opacity: .6; }
.speech-test-button {
    min-height: 30px;
    padding: 5px 8px;
    border-radius: 8px;
    font-size: 11px;
}
.speech-test-button.speaking { color: white; background: var(--brand); }
.speech-settings.unavailable { opacity: .65; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.clear-chat { color: var(--danger); font-size: 12px; }
.clear-chat:hover { background: #f8ecea; }
.clear-chat:disabled { opacity: .5; cursor: wait; }

.chat-panel {
    /* A altura controlada impede que o histórico transforme a página em uma lista longa. */
    height: 640px;
    height: min(680px, calc(100dvh - 120px));
    min-height: 520px;
    max-height: 680px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.messages {
    /* Somente as mensagens rolam; cabeçalho e compositor permanecem visíveis. */
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.chat-panel > .panel-heading,
.chat-panel > .quick-prompts,
.chat-panel > .composer,
.chat-panel > .voice-status { flex: 0 0 auto; }
.message { display: flex; gap: 9px; min-width: 0; max-width: 84%; align-items: flex-end; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.has-chart { width: min(96%, 720px); max-width: min(96%, 720px); align-items: flex-start; }
.avatar { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 10px; display: grid; place-items: center; background: var(--brand); color: white; font-family: Georgia, serif; }
/* O assistente usa o símbolo da marca; o avatar do usuário continua textual. */
.message.assistant .avatar {
    color: transparent;
    background: var(--brand) url("/static/img/simbolo-centauria.png") center / cover no-repeat;
}
.message.user .avatar { background: #dfe9e4; color: var(--brand); }
.bubble { padding: 11px 14px; border-radius: 16px 16px 16px 4px; background: #edf3f0; line-height: 1.5; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .bubble { background: var(--brand); color: white; border-radius: 16px 16px 4px 16px; }
.message.has-chart .bubble { width: 100%; min-width: 0; }
.bubble-tools {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
    padding-top: 7px;
    border-top: 1px solid rgba(0,74,62,.1);
    white-space: normal;
}
.speak-message {
    border: 0;
    border-radius: 999px;
    padding: 5px 9px;
    color: var(--brand);
    background: rgba(0,107,88,.08);
    font-size: 11px;
    font-weight: 800;
}
.speak-message:hover { background: rgba(0,107,88,.14); }
.speak-message.speaking { color: white; background: var(--brand); }
.chat-chart {
    margin-top: 12px;
    padding: 14px;
    border: 1px solid #d6e4de;
    border-radius: 14px;
    background: #fff;
    white-space: normal;
}
.chat-chart-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 12px; }
.chat-chart-heading strong, .chat-chart-heading span { display: block; }
.chat-chart-heading strong { color: var(--ink); font-size: 13px; }
.chat-chart-heading span { color: var(--muted); margin-top: 2px; font-size: 10px; }
.chat-chart-heading > b { color: var(--brand); font-family: Georgia, serif; font-size: 27px; font-weight: 500; }
.chat-chart-area { position: relative; height: 270px; min-width: 0; }
.chat-chart-fallback { height: auto; display: grid; gap: 8px; }
.chat-chart-row { display: grid; grid-template-columns: minmax(105px, 1.25fr) 2fr 24px; gap: 7px; align-items: center; font-size: 10px; }
.chat-chart-row > i { height: 9px; overflow: hidden; border-radius: 999px; background: #e6eeea; }
.chat-chart-row > i > i { display: block; min-width: 2px; height: 100%; border-radius: inherit; background: var(--brand-2); }
.chat-chart-row > b { color: var(--brand); text-align: right; }
.message.pending .bubble { opacity: .6; }
.quick-prompts { padding: 0 22px 12px; display: flex; gap: 8px; overflow-x: auto; }
.quick-prompts { scrollbar-width: none; }
.quick-prompts::-webkit-scrollbar { display: none; }
.quick-prompts button { border: 1px solid var(--line); background: white; color: var(--brand); padding: 7px 10px; border-radius: 999px; white-space: nowrap; font-size: 12px; }
.composer { margin: 0 18px 18px; border: 1px solid #cbd8d3; border-radius: 17px; padding: 10px 10px 10px 14px; display: flex; align-items: flex-end; gap: 10px; background: #fbfcfb; }
.composer:focus-within { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(45,106,88,.1); }
.composer textarea { border: 0; outline: 0; resize: none; flex: 1; background: transparent; min-height: 42px; max-height: 130px; line-height: 1.45; }
.composer-actions { display: flex; gap: 7px; align-items: center; }
.voice-status { margin: -11px 22px 14px; min-height: 16px; color: var(--danger); font-size: 12px; }

.primary, .secondary, .icon-button, .text-button { border: 0; border-radius: 12px; font-weight: 750; }
.primary { color: white; background: var(--brand); padding: 11px 17px; }
.primary:hover { background: #225346; }
.primary:disabled { opacity: .55; cursor: wait; }
.primary.compact { padding: 10px 15px; }
.secondary { background: #edf2ef; color: var(--ink); padding: 11px 17px; }
.icon-button { width: 40px; height: 40px; color: var(--danger); background: #f4ebe9; font-size: 14px; }
.icon-button.listening { animation: pulse 1s infinite; background: #f1d5d2; }
.text-button { background: transparent; color: var(--brand-2); padding: 6px; }
@keyframes pulse { 50% { transform: scale(.88); opacity: .65; } }

.alerts-panel { min-height: 560px; overflow: hidden; }
.alerts-list { padding: 10px 16px 18px; max-height: 490px; overflow-y: auto; }
.alert-card { padding: 14px 8px; border-bottom: 1px solid var(--line); }
.alert-card:last-child { border-bottom: 0; }
.alert-date { display: flex; justify-content: space-between; color: var(--brand-2); font-weight: 800; font-size: 12px; }
.alert-card p { margin: 7px 0 10px; font-size: 14px; line-height: 1.4; }
.alert-card button { border: 0; color: var(--muted); background: #edf2ef; border-radius: 8px; padding: 6px 9px; font-size: 11px; }
.alert-heading-actions { display: flex; align-items: center; gap: 3px; }

.timeline-panel { margin-top: 18px; overflow: hidden; }
.timeline-heading { align-items: flex-end; }
.filters { display: flex; gap: 9px; }
.filters input, .filters select { border: 1px solid var(--line); border-radius: 11px; padding: 9px 11px; color: var(--ink); background: white; }
.timeline { padding: 6px 22px 24px; }
.day-group { margin-top: 20px; }
.day-label { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin: 0 0 10px; }
.event-card { position: relative; display: grid; grid-template-columns: 76px 1fr auto; gap: 14px; align-items: start; padding: 15px 0; border-top: 1px solid var(--line); }
.event-time { color: var(--muted); font-weight: 750; font-size: 13px; padding-top: 3px; }
.event-category { display: inline-block; color: var(--brand-2); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 5px; }
.event-title { margin: 0; font-size: 15px; }
.event-original { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.event-meta { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.event-meta span { background: #eef3f0; border-radius: 999px; padding: 4px 8px; font-size: 11px; color: #4e625a; }
.event-actions { display: flex; gap: 6px; }
.event-actions button { border: 1px solid var(--line); background: white; color: var(--muted); border-radius: 9px; padding: 7px 9px; font-size: 11px; }
.event-actions button:hover { color: var(--brand); border-color: #b8ccc4; }
.attachment-list { margin-top: 9px; display: flex; gap: 8px; flex-wrap: wrap; }
.attachment-list a { color: var(--brand-2); font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 32px 10px; }

dialog { width: min(620px, calc(100% - 30px)); border: 0; border-radius: 22px; padding: 0; box-shadow: 0 30px 100px rgba(8,32,25,.3); }
dialog::backdrop { background: rgba(15,35,29,.55); backdrop-filter: blur(3px); }
.dialog-form { padding: 0 22px 22px; }
.dialog-heading { margin: 0 -22px 20px; padding: 20px 22px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 3px 0 0; }
.close-dialog { border: 0; background: transparent; color: var(--muted); font-size: 25px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.dialog-form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 750; margin-bottom: 13px; }
.dialog-form input, .dialog-form select, .dialog-form textarea { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 10px 11px; color: var(--ink); background: white; }
.field-label { display: block; color: var(--muted); font-size: 12px; font-weight: 750; margin-bottom: 6px; }
.horse-photo-field { margin-bottom: 13px; }
.horse-photo-picker {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 94px;
    padding: 12px;
    border: 1px dashed #b9cdc5;
    border-radius: 14px;
    background: #f7faf8;
}
.horse-photo-preview {
    width: 74px;
    height: 74px;
    flex: 0 0 74px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid #d5e1dc;
    border-radius: 16px;
    color: var(--muted);
    background: #eaf2ee;
    text-align: center;
    font-size: 10px;
    font-weight: 750;
}
.horse-photo-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.horse-photo-controls { min-width: 0; display: flex; align-items: flex-start; flex-direction: column; gap: 5px; }
.dialog-form .horse-photo-button {
    display: inline-flex;
    width: auto;
    align-items: center;
    justify-content: center;
    margin: 0 0 2px;
    padding: 9px 13px;
    color: var(--brand);
    cursor: pointer;
}
.horse-photo-controls strong {
    max-width: 100%;
    overflow: hidden;
    color: var(--ink);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.horse-photo-controls small { color: var(--muted); font-size: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast { position: fixed; right: 24px; bottom: 24px; max-width: 360px; background: var(--ink); color: white; padding: 13px 16px; border-radius: 12px; box-shadow: var(--shadow); transform: translateY(120px); opacity: 0; transition: .25s; z-index: 50; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
    .topbar { height: auto; min-height: 76px; flex-wrap: wrap; gap: 10px; padding-top: 9px; padding-bottom: 9px; }
    .horse-switcher { order: 3; width: 100%; }
    .metrics { grid-template-columns: 1fr 1fr; }
    .workspace { grid-template-columns: 1fr; }
    .alerts-panel { min-height: auto; }
    .alerts-list { max-height: 330px; }
}

@media (max-width: 640px) {
    .topbar { padding: 0 16px; }
    .system-state > span:not(.state-dot), .system-state a { display: none; }
    .page-shell { width: min(100% - 24px, 1240px); padding-top: 24px; }
    .hero { grid-template-columns: 1fr; justify-items: center; gap: 18px; }
    .hero-balance { display: none; }
    .hero-horse-photo { width: 112px; height: 112px; margin-bottom: 11px; font-size: 39px; }
    .hero-actions { width: 100%; }
    .hero-actions button { flex: 1; }
    .hero h1 { font-size: 36px; }
    .metrics { gap: 8px; }
    .metric { padding: 14px; border-radius: 15px; }
    .metric strong { font-size: 25px; }
    .panel { border-radius: 18px; }
    .chat-panel {
        height: min(680px, calc(100dvh - 90px));
        min-height: 500px;
    }
    .messages { padding: 18px; }
    .message { max-width: 94%; }
    .message.has-chart { width: 100%; max-width: 100%; }
    .chat-chart { padding: 11px 9px; }
    .chat-chart-area { height: 300px; }
    .timeline-heading { align-items: stretch; flex-direction: column; }
    .filters { flex-direction: column; width: 100%; }
    .event-card { grid-template-columns: 54px 1fr; }
    .event-actions { grid-column: 2; }
    .alert-heading-actions { flex-direction: column; align-items: flex-end; }
    .chat-heading-actions { flex-direction: column; align-items: flex-end; gap: 2px; }
    .speech-settings { flex-wrap: wrap; justify-content: flex-end; max-width: 230px; }
    .speech-voice-control { order: 3; width: 100%; }
    .speech-voice-control select { width: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .wide { grid-column: auto; }
    .horse-photo-picker { align-items: flex-start; }
}
