/* Base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    background-image: url('../assets/images/farm-background.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: #333;
    line-height: 1.6;
    min-height: 100%;
    position: relative;
    overflow-x: hidden;
}

/* Fix for iOS background-attachment: fixed not working */
@supports (-webkit-touch-callout: none) {
    body {
        background-attachment: scroll;
    }
    
    /* Alternative fixed background for iOS */
    body::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-image: url('../assets/images/farm-background.jpg');
        background-size: cover;
        background-position: center;
        z-index: -1;
    }
}

h1, h2, h3, h4, h5, h6 {
    margin-bottom: 0.5rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    line-height: 1.2;
    position: relative;
    padding-bottom: 8px;
    color: #2c3e50;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    text-align: center;
}

h2 {
    font-weight: 700;
    font-size: 1.6rem;
    color: #2c3e50;
    position: relative;
    padding-bottom: 12px;
    margin-bottom: 20px;
    display: inline-block;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border-bottom: none;
    margin-left: auto;
    margin-right: auto;
    display: table;
}

h2:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    height: 3px;
    width: 60px;
    background: linear-gradient(to right, #3498db, #2ecc71);
    border-radius: 2px;
}

h3 {
    font-size: 1.35rem;
    font-weight: 600;
    color: #34495e;
    margin-bottom: 15px;
    position: relative;
    letter-spacing: 0.3px;
}

.page-header h2, .welcome-card h2 {
    font-weight: 700;
    position: relative;
    padding: 0 0 12px 0;
    margin-bottom: 15px;
    width: auto;
    display: table;
    color: #34495e;
    text-align: center;
    border-bottom: none;
    margin-left: auto;
    margin-right: auto;
}

.page-header h2:after, .welcome-card h2:after {
    content: '';
    position: absolute;
    width: 60px;
    height: 3px;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(to right, #3498db, #2ecc71);
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.stat-card h3 {
    font-weight: 600;
    font-size: 1.1rem;
    padding: 10px 15px;
    margin: 0 auto 15px auto;
    color: #2c3e50;
    background: rgba(52, 152, 219, 0.1);
    border-radius: 5px;
    position: relative;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: none;
    display: table;
    width: auto;
}

.stat-card h3::after {
    content: '';
    position: absolute;
    width: 60px;
    height: 2px;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(to right, #3498db, #2ecc71);
    border-radius: 2px;
}

a {
    color: #3498db;
    text-decoration: none;
}

/* Mobile navigation */
.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: white;
    display: flex;
    justify-content: space-around;
    padding: 10px 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
    height: auto;
    min-height: 60px; /* Set a minimum height for the nav bar */
}

.mobile-nav a {
    color: #7f8c8d;
    text-align: center;
    text-decoration: none;
    font-size: 0.9rem;
    padding: 10px;
    flex: 1;
    transition: all 0.2s ease;
    position: relative;
}

.mobile-nav a:hover {
    color: #3498db;
    transform: translateY(-3px);
}

.mobile-nav a.active {
    color: #3498db;
    font-weight: bold;
    border-bottom: 3px solid #3498db;
}

.mobile-nav a:before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 3px;
    background-color: #3498db;
    transition: all 0.3s ease;
    transform: translateX(-50%);
}

.mobile-nav a:hover:before {
    width: 70%;
}

/* Additional button effects */
.add-button, .count-button, .login-button, .logout-button {
    transition: all 0.2s ease-in-out;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.add-button:hover, .count-button:hover, .login-button:hover, .logout-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}

.add-button:before, .count-button:before, .login-button:before, .logout-button:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, rgba(255,255,255,0.2), transparent);
    transition: all 0.3s ease;
}

.add-button:hover:before, .count-button:hover:before, .login-button:hover:before, .logout-button:hover:before {
    left: 100%;
}

/* Standard Action Buttons */
.action-button {
    display: flex;
    font-weight: 600;
    text-align: center;
    white-space: normal; /* Allow text wrapping */
    vertical-align: middle;
    user-select: none;
    padding: 8px 6px;
    font-size: 0.9rem;
    line-height: 1.2;
    border-radius: 6px;
    transition: all 0.2s ease;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border: none;
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
    width: 100%;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    word-break: break-word; /* Break long words if needed */
    hyphens: none; /* Prevent hyphenation */
}

