/* Animals page – Farm Manager brand palette */

:root {
    --fm-green-dark: #234f2e;
    --fm-green: #2f6b2f;
    --fm-text: #1f2520;
    --fm-muted: #566052;
    --fm-page-bg: #eef1e6;
    --fm-green-soft: #e6efe2;
    --fm-surface: #ffffff;
    --fm-surface-soft: #f8f9f4;
    --fm-border: #cfd8c6;
    --fm-amber: #d99a24;
    --fm-alert: #b42318;
}

body {
    background: var(--fm-page-bg);
    background-image: none;
    color: var(--fm-text);
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

body::before {
    display: none;
}

@supports (padding: max(0px)) {
    body {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
    }
}

#app-content {
    padding-left: 0;
    padding-right: 0;
    padding-top: 0.75rem;
}

.animals-container {
    display: flex;
    flex-direction: column;
    gap: 2.25rem;
    width: min(calc(100% - 1.5rem), 1440px);
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.25rem 0 7.5rem;
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100vh;
    box-sizing: border-box;
}

.animals-container > * {
    box-sizing: border-box;
}

.animals-container .content-container {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    background: transparent;
    margin: 0;
    padding: 0;
    box-shadow: none;
    border-radius: 0;
}

.animals-page-hero,
.quick-actions,
.animals-workspace,
.inventory-collapsible,
.animal-actions,
.animals-activity-grid,
.management-actions {
    width: 100%;
}

.app-page-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.animals-page-hero {
    display: grid;
    grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
    gap: 2rem;
    align-items: center;
    background: linear-gradient(135deg, #ffffff 0%, #e6efe2 100%);
    border: 1px solid var(--fm-border);
    border-radius: 24px;
    padding: 1.6rem 2rem;
    box-shadow: 0 14px 30px rgba(31, 37, 32, 0.08);
}

.animals-page-hero__brand {
    display: flex;
    align-items: center;
    justify-content: center;
}

.animals-page-hero__copy {
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: left;
}

.brand-logo--app-page {
    display: block;
    max-width: 220px;
    width: 100%;
    height: auto;
    object-fit: contain;
}

.page-kicker {
    margin: 0 0 0.35rem;
    color: var(--fm-green);
    font-size: 0.78rem;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

.animals-page-title {
    margin: 0;
    padding-bottom: 0;
    color: var(--fm-green-dark);
    font-size: clamp(2.4rem, 5vw, 4rem);
    font-weight: 900;
    letter-spacing: -0.055em;
    line-height: 0.95;
    text-align: left;
    text-shadow: none;
    text-transform: none;
    display: block;
}

.animals-page-title::after {
    display: none;
}

.page-subtitle {
    margin: 0.75rem 0 0;
    color: var(--fm-muted);
    font-size: clamp(0.98rem, 1.5vw, 1.08rem);
    line-height: 1.5;
    font-weight: 400;
    max-width: 720px;
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 1rem;
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
}

.quick-actions .action-button {
    min-height: 52px;
    font-size: 1rem;
}

.animals-workspace {
    display: flex;
    flex-direction: column;
    gap: 2.25rem;
}

.stat-card,
.inventory-collapsible {
    background: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 20px;
    box-shadow: 0 10px 24px rgba(31, 37, 32, 0.07);
    overflow: hidden;
    margin-bottom: 0;
}

.inventory-collapsible.stat-card {
    padding: 0;
}

.stat-card:not(.inventory-collapsible) {
    padding: 1.25rem;
}

.stat-card h3 {
    margin: 0 0 1.1rem;
    color: var(--fm-green-dark);
    font-weight: 850;
    font-size: 1.15rem;
    text-shadow: none;
    text-transform: none;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

.stat-card h3::after {
    display: none;
}

.inventory-collapsible {
    list-style: none;
    width: 100%;
}

.inventory-collapsible-summary {
    list-style: none;
    cursor: pointer;
    font-size: 1.05rem;
    font-weight: 850;
    color: var(--fm-green-dark);
    padding: 1.15rem 1.4rem;
    margin: 0;
    border-bottom: 1px solid var(--fm-border);
}

.inventory-collapsible-summary::-webkit-details-marker {
    display: none;
}

.inventory-collapsible-summary::before {
    content: '▸ ';
    display: inline-block;
    width: 1em;
    transition: transform 0.15s ease;
}

.inventory-collapsible[open] .inventory-collapsible-summary::before {
    transform: rotate(90deg);
}

.inventory-collapsible-body {
    margin-top: 0;
    padding: 1.4rem;
}

.stat-number,
#total-animals.stat-number {
    color: var(--fm-green-dark);
    font-weight: 900;
    font-size: clamp(2.3rem, 5vw, 3.4rem);
    margin-bottom: 1.25rem;
    line-height: 1;
}

#inventory-breakdown {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

#inventory-breakdown > p {
    grid-column: 1 / -1;
    margin: 0;
}

.animals-activity-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
    gap: 1.5rem;
    align-items: start;
}

