/* === Boi Gordo IA — PWA Mobile-First === */

/* RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a1a;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: 68px;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

/* === HEADER === */
.app-header {
    background: linear-gradient(135deg, #2d7a3a, #1a5c28);
    color: white;
    display: flex;
    align-items: center;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    gap: 12px;
    min-height: 56px;
}
.header-left { flex-shrink: 0; }
.header-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 1px;
}
.header-center { flex: 1; min-width: 0; }
.header-title { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.3px; }
.header-subtitle { font-size: 0.75rem; opacity: 0.8; margin-top: 1px; }
.header-right { flex-shrink: 0; }
.header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* === TOAST === */
.toast {
    position: fixed;
    top: calc(70px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 999;
    text-align: center;
    max-width: 90%;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    transition: opacity 0.3s, transform 0.3s;
    backdrop-filter: blur(8px);
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(-10px); }
.toast.success { background: rgba(40,167,69,0.95); color: white; }
.toast.error { background: rgba(220,53,69,0.95); color: white; }
.toast.info { background: rgba(0,123,255,0.95); color: white; }

/* === TABS === */
.tab-content { display: none; animation: fadeIn 0.2s ease; }
.tab-content.active { display: flex; flex-direction: column; }
@keyframes fadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }

/* === TAB HEADER BAR === */
.tab-header-bar {
    display: flex;
    align-items: center;
    padding: 16px;
    gap: 12px;
}
.tab-title-inline { font-size: 1.3rem; font-weight: 800; color: #1a1a1a; flex: 1; }
.btn-icon-accent {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #2d7a3a;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(45,122,58,0.3);
    transition: transform 0.1s;
}
.btn-icon-accent:active { transform: scale(0.92); }
.btn-back {
    background: none;
    border: none;
    color: #2d7a3a;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* === FILTER CHIPS === */
.filter-chips { display: flex; gap: 8px; padding: 0 16px 12px; overflow-x: auto; }
.chip {
    padding: 6px 16px;
    border-radius: 20px;
    border: 1.5px solid #ddd;
    background: white;
    color: #666;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.chip.active { background: #2d7a3a; color: white; border-color: #2d7a3a; }
.chip:active { transform: scale(0.95); }

/* === REBANHO STATS === */
.rebanho-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 0 16px 12px;
}
.stat-card {
    background: white;
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.stat-value { font-size: 1.4rem; font-weight: 800; color: #2d7a3a; }
.stat-label { font-size: 0.7rem; color: #888; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

/* === ANIMAL LIST === */
.animal-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px 16px; }

.loading-skeleton { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
.skel-card { height: 72px; background: linear-gradient(90deg, #e8e8e8 25%, #f0f0f0 50%, #e8e8e8 75%); background-size: 200%; border-radius: 14px; animation: shimmer 1.5s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.empty-state { text-align: center; padding: 48px 24px; color: #888; }
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 0.95rem; line-height: 1.5; }

/* Animal card */
.animal-card {
    background: white;
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.06);
    border-left: 5px solid #aaa;
    cursor: pointer;
    transition: transform 0.1s;
    display: flex;
    align-items: center;
    gap: 12px;
}
.animal-card:active { transform: scale(0.98); }
.animal-card.status-bom { border-left-color: #28a745; }
.animal-card.status-atencao { border-left-color: #ffc107; }
.animal-card.status-critico { border-left-color: #dc3545; }
.animal-card.status-novo { border-left-color: #6c757d; }
.card-icon { font-size: 2rem; flex-shrink: 0; }
.card-info { flex: 1; min-width: 0; }
.card-id { font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-details { font-size: 0.8rem; color: #666; margin-top: 2px; }
.card-gmd { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; margin-top: 4px; }
.gmd-bom { background: #d4edda; color: #155724; }
.gmd-atencao { background: #fff3cd; color: #856404; }
.gmd-critico { background: #f8d7da; color: #721c24; }
.gmd-sem-dado { background: #e9ecef; color: #6c757d; }
.card-arrow { color: #ccc; font-size: 1.2rem; flex-shrink: 0; }

/* === CHAT STYLES (WhatsApp-like) === */
#tab-chat {
    height: calc(100vh - 56px - 68px);
    height: calc(100dvh - 56px - 68px);
    padding: 0;
    position: relative;
    background: #e5ddd5;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='a' patternUnits='userSpaceOnUse' width='60' height='60'%3E%3Ccircle cx='10' cy='10' r='1' fill='%23c9c2b6' opacity='.15'/%3E%3Ccircle cx='40' cy='30' r='1' fill='%23c9c2b6' opacity='.1'/%3E%3Ccircle cx='20' cy='50' r='1' fill='%23c9c2b6' opacity='.12'/%3E%3C/pattern%3E%3C/defs%3E%3Crect fill='url(%23a)' width='60' height='60'/%3E%3C/svg%3E");
}

/* Scroll area for messages */
.chat-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Welcome screen */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    flex: 1;
    min-height: 60vh;
}
.cw-avatar {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, #2d7a3a, #1a5c28);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    box-shadow: 0 4px 16px rgba(45,122,58,0.3);
}
.cw-title { font-size: 1.4rem; font-weight: 800; color: #1a1a1a; margin-bottom: 8px; }
.cw-desc { font-size: 0.9rem; color: #666; line-height: 1.5; max-width: 300px; margin-bottom: 24px; }

.cw-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 320px; }
.cw-chip {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1.5px solid #2d7a3a;
    background: rgba(255,255,255,0.9);
    color: #2d7a3a;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.cw-chip:active { background: #2d7a3a; color: white; transform: scale(0.95); }

/* Chat bubbles */
.chat-bubble {
    max-width: 82%;
    padding: 8px 12px;
    font-size: 0.95rem;
    line-height: 1.5;
    animation: bubbleIn 0.2s ease;
    word-break: break-word;
    white-space: pre-wrap;
    position: relative;
}
@keyframes bubbleIn { from { opacity:0; transform: translateY(6px) scale(0.97); } to { opacity:1; transform: translateY(0) scale(1); } }

/* User bubble (right, green) — WhatsApp tail */
.bubble-user {
    align-self: flex-end;
    background: #dcf8c6;
    color: #1a1a1a;
    border-radius: 12px 12px 4px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    margin-right: 4px;
}
.bubble-user::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -6px;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-left-color: #dcf8c6;
    border-bottom-color: #dcf8c6;
    border-bottom-right-radius: 4px;
}

/* AI bubble (left, white) — WhatsApp tail */
.bubble-ai {
    align-self: flex-start;
    background: white;
    color: #1a1a1a;
    border-radius: 12px 12px 12px 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    margin-left: 4px;
}
.bubble-ai::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -6px;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-right-color: white;
    border-bottom-color: white;
    border-bottom-left-radius: 4px;
}
.bubble-ai strong, .bubble-ai b { color: #2d7a3a; }

/* Timestamp + check */
.bubble-time {
    font-size: 0.65rem;
    color: #999;
    text-align: right;
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}
.bubble-user .bubble-time::after {
    content: '✓✓';
    font-size: 0.6rem;
    color: #53bdeb;
}

/* Chart & Table inside bubbles */
.bubble-chart-wrap {
    margin: 10px -4px 6px;
    background: #fafafa;
    border-radius: 10px;
    padding: 8px;
    position: relative;
    height: 200px;
}
.bubble-chart {
    width: 100% !important;
    height: 100% !important;
}

.bubble-table-wrap {
    margin: 8px -4px 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.bubble-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    background: #fafafa;
    border-radius: 8px;
    overflow: hidden;
}
.bubble-table th {
    background: #2d7a3a;
    color: white;
    font-weight: 700;
    padding: 6px 10px;
    text-align: left;
    white-space: nowrap;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.bubble-table td {
    padding: 5px 10px;
    border-bottom: 1px solid #e8e8e8;
    white-space: nowrap;
    color: #333;
}
.bubble-table tr:last-child td { border-bottom: none; }
.bubble-table tr:nth-child(even) { background: #f4f4f4; }
.bubble-table td:first-child { font-weight: 600; }

/* Widen AI bubbles that contain charts/tables */
.bubble-ai:has(.bubble-chart-wrap),
.bubble-ai:has(.bubble-table-wrap) {
    max-width: 95%;
}

/* Bubble footer (time + TTS button) */
.bubble-footer {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    margin-top: 4px;
}
.bubble-footer .bubble-time {
    margin-top: 0;
}

/* TTS play button on AI bubbles */
.tts-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(45,122,58,0.1);
    color: #2d7a3a;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
    padding: 0;
}
.tts-btn:active { transform: scale(0.9); }
.tts-btn.playing { background: #2d7a3a; color: white; }
.tts-btn.loading { opacity: 0.6; pointer-events: none; }

.tts-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(45,122,58,0.3);
    border-top-color: #2d7a3a;
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.6s linear infinite;
}

/* TTS toggle button in header */
#ttsToggle.off { opacity: 0.4; }
#ttsToggle.off svg { opacity: 0.5; }

/* Typing indicator */
.typing-indicator {
    align-self: flex-start;
    background: white;
    border-radius: 12px 12px 12px 4px;
    padding: 12px 16px;
    display: flex;
    gap: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    margin-left: 4px;
}
.typing-dot {
    width: 8px;
    height: 8px;
    background: #2d7a3a;
    border-radius: 50%;
    animation: typingBounce 1.2s infinite;
    opacity: 0.4;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Chat input bar — fixed at bottom of chat area */
.chat-bar {
    background: #f0f0f0;
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}
.chat-bar-inner {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: white;
    border-radius: 24px;
    padding: 4px 6px 4px 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.chat-bar-inner textarea {
    flex: 1;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.4;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 8px 0;
    background: transparent;
    color: #1a1a1a;
}
.chat-bar-inner textarea::placeholder { color: #999; }
.chat-bar-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #ccc;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.1s, background 0.15s;
}
.chat-bar-send:not(:disabled) { background: #2d7a3a; }
.chat-bar-send:not(:disabled):active { transform: scale(0.9); background: #1a5c28; }
.chat-bar-send:disabled { opacity: 0.6; cursor: default; }

/* Mic button */
.chat-bar-mic {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #2d7a3a;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.1s, background 0.15s;
}
.chat-bar-mic:active { transform: scale(0.9); }
.chat-bar-mic.hidden { display: none; }
.chat-bar-mic.recording {
    background: #dc3545;
    animation: micPulse 1s ease-in-out infinite;
}
@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220,53,69,0.5); }
    50% { box-shadow: 0 0 0 10px rgba(220,53,69,0); }
}

/* === BOTTOM NAV === */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    display: flex;
    justify-content: space-around;
    padding: 4px 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -1px 12px rgba(0,0,0,0.08);
    z-index: 100;
    border-top: 1px solid #e8e8e8;
}
.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    padding: 6px 16px;
    cursor: pointer;
    border-radius: 8px;
    min-width: 64px;
    transition: all 0.15s;
    position: relative;
}
.nav-btn:active { transform: scale(0.92); }
.nav-icon-svg { stroke: #888; transition: stroke 0.15s; }
.nav-label { font-size: 0.65rem; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.3px; transition: color 0.15s; }
.nav-btn.active .nav-icon-svg { stroke: #2d7a3a; }
.nav-btn.active .nav-label { color: #2d7a3a; }
.nav-btn.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: #2d7a3a;
    border-radius: 0 0 3px 3px;
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    font-size: 1rem;
    padding: 14px 20px;
    min-height: 50px;
    transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: #2d7a3a; color: white; }
.btn-primary:active { background: #1a5c28; }
.btn-full { width: 100%; }
.btn.loading-btn { pointer-events: none; opacity: 0.7; }

/* === FORMS === */
.form-group { margin-bottom: 14px; padding: 0 16px; }
.form-group label { display: block; font-weight: 700; font-size: 0.8rem; color: #555; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.input-field {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    background: white;
    color: #1a1a1a;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color 0.2s;
}
.input-field:focus { outline: none; border-color: #2d7a3a; box-shadow: 0 0 0 3px rgba(45,122,58,0.12); }
select.input-field {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23555' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

/* === MODAL === */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden { display: none; }
.modal-content {
    background: white;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    border-radius: 20px 20px 0 0;
    padding: 20px 16px;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.25s ease;
    -webkit-overflow-scrolling: touch;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-close {
    position: absolute; top: 12px; right: 16px;
    background: #f0f0f0; border: none; width: 36px; height: 36px;
    border-radius: 50%; font-size: 1.2rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center; color: #666; z-index: 10;
}
.modal-close:active { background: #ddd; }

/* Modal sections */
.modal-header { text-align: center; margin-bottom: 16px; padding-right: 40px; }
.modal-animal-id { font-size: 1.3rem; font-weight: 800; }
.modal-status-badge { display: inline-block; padding: 4px 14px; border-radius: 20px; font-size: 0.8rem; font-weight: 700; margin-top: 6px; }
.modal-section { margin-bottom: 16px; }
.modal-section-title { font-size: 0.8rem; font-weight: 700; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; padding-bottom: 4px; border-bottom: 1px solid #eee; }
.info-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 0.9rem; }
.info-label { color: #666; }
.info-value { font-weight: 700; }

/* Tips */
.tip-card { background: #f8f9fa; border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; border-left: 4px solid #007bff; }
.tip-card.tip-warning { border-left-color: #ffc107; background: #fffde7; }
.tip-card.tip-danger { border-left-color: #dc3545; background: #fff5f5; }
.tip-card.tip-success { border-left-color: #28a745; background: #f0fff0; }
.tip-text { font-size: 0.85rem; line-height: 1.5; color: #333; }

/* Feed item */
.feed-item { display: flex; justify-content: space-between; padding: 5px 0; font-size: 0.85rem; border-bottom: 1px solid #f0f0f0; }
.feed-item:last-child { border-bottom: none; }

/* Formula ativa in modal */
.formula-ativa-section { background: #e8f5e9; border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.formula-ativa-section h4 { font-size: 0.85rem; font-weight: 700; color: #2d7a3a; margin-bottom: 6px; }
.formula-ativa-ing { display: flex; justify-content: space-between; padding: 3px 0; font-size: 0.8rem; border-bottom: 1px solid rgba(0,0,0,0.06); }
.formula-ativa-ing:last-child { border-bottom: none; }

/* Avaliacao */
.avaliacao-section { border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.avaliacao-section.avaliacao-melhorou { background: #e8f5e9; border: 2px solid #4caf50; }
.avaliacao-section.avaliacao-estavel { background: #fff3cd; border: 2px solid #ffc107; }
.avaliacao-section.avaliacao-piorou { background: #f8d7da; border: 2px solid #dc3545; }
.avaliacao-section.avaliacao-insuficiente { background: #e9ecef; border: 2px solid #6c757d; }
.avaliacao-section h4 { font-size: 0.85rem; font-weight: 700; margin-bottom: 4px; }
.avaliacao-text { font-size: 0.85rem; line-height: 1.5; }
.avaliacao-rec { font-size: 0.8rem; font-weight: 600; margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(0,0,0,0.1); }

/* Formula CTA button in modal */
.btn-recalcular { background: #e3f2fd; color: #1565c0; border: 2px solid #1565c0; width: 100%; margin-top: 8px; }
.btn-recalcular:active { background: #bbdefb; }

/* === FINANCEIRO === */
.fin-cards { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 0 16px 16px; }
.fin-card {
    border-radius: 14px;
    padding: 14px 12px;
    text-align: center;
}
.fin-receita { background: #e8f5e9; }
.fin-despesa { background: #fce4ec; }
.fin-saldo { background: #e3f2fd; }
.fin-card-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #666; }
.fin-card-value { font-size: 1.1rem; font-weight: 800; margin-top: 4px; color: #1a1a1a; }

.fin-form { padding: 0 16px 16px; }
.fin-form.hidden { display: none; }
.fin-form-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.fin-toggle-btn {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    border: 2px solid #ddd;
    background: white;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}
.fin-toggle-btn.active { border-color: #2d7a3a; background: #e8f5e9; color: #2d7a3a; }
.fin-toggle-btn:active { transform: scale(0.97); }

/* Resultado por lote */
.fin-resultado { padding: 0 16px 8px; }
.fin-resultado-card {
    background: linear-gradient(135deg, #1565c0, #0d47a1);
    border-radius: 14px;
    padding: 16px;
    color: white;
}
.fin-resultado-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
    margin-bottom: 10px;
}
.fin-resultado-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.fin-resultado-item { }
.fin-resultado-label { font-size: 0.7rem; opacity: 0.7; }
.fin-resultado-value { font-size: 1.1rem; font-weight: 800; }

.fin-list { padding: 0 16px; }
.fin-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: white;
    border-radius: 12px;
    margin-bottom: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.fin-item-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.fin-item-icon.despesa { background: #fce4ec; }
.fin-item-icon.receita { background: #e8f5e9; }
.fin-item-info { flex: 1; min-width: 0; }
.fin-item-desc { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fin-item-date { font-size: 0.75rem; color: #888; margin-top: 2px; }
.fin-item-valor { font-size: 1rem; font-weight: 800; flex-shrink: 0; }
.fin-item-valor.despesa { color: #dc3545; }
.fin-item-valor.receita { color: #28a745; }

/* === FINANCEIRO CATEGORIES === */
.fin-categorias {
    background: white;
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.fin-cat-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
}
.fin-cat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid #f5f5f5;
}
.fin-cat-row:last-child { border-bottom: none; }
.fin-cat-name { color: #444; text-transform: capitalize; flex: 1; }
.fin-cat-val { font-weight: 700; margin-left: 8px; font-size: 0.8rem; }
.fin-cat-val.despesa { color: #dc3545; }
.fin-cat-val.receita { color: #28a745; }

/* === SANIDADE === */
.sanidade-calendario {
    margin: 0 16px 16px;
    background: linear-gradient(135deg, #1565c0, #0d47a1);
    border-radius: 14px;
    padding: 16px;
    color: white;
}
.calendario-header { font-size: 1rem; font-weight: 700; margin-bottom: 8px; }
.calendario-tip { font-size: 0.85rem; line-height: 1.5; opacity: 0.9; }

.sanidade-form { padding: 0 16px 16px; }
.sanidade-form.hidden { display: none; }

.sanidade-alertas { padding: 0 16px; }
.sanidade-historico { padding: 0 16px 16px; }
.sanidade-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 16px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid #eee;
}

.alerta-card {
    background: white;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 8px;
    border-left: 4px solid #ffc107;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.alerta-card.critico { border-left-color: #dc3545; }
.alerta-card-titulo { font-size: 0.9rem; font-weight: 700; color: #1a1a1a; margin-bottom: 4px; }
.alerta-card-texto { font-size: 0.8rem; color: #555; line-height: 1.4; }
.alerta-card-animal { font-size: 0.75rem; color: #2d7a3a; font-weight: 600; margin-top: 4px; }

/* === LOADING === */
.loading { text-align: center; color: #888; padding: 32px 16px; font-size: 0.9rem; }

/* Spinner for buttons */
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,0.3); border-top-color: white; border-radius: 50%; animation: spin 0.6s linear infinite; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === iOS safe areas === */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
    #tab-chat { height: calc(100dvh - 56px - 68px - env(safe-area-inset-bottom)); }
    .chat-bar { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}

/* iOS keyboard open — shrink chat to fit */
@media (max-height: 500px) {
    #tab-chat { height: calc(100dvh - 56px); }
    .bottom-nav { display: none; }
    .chat-welcome { min-height: auto; padding: 20px 16px; }
}