.action-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.action-button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Button shine effect on hover */
.action-button:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, rgba(255,255,255,0.2), transparent);
    transition: all 0.3s ease;
}

.action-button:hover:before {
    left: 100%;
}

/* Button colors */
.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-success {
    background-color: #2ecc71;
    color: white;
}

.btn-success:hover {
    background-color: #27ae60;
}

.btn-warning {
    background-color: #f39c12;
    color: white;
}

.btn-warning:hover {
    background-color: #e67e22;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-secondary {
    color: #ffffff;
    background-color: #333333; /* Even darker grey color */
    border: none;
    align-items: center;
    justify-content: center;
}

.btn-secondary:hover {
    background-color: #1a1a1a; /* Almost black on hover */
    transform: translateY(-2px);
}

.btn-info {
    background-color: #9b59b6;
    color: white;
}

.btn-info:hover {
    background-color: #8e44ad;
}

/* Button sizes */
.btn-lg {
    padding: 12px 20px;
    font-size: 1.1rem;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Old button styles keep for backward compatibility */
button, .btn {
    display: inline-block;
    font-weight: 400;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    user-select: none;
    border: 1px solid transparent;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: 0.25rem;
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Button Container/Grids */
.button-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 15px;
}

.button-row .action-button {
    flex: 1;
    min-width: 120px;
}

/* Responsive adjustments for portrait mode and small screens */
@media screen and (max-width: 480px), screen and (orientation: portrait) {
    .button-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .button-row {
        gap: 8px;
        flex-direction: column; /* Stack buttons vertically in portrait */
    }
    
    .button-row .action-button {
        width: 100%;
        margin-right: 0;
    }
    
    .action-button {
        font-size: 0.8rem;
        padding: 6px 4px;
        min-height: 40px;
        letter-spacing: 0;
        word-break: break-word;
        white-space: normal;
        hyphens: none; /* Prevent hyphenation in portrait mode */
        text-transform: none; /* Remove uppercase in portrait to save space */
    }
    
    /* Specific fixes for feed and health pages */
    .feed-actions button, 
    .animal-actions button, 
    .management-actions button,
    .health-container .quick-actions button,
    .health-container .action-buttons button {
        font-size: 0.75rem;
        padding: 5px 3px;
        min-height: 38px;
        white-space: normal;
        word-break: break-word;
        hyphens: none; /* Prevent hyphenation */
        text-transform: none;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1.1;
    }
    
    /* For very small screens */
    @media (max-width: 360px) {
        .action-button {
            font-size: 0.75rem;
            padding: 5px 3px;
        }
    }
}

/* Forms */
input, select, textarea {
    display: block;
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 8px;
    font-size: 16px !important; /* Prevent iOS zoom on focus */
}

input:focus, select:focus, textarea:focus {
    color: #495057;
    background-color: #fff;
    border-color: #3498db;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
}

label {
    margin-bottom: 0.5rem;
    display: inline-block;
}

/* Utilities */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mt-5 { margin-top: 3rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mb-5 { margin-bottom: 3rem; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.hidden { display: none; }

/* App Container */
#app-content {
    width: 100%;
    margin: 0 auto;
    padding: 10px;
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden; /* Prevent horizontal scrolling */
    padding-bottom: 80px; /* Ensure content doesn't get hidden under the nav bar */
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    background-color: transparent;
}

/* Safe Area */
@supports (padding: max(0px)) {
    body {
        /* Ensure elements don't overlap with the notch on iPhones */
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        padding-top: max(10px, env(safe-area-inset-top));
        overflow-x: hidden; /* Prevent horizontal scrolling */
    }
    
    .mobile-nav {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

.feed-item {
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 8px;
    border-left: 4px solid #3498db;
}

.feed-item.low-stock {
    border-left: 4px solid #e74c3c;
    background-color: rgba(231, 76, 60, 0.1);
}

.feed-item.good-stock {
    border-left: 4px solid #2ecc71;
}

.feed-details {
    display: flex;
    flex-direction: column;
    margin-bottom: 5px;
}

.feed-name {
    font-weight: bold;
    font-size: 1.1rem;
}

.feed-quantity {
    font-size: 1.1rem;
    font-weight: bold;
    color: #3498db;
}

.feed-warning {
    color: #e74c3c;
    font-size: 0.9rem;
    margin-top: 3px;
}

.feed-info {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
    color: #7f8c8d;
}

/* Mobile keyboard accessibility improvements */
@media screen and (max-height: 450px) {
    .popup-content {
        margin-top: 10px;
        padding: 15px;
        max-height: 85vh;
        overflow-y: auto;
    }
    
    .form-group {
        margin-bottom: 10px;
    }
    
    .form-actions {
        margin-top: 10px;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    input, select, textarea {
        font-size: 16px !important; /* Prevent iOS zoom on focus */
    }
    
    select {
        background-image: url("data:image/svg+xml;utf8,<svg fill='gray' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
        background-repeat: no-repeat;
        background-position: right 8px center;
        padding-right: 30px;
    }
    
    input[type="date"] {
        min-height: 44px;
    }
}

/* Portrait mode adjustments */
@media screen and (max-width: 480px) and (orientation: portrait) {
    .stat-card {
        padding: 15px;
        margin-bottom: 12px;
    }
    
    .feed-item {
        padding: 8px;
        margin-bottom: 6px;
    }
    
    /* Ensure popups adjust to available space */
    .popup-content {
        width: 95%;
        max-width: 95%;
        padding: 15px;
        max-height: 85vh;
        margin: auto;
        position: relative;
        top: 0;
        transform: none;
    }
    
    /* Center the popup in portrait view */
    .popup {
        align-items: center !important;
        justify-content: center !important;
    }
}

/* Make content responsive */
img, video, table {
    max-width: 100%;
    height: auto;
}

/* Truncate long text with ellipsis where needed */
.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Better text wrapping for all elements */
p, h1, h2, h3, h4, h5, h6, span, div, button, a {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Better mobile-friendly tables */
@media (max-width: 480px) {
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* Add iOS-specific input field improvements */
input, textarea, select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0;
    font-size: 16px; /* iOS will zoom in on inputs with font sizes smaller than 16px */
}

input:focus, textarea:focus, select:focus {
    outline: none;
}

/* Ensure inputs are tappable on iOS */
.form-group {
    cursor: pointer;
}

/* Prevent iOS zoom on input focus */
@media screen and (-webkit-min-device-pixel-ratio: 0) { 
    select:focus,
    textarea:focus,
    input:focus {
        font-size: 16px;
        touch-action: manipulation;
    }
}

/* Improved iOS keyboard handling */
body.keyboard-open {
    /* Adjustments for when keyboard is visible */
    height: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Ensure popups remain visible and centered when keyboard is open */
.popup.keyboard-visible {
    align-items: center !important;
    justify-content: center !important;
}

.popup.keyboard-visible .popup-content {
    max-height: 70vh;
    overflow-y: auto;
    position: relative;
    top: 0 !important;
    transform: none !important;
}

/* Ensure form controls are large enough for touch on mobile */
button, 
input[type="submit"],
input[type="button"] {
    min-height: 44px; /* iOS accessibility guideline */
    touch-action: manipulation;
}

/* Content container with background overlay for better readability */
.content-container {
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    padding: 20px;
    margin: 15px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    width: calc(100% - 30px); /* Full width minus margins */
    box-sizing: border-box;
}

.popup-content {
    background-color: rgba(255, 255, 255, 0.8); /* Changed from solid white to translucent */
    border-radius: 10px;
    padding: 20px;
    max-width: 90%;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    margin: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
}

.auth-toggle {
    text-align: center;
    margin-top: 16px;
    font-size: 0.95rem;
    color: #2c3e50;
}
.auth-toggle a {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
}
.auth-toggle a:hover {
    text-decoration: underline;
} 