.animals-activity-grid .stat-card {
    margin-bottom: 0;
    padding: 1.35rem;
}

.action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 50px;
    border-radius: 999px;
    padding: 0.85rem 1.15rem;
    line-height: 1.2;
    white-space: normal;
    font-weight: 850;
    letter-spacing: -0.01em;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, border-color 160ms ease;
    text-transform: none;
    box-shadow: none;
}

.action-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(31, 37, 32, 0.10);
}

.btn-success,
.btn-primary {
    background: var(--fm-green-dark);
    color: #ffffff;
    border-color: var(--fm-green-dark);
}

.btn-success:hover,
.btn-primary:hover {
    background: var(--fm-green);
    border-color: var(--fm-green);
}

.btn-secondary {
    background: var(--fm-surface);
    color: var(--fm-green-dark);
    border-color: var(--fm-border);
}

.btn-secondary:hover {
    background: var(--fm-green-soft);
    border-color: var(--fm-green);
}

.btn-warning {
    background: var(--fm-surface-soft);
    color: #7a5200;
    border-color: rgba(217, 154, 36, 0.45);
}

.btn-warning:hover {
    background: #e9eddf;
}

.btn-danger {
    background: var(--fm-surface);
    color: var(--fm-alert);
    border-color: rgba(180, 35, 24, 0.35);
}

.btn-danger:hover {
    background: var(--fm-surface);
    border-color: var(--fm-alert);
}

.animal-actions,
.button-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1rem;
    width: 100%;
    background: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 20px;
    padding: 1rem;
    box-shadow: 0 10px 24px rgba(31, 37, 32, 0.06);
    margin-bottom: 0;
}

.animal-actions .action-button {
    min-height: 54px;
    padding: 0.9rem 1rem;
    background: var(--fm-surface);
    color: var(--fm-green-dark);
    border: 1px solid var(--fm-border);
}

.animal-actions .action-button:hover {
    background: var(--fm-green-soft);
    border-color: var(--fm-green);
}

.management-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    background: transparent;
    border: 1px dashed var(--fm-border);
    border-radius: 18px;
    padding: 1rem;
}

.management-actions::before {
    content: none !important;
}

.management-actions .action-button {
    min-height: 48px;
}

.management-actions .btn-warning {
    background: var(--fm-surface);
    color: #7a5200;
    border-color: rgba(217, 154, 36, 0.45);
}

.management-actions .btn-danger {
    background: var(--fm-surface);
    color: var(--fm-alert);
    border-color: rgba(180, 35, 24, 0.35);
}

.danger-btn {
    background-color: var(--fm-alert) !important;
    color: #ffffff !important;
    border: 1px solid var(--fm-alert) !important;
}

.form-actions .save-btn.danger-btn {
    background-color: var(--fm-alert) !important;
    color: #ffffff !important;
    border: 1px solid var(--fm-alert) !important;
    text-transform: none;
    font-weight: 700;
}

.inventory-item {
    display: flex;
    flex-direction: column;
    background: var(--fm-surface-soft);
    border: 1px solid var(--fm-border);
    border-radius: 16px;
    padding: 1.05rem 1.1rem;
    margin: 0;
}

