/* Shared Styling for Agropac Calculators */
:root {
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #475569;
    --primary: #059669;
    /* Emerald green accent */
    --primary-hover: #047857;
    --border-color: #cbd5e1;
    --border-focus: #059669;
    --accent: #3b82f6;
    /* Blue accent for toggles/links */
    --danger: #ef4444;
    /* Red for alerts/errors */
    --warning-bg: #fffbeb;
    --warning-border: #f59e0b;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    /* Prevent horizontal scrolling at body level */
}

/* Navbar */
.navbar {
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    height: 60px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-logo {
    font-weight: 700;
    font-size: 17px;
    color: var(--text-main);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 18px;
}

.nav-links-desktop {
    display: none;
    list-style: none;
    gap: 20px;
    align-items: center;
}

.nav-links-desktop a {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    transition: color 0.2s;
}

.nav-links-desktop a:hover {
    color: var(--primary);
}

/* Burger Toggle Button */
.burger-menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 24px;
    height: 16px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 101;
    outline: none;
}

.burger-bar {
    width: 100%;
    height: 2px;
    background-color: var(--text-main);
    transition: all 0.3s ease;
}

/* Burger Animation */
.burger-menu-btn.active .burger-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.burger-menu-btn.active .burger-bar:nth-child(2) {
    opacity: 0;
}

.burger-menu-btn.active .burger-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Mobile Slide-down Menu Drawer */
.mobile-drawer {
    position: fixed;
    top: 60px;
    left: 0;
    width: 100%;
    max-height: 0;
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    transition: max-height 0.35s ease;
    z-index: 99;
    box-shadow: var(--shadow-md);
}

.mobile-drawer.active {
    max-height: 420px;
    /* enough height to accommodate user info & 7 menu links */
}

.mobile-drawer-links {
    list-style: none;
    padding: 12px 16px;
}

.mobile-drawer-links li {
    margin-bottom: 8px;
}

.mobile-drawer-links a {
    display: block;
    text-decoration: none;
    color: var(--text-main);
    font-size: 15px;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.mobile-drawer-links a:hover {
    background-color: #f1f5f9;
    color: var(--primary);
}

/* Main Container Layout */
.container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 16px 12px;
    overflow-x: hidden;
    /* Force container elements to wrap/contain horizontal scroll */
}

/* Header Accent Line */
.header-accent {
    height: 4px;
    background-color: var(--primary);
    margin-bottom: 16px;
    border-radius: 2px;
}

header {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: flex-start;
}

.back-link {
    display: inline-flex;
    align-items: center;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--card-bg);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.back-link:hover {
    color: var(--primary);
    border-color: var(--primary);
}

h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

/* Search bar on index */
.search-container {
    margin-bottom: 16px;
}

.search-input {
    width: 100%;
    box-sizing: border-box !important;
    padding: 12px 16px;
    font-size: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--card-bg);
    color: var(--text-main);
    box-shadow: var(--shadow);
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--border-focus);
}

/* Grid & Cards */
.calculator-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.calc-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.calc-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.calc-card h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.calc-card p {
    font-size: 13px;
    color: var(--text-muted);
}