.inventory-item:last-child {
    border-bottom: 1px solid var(--fm-border);
}

.inventory-item .category {
    font-weight: 800;
    color: var(--fm-text);
}

.inventory-item .count {
    font-weight: 900;
    color: var(--fm-green-dark);
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-size: 1.25rem;
}

.inventory-item .main-info {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    width: 100%;
}

.location-breakdown {
    margin-top: 0.45rem;
    margin-left: 0;
    font-size: 0.9rem;
    color: var(--fm-muted);
}

.location-item {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.location-name {
    margin-right: 10px;
}

.location-count {
    font-weight: 500;
}

.transaction-item {
    background: var(--fm-surface-soft);
    border: 1px solid var(--fm-border);
    border-radius: 16px;
    padding: 1rem 1.1rem;
    margin-bottom: 0.9rem;
    border-left: 4px solid var(--fm-border);
}

.transaction-item:last-child {
    margin-bottom: 0;
}

.transaction-item.add {
    border-left-color: var(--fm-green);
}

.transaction-item.sell {
    border-left-color: var(--fm-alert);
}

.transaction-item.buy {
    border-left-color: var(--fm-green-dark);
}

.transaction-item.move {
    border-left-color: var(--fm-amber);
}

.transaction-item.death {
    border-left-color: var(--fm-muted);
}

.transaction-item.birth {
    border-left-color: var(--fm-green);
}

.transaction-details {
    display: grid;
    gap: 0.25rem;
}

.transaction-date {
    color: var(--fm-muted);
    font-size: 0.85rem;
    font-weight: 700;
}

.transaction-category {
    font-weight: 800;
    color: var(--fm-green-dark);
}

.transaction-description {
    margin-top: 0;
    color: var(--fm-text);
}

.transaction-price,
.transaction-total {
    font-weight: 700;
    color: var(--fm-muted);
    font-size: 0.9rem;
}

.transaction-total.income {
    color: var(--fm-green);
}

.transaction-total.expense {
    color: var(--fm-alert);
}

/* Popup Styles */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    overflow: hidden;
}

.popup-content {
    background-color: var(--fm-surface);
    border: 1px solid var(--fm-border);
    padding: 20px;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 14px 30px rgba(31, 37, 32, 0.12);
    position: relative;
    margin: auto;
}

.popup-content h3 {
    margin-top: 0;
    color: var(--fm-green-dark);
    font-weight: 800;
    margin-bottom: 20px;
    text-align: center;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 700;
    color: var(--fm-text);
}

/* Make all inputs more touch-friendly */
input, select, textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    font-size: 16px; /* Prevents iOS zoom on focus */
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #ddd;
    background-color: #fff; /* Ensure white background for better visibility */
}

/* Fix for iOS input field focus issues */
input[type="text"], 
input[type="number"], 
textarea {
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    -webkit-user-select: text;
    user-select: text;
    touch-action: manipulation;
}

/* Specific styles for new category input field */
.new-category-input input {
    border: 2px solid var(--fm-green-dark);
    background-color: var(--fm-green-soft);
    box-shadow: 0 0 5px rgba(35, 79, 46, 0.15);
}

/* Override for iOS devices */
input[type="date"] {
    min-height: 44px; /* Better touch target */
}

/* Remove spinner buttons from number inputs */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Firefox */
input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Enhanced form styling */
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    margin-top: 4px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--fm-green-dark);
    outline: none;
    box-shadow: 0 0 0 3px rgba(35, 79, 46, 0.15);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.cancel-btn {
    background-color: var(--fm-surface);
    color: var(--fm-muted);
    border: 1px solid var(--fm-border);
    padding: 10px 15px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 700;
}

.save-btn {
    background-color: var(--fm-green-dark);
    color: #ffffff;
    border: 1px solid var(--fm-green-dark);
    padding: 10px 15px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 700;
}

.save-btn:hover {
    background-color: var(--fm-green);
    border-color: var(--fm-green);
}

/* Empty states */
.empty-state {
    text-align: center;
    color: var(--fm-muted);
    padding: 20px 0;
}

/* Landscape orientation adjustments */
@media (orientation: landscape) {
    .popup-content {
        width: 80%;
        max-height: 80vh;
        display: flex;
        flex-direction: column;
    }
    
    .popup-content form {
        overflow-y: auto;
        max-height: calc(80vh - 80px);
        padding-right: 10px;
    }
    
    .form-actions {
        position: sticky;
        bottom: 0;
        background-color: white;
        padding-top: 10px;
        margin-top: 10px;
        border-top: 1px solid #eee;
    }
}

/* For smaller screens in landscape mode */
@media (orientation: landscape) and (max-height: 500px) {
    .popup-content {
        width: 90%;
        max-height: 90vh;
    }
    
    .popup-content h3 {
        margin-top: 0;
        margin-bottom: 10px;
        font-size: 1.1rem;
    }
    
    .form-group {
        margin-bottom: 10px;
    }
    
    .form-group label {
        margin-bottom: 3px;
        font-size: 0.9rem;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 8px;
        font-size: 0.9rem;
    }
}

/* Stock count styling */
.count-field-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.count-field-group .expected-count {
    font-size: 0.9em;
    color: #666;
}

.count-field-group.count-match {
    background-color: rgba(0, 255, 0, 0.1);
    border-radius: 4px;
}

.count-field-group.count-higher {
    background-color: rgba(255, 165, 0, 0.1);
    border-radius: 4px;
}

.count-field-group.count-lower {
    background-color: rgba(255, 0, 0, 0.1);
    border-radius: 4px;
}

.instructions {
    margin-bottom: 15px;
    font-size: 0.9em;
    color: #555;
}

/* Enhance popup styling */
.popup-content form {
    max-height: 80vh;
    overflow-y: auto;
    padding-right: 5px;
}

/* Better text wrapping for all areas */
.transaction-item, .inventory-item, .animal-actions button {
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
}

/* Improve portrait mode specifically */
@media (max-width: 480px) and (orientation: portrait) {
    .inventory-item {
        flex-wrap: wrap;
    }

    .inventory-item .category {
        width: 100%;
        margin-bottom: 4px;
    }

    .popup {
        align-items: center;
        justify-content: center;
    }

    .popup-content {
        width: 95%;
        max-width: 95%;
        padding: 15px;
        margin: auto;
        position: relative;
        top: 0;
        transform: none;
    }
}

/* No categories message */
.no-categories-message {
    text-align: center;
    padding: 20px;
    background-color: var(--fm-surface-soft);
    border-radius: 16px;
    margin: 10px 0;
    border: 1px dashed var(--fm-border);
}

.no-categories-message p {
    margin-bottom: 10px;
    color: var(--fm-text);
    font-size: 1.1rem;
}

.no-categories-message p:last-child {
    font-weight: 700;
    color: var(--fm-green-dark);
    font-size: 1rem;
}

/* Recent Counts styling */
.count-item {
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--fm-surface-soft);
    border: 1px solid var(--fm-border);
    border-radius: 16px;
    padding: 1rem 1.1rem;
    margin-bottom: 0.9rem;
}

.count-item:last-child {
    margin-bottom: 0;
}

.count-item.resolution {
    background-color: var(--fm-green-soft);
    border-left: 4px solid var(--fm-green);
}