/* Main Calculator Split Layout */
.calc-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.inputs-panel,
.outputs-panel {
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

/* Input Card & Forms */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-control {
    display: block;
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid #94a3b8 !important;
    border-radius: 6px !important;
    background-color: #ffffff !important;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    border-color: var(--border-focus) !important;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15) !important;
}

/* Size Presets / Chips */
.presets-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.preset-btn {
    background-color: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover,
.preset-btn.active {
    background-color: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

/* Output values styling */
.summary-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px dashed var(--border-color);
    font-size: 13px;
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-value {
    font-weight: 600;
}

/* Responsive Tables without horizontal scroll of page */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

th {
    background-color: #f1f5f9;
    font-weight: 600;
    color: var(--text-muted);
    padding: 8px 10px;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
    /* Keep header on single line within scrolling card */
}

td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    white-space: nowrap;
    /* Prevent messy wraps within grid columns */
}

tr:nth-child(even) {
    background-color: #f8fafc;
}

.highlight-row {
    background-color: #ecfdf5 !important;
    font-weight: 600;
}

/* Toggle switch styling */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(18px);
}

/* Warnings / Info Alerts */
.alert-warning {
    background-color: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: 6px;
    padding: 10px;
    font-size: 12px;
    color: #92400e;
}

/* Global Footer */
.global-footer {
    background-color: #ffffff;
    border-top: 1px solid var(--border-color);
    padding: 16px 0;
    text-align: center;
    margin-top: 40px;
}

.footer-container p {
    font-size: 12px;
    color: var(--text-muted);
}

/* Responsive grid breakouts for larger viewports */
@media (min-width: 640px) {
    .calculator-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (min-width: 768px) {
    .nav-links-desktop {
        display: flex;
    }

    .burger-menu-btn {
        display: none;
    }

    .mobile-drawer {
        display: none;
    }

    .calc-layout {
        grid-template-columns: 320px 1fr;
        align-items: start;
    }
}

/* WebView / small mobile specific media query adjustments to block page scroll */
@media (max-width: 480px) {
    body {
        font-size: 13px;
    }

    .container {
        padding: 10px 8px;
    }

    .card {
        padding: 10px;
    }

    table {
        font-size: 11px;
    }

    th,
    td {
        padding: 6px 8px;
    }
}

/* Export to Image Button Styling */
.export-container {
    margin-bottom: 12px;
    display: flex;
    justify-content: flex-end;
}

.export-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: var(--accent) !important;
    /* solid blue accent */
    color: #ffffff !important;
    border: none !important;
    border-radius: 6px !important;
    padding: 8px 16px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: background-color 0.2s !important;
    box-shadow: var(--shadow) !important;
}

.export-btn:hover {
    background-color: #2563eb !important;
}

.export-btn-icon {
    font-size: 15px;
}

/* Responsive visibility rules for export buttons */
.header-export-btn {
    display: inline-flex;
}
@media (max-width: 768px) {
    .header-export-btn {
        display: none !important;
    }
}
@media (min-width: 769px) {
    .export-container {
        display: none !important;
    }
}

/* Fluid Container for Full-Width Pages */
.container-fluid {
    width: 100%;
    max-width: 100% !important;
    padding: 0;
    margin: 0;
}

/* Dashboard Layout Structure */
.dashboard-layout {
    display: flex;
    min-height: calc(100vh - 60px - 50px);
    /* subtract navbar & footer */
    width: 100%;
}

.dashboard-sidebar {
    width: 15%;
    min-width: 240px;
    background-color: #ffffff;
    border-right: 1px solid var(--border-color);
    padding: 24px 0;
    box-sizing: border-box;
}

.dashboard-content {
    width: 75%;
    padding: 32px 24px;
    box-sizing: border-box;
    overflow-y: auto;
}

/* Sidebar Menu */
.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-menu-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    border-left: 4px solid transparent;
    transition: all 0.2s;
}

.sidebar-menu-item.active a {
    color: var(--primary);
    background-color: #f0fdf4;
    border-left-color: var(--primary);
}

.sidebar-menu-item a:hover:not(.active) {
    color: var(--text-main);
    background-color: #f8fafc;
}

/* Metrics Cards */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.metric-card-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-card-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 4px;
    line-height: 1.2;
}

.metric-card-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Simple Rate Results styling */
.results-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.results-card-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.rate-box {
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    text-align: center;
    transition: border-color 0.2s;
}

.rate-box:hover {
    border-color: var(--primary);
}

.rate-box-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.rate-box-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 2px;
}

.rate-box-unit {
    font-size: 11px;
    color: var(--text-muted);
}

/* Responsive Overrides for Mobile APK and Small Screens */
@media (max-width: 768px) {
    .dashboard-layout {
        flex-direction: column;
    }

    .dashboard-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 12px 16px;
    }

    .sidebar-menu {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
    }

    .sidebar-menu-item {
        flex: 0 0 auto;
    }

    .sidebar-menu::-webkit-scrollbar {
        height: 4px;
    }
    .sidebar-menu::-webkit-scrollbar-track {
        background: transparent;
    }
    .sidebar-menu::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 2px;
    }

    .sidebar-menu-item a {
        padding: 8px 12px;
        justify-content: center;
        border-left: none;
        border-bottom: 3px solid transparent;
        border-radius: 6px;
        font-size: 13px;
    }

    .sidebar-menu-item.active a {
        border-bottom-color: var(--primary);
        border-radius: 6px 6px 0 0;
    }

    .dashboard-content {
        width: 100%;
        padding: 20px 16px;
    }
}