.count-date {
    color: var(--fm-muted);
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.count-category {
    font-weight: 800;
    color: var(--fm-green-dark);
    margin-bottom: 4px;
}

.count-details {
    margin-top: 0.25rem;
    color: var(--fm-text);
}

.count-notes {
    margin-top: 8px;
    font-style: italic;
    color: var(--fm-muted);
    font-size: 0.9em;
    border-top: 1px dotted var(--fm-border);
    padding-top: 6px;
}

.count-details .diff {
    font-weight: 800;
}

.count-details .diff.match {
    color: var(--fm-green);
}

.count-details .diff.surplus {
    color: var(--fm-green-dark);
}

.count-details .diff.shortage {
    color: var(--fm-alert);
}

.resolution-text {
    color: var(--fm-green);
    font-weight: 700;
    display: block;
}

.final-count {
    color: var(--fm-text);
    display: block;
    margin-top: 2px;
}

.resolved-badge {
    display: inline-block;
    background-color: var(--fm-green);
    color: #ffffff;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 0.8em;
    margin-left: 8px;
    font-weight: 700;
    vertical-align: middle;
}

.discrepancy-item {
    background-color: var(--fm-surface);
    border: 1px solid var(--fm-border);
    border-radius: 16px;
    margin-bottom: 10px;
    padding: 10px;
}

.discrepancy-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.discrepancy-category {
    font-weight: 800;
    font-size: 1.1em;
    color: var(--fm-green-dark);
}

.discrepancy-date {
    color: var(--fm-muted);
    font-size: 0.9em;
}

.discrepancy-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.discrepancy-details > div {
    margin: 2px 0;
}

.difference.positive-diff {
    color: var(--fm-green);
}

.difference.negative-diff {
    color: var(--fm-alert);
}

.resolution-attempt {
    margin-top: 8px;
    padding: 8px;
    background-color: var(--fm-surface-soft);
    border-left: 3px solid var(--fm-green);
    border-radius: 8px;
}

.resolution-count {
    color: var(--fm-green);
    font-weight: 800;
}

.resolution-attempt .counter-name {
    color: var(--fm-muted);
    font-style: italic;
    margin: 4px 0;
}

.resolution-attempt .resolution-date {
    font-size: 0.9em;
    color: var(--fm-muted);
}

.notes {
    margin-top: 8px;
    font-style: italic;
    color: var(--fm-muted);
    padding-left: 8px;
    border-left: 2px solid var(--fm-border);
}

.count-item .count-notes {
    font-size: 0.85rem;
    font-style: italic;
    color: var(--fm-muted);
    margin-top: 3px;
}

.count-item .counter-name {
    font-size: 0.85rem;
    color: var(--fm-muted);
    margin-top: 0.35rem;
    font-style: italic;
}

.count-item.resolution {
    border-left-color: var(--fm-green);
}

/* Responsive layout */
@media (max-width: 1100px) {
    .animal-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 1050px) {
    #inventory-breakdown {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 980px) {
    .animals-activity-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 780px) {
    .management-actions {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .animals-page-hero {
        grid-template-columns: 1fr;
        gap: 1.1rem;
        padding: 1.35rem 1.25rem;
        text-align: center;
    }

    .animals-page-hero__copy {
        text-align: center;
        align-items: center;
    }

    .animals-page-title {
        font-size: clamp(2.3rem, 12vw, 3.4rem);
        text-align: center;
    }

    .page-subtitle {
        max-width: 34rem;
    }

    .animal-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .brand-logo--app-page {
        max-width: 180px;
    }
}

@media (max-width: 700px) {
    .animals-container {
        width: min(calc(100% - 1rem), 100%);
        padding-top: 0.9rem;
        padding-bottom: 7.75rem;
    }
}

@media (max-width: 620px) {
    #inventory-breakdown {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .quick-actions {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .animal-actions,
    .button-grid {
        grid-template-columns: 1fr;
    }

    .action-button {
        width: 100%;
    }
}

/* Brand overrides – beat legacy main.css rules on this page */
.animals-container .management-actions .action-button {
    min-width: 0;
    margin-bottom: 0;
    box-shadow: none;
    border-bottom: none;
}

.animals-container .animal-actions .action-button:active,
.animals-container .quick-actions .action-button:active,
.animals-container .management-actions .action-button:active {
    transform: none;
    box-shadow: none;
    border-bottom: none;
}

.animals-container .action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    margin-bottom: 0;
    white-space: normal;
    word-break: break-word;
}

.animals-container .action-button:before {
    display: none;
}

.animals-container .button-row .action-button {
    width: auto;
}

.animals-container .stat-card h3 {
    background: transparent;
    box-shadow: none;
    text-shadow: none;
    text-transform: none;
    padding: 0;
} 