/* ==========================================================================
   3D Farm Telegram WebApp Stylesheet — Modern Dark Glassmorphism UI
   ========================================================================== */

:root {
    color-scheme: dark;
    --bg-dark: #090d16;
    --bg-radial: radial-gradient(circle at 50% 0%, #1e1b4b 0%, #090d16 100%);
    --card-glass: rgba(30, 41, 59, 0.65);
    --card-glass-hover: rgba(51, 65, 85, 0.75);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.3);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;

    --primary: var(--tg-theme-button-color, #6366f1);
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.4);

    --emerald: #10b981;
    --emerald-glow: rgba(16, 185, 129, 0.35);
    --amber: #f59e0b;
    --amber-glow: rgba(245, 158, 11, 0.35);
    --rose: #f43f5e;
    --rose-glow: rgba(244, 63, 94, 0.35);
    --cyan: #06b6d4;
    --cyan-glow: rgba(6, 182, 212, 0.35);
    --purple: #a855f7;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    /* Centralized Semantic Stacking Context Layering */
    --z-base: 1;
    --z-header: 100;
    --z-nav: 150;
    --z-pull-refresh: 950;
    --z-floating-bar: 950;
    --z-modal-backdrop: 1000;
    --z-modal: 1010;
    --z-modal-nested: 1020;
    --z-modal-fullscreen: 1050;
    --z-popover: 1500;
    --z-toast: 2000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.45) rgba(15, 23, 42, 0.6);
}

/* Modern Sleek Dark Glassmorphic Scrollbars across entire App */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
    border-radius: 8px;
}

::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.4);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary, #6366f1);
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
}

::-webkit-scrollbar-button {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* Eliminate native white squares & spinner arrows across all number inputs */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button,
*::-webkit-inner-spin-button,
*::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
    display: none !important;
}

input[type="number"] {
    -moz-appearance: textfield !important;
    appearance: textfield !important;
}

html {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    background-image: var(--bg-radial);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
    padding-bottom: calc(75px + env(safe-area-inset-bottom, 0px));
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

@media (min-width: 768px) {
    .app-container {
        max-width: 1140px;
        padding: 0 20px;
    }
    .app-header {
        border-radius: var(--radius-lg);
        margin-top: 14px;
        border: 1px solid var(--border-glass);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    }
}

@media (min-width: 1200px) {
    .app-container {
        max-width: 1380px;
        padding: 0 24px;
    }
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(16px + env(safe-area-inset-top, 0px)) 20px 16px 20px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-glass);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.brand-titles h1 {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    background: linear-gradient(90deg, #fff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-titles .subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge {
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.badge-active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--emerald);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: var(--emerald);
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.2);
    color: var(--amber);
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge-danger {
    background: rgba(244, 63, 94, 0.2);
    color: var(--rose);
    border: 1px solid rgba(244, 63, 94, 0.4);
}

.badge-primary {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.4);
}

.badge-secondary {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-muted);
    border: 1px solid rgba(148, 163, 184, 0.4);
}

.badge-info {
    background: rgba(14, 165, 233, 0.2);
    color: #0ea5e9;
    border: 1px solid rgba(14, 165, 233, 0.4);
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover, .icon-btn:active {
    background: rgba(255, 255, 255, 0.15);
    transform: rotate(45deg);
}

/* App Content & Tabs */
.app-content {
    padding: 16px;
    flex: 1;
}

.tab-page {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.tab-page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
}

.pulse-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--emerald);
    box-shadow: 0 0 10px var(--emerald);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Glass Card */
.glass-card {
    background: var(--card-glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-soft);
    transition: var(--transition);
}

.glass-card:hover {
    border-color: var(--border-glow);
}

.glass-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Mobile iOS Safari auto-zoom prevention and touch target polish */
@media screen and (max-width: 768px) {
    input, select, textarea, .form-control {
        font-size: 16px !important;
    }
}

/* Flex, Gap & Alignment Utilities */
.d-flex { display: flex !important; }
.flex-column { flex-direction: column !important; }
.hidden, .d-flex.hidden { display: none !important; }
.gap-1 { gap: 4px !important; }
.gap-2 { gap: 8px !important; }
.gap-3 { gap: 12px !important; }
.flex-wrap { flex-wrap: wrap !important; }
.align-items-center { align-items: center !important; }
.align-items-stretch { align-items: stretch !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-center { justify-content: center !important; }
.flex-shrink-0 { flex-shrink: 0 !important; }
.w-100 { width: 100% !important; }
.h-100 { height: 100% !important; }
.d-block { display: block !important; }
.d-inline-block { display: inline-block !important; }
.overflow-hidden { overflow: hidden !important; }
.rounded { border-radius: var(--radius-sm) !important; }
.text-truncate { overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important; }
.font-monospace { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important; }
.fw-bold, .font-weight-bold { font-weight: 700 !important; }

/* Spacing Utilities */
.p-1 { padding: 4px !important; }
.p-2 { padding: 8px !important; }
.p-3 { padding: 12px !important; }
.p-4 { padding: 16px !important; }
.px-1 { padding-left: 4px !important; padding-right: 4px !important; }
.px-2 { padding-left: 8px !important; padding-right: 8px !important; }
.py-1 { padding-top: 4px !important; padding-bottom: 4px !important; }
.py-2 { padding-top: 8px !important; padding-bottom: 8px !important; }
.m-0 { margin: 0 !important; }
.mt-1 { margin-top: 4px !important; }
.mt-2 { margin-top: 8px !important; }
.mt-3 { margin-top: 12px !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 4px !important; }
.mb-2 { margin-bottom: 8px !important; }
.mb-3 { margin-bottom: 12px !important; }
.me-1 { margin-right: 4px !important; }
.me-2 { margin-right: 8px !important; }
.ms-1 { margin-left: 4px !important; }
.ms-2 { margin-left: 8px !important; }

/* Grid Column Shims */
.col-md-6, .col-md-4, .col-md-3 {
    flex: 1 1 200px;
    min-width: 0;
}

/* Position Utilities */
.position-relative { position: relative !important; }
.position-absolute { position: absolute !important; }
.top-0 { top: 0 !important; }
.start-0 { left: 0 !important; }
.end-0 { right: 0 !important; }
.bottom-0 { bottom: 0 !important; }

/* Brand and Functional Color Utilities (Used throughout HTML & JS icons/badges) */
.color-green { color: var(--emerald) !important; }
.color-red { color: var(--rose) !important; }
.color-amber, .color-orange, .color-yellow { color: var(--amber) !important; }
.color-blue { color: var(--primary) !important; }
.color-cyan { color: var(--cyan, #06b6d4) !important; }
.color-purple { color: var(--purple, #a855f7) !important; }
.color-muted { color: var(--text-muted) !important; }

/* Text Color Classes */
.text-success { color: var(--emerald) !important; }
.text-danger { color: var(--rose) !important; }
.text-warning, .text-amber { color: var(--amber) !important; }
.text-info { color: #0ea5e9 !important; }
.text-muted { color: var(--text-muted) !important; }
.text-light, .text-white { color: #ffffff !important; }
.text-center { text-align: center !important; }

/* Close Button Fallback */
.btn-close {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-glass);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    transition: var(--transition);
}
.btn-close:hover {
    background: var(--rose);
    color: #fff;
}


/* ==========================================================================
   Mobile Smartphone Screen Optimization (< 600px)
   ========================================================================== */
@media (max-width: 600px) {
    html, body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
    body {
        padding-bottom: 84px;
    }
    .app-header {
        padding: 8px 12px;
        gap: 8px;
    }
    .brand-titles h1 {
        font-size: 15px;
    }
    .brand-titles .subtitle {
        font-size: 10.5px;
    }
    .header-actions {
        gap: 6px;
    }
    .header-actions .btn-sm {
        padding: 4px 8px;
        font-size: 11px;
    }
    .brand-logo {
        width: 32px;
        height: 32px;
        font-size: 15px;
    }
    .app-content {
        padding: 10px;
    }
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .section-header > div,
    .section-header .d-flex {
        width: 100%;
        display: flex !important;
        flex-wrap: wrap;
        gap: 6px !important;
    }
    .section-header .d-flex .btn:not(.compact-cols-btn):not(.btn-xs),
    .section-header .d-flex a.btn {
        flex: 1 1 auto;
        min-width: 85px;
        padding: 6px 8px;
        font-size: 11px;
        text-align: center;
        justify-content: center;
    }
    .view-mode-switcher {
        display: inline-flex !important;
        flex-wrap: nowrap !important;
        width: auto !important;
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid var(--border-glass);
        border-radius: 8px;
        padding: 2px;
        gap: 2px;
    }
    .view-mode-switcher .btn {
        flex: 0 0 auto !important;
        min-width: 0 !important;
        padding: 4px 8px !important;
        font-size: 11px !important;
        border: none !important;
    }
    .compact-grid-picker {
        display: inline-flex !important;
        flex-wrap: nowrap !important;
        width: auto !important;
        gap: 3px !important;
        align-items: center !important;
    }
    .compact-grid-picker .compact-cols-btn {
        flex: 0 0 auto !important;
        min-width: 26px !important;
        width: 26px !important;
        height: 26px !important;
        padding: 0 !important;
        font-size: 11px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    .compact-grid-picker .compact-cols-btn[data-cols="auto"] {
        width: auto !important;
        min-width: 38px !important;
        padding: 0 6px !important;
    }
    .fleet-batch-actions {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
        width: 100% !important;
    }
    .fleet-batch-actions .fleet-batch-btn {
        width: 100% !important;
        padding: 6px 4px !important;
        font-size: 11px !important;
        white-space: nowrap !important;
        text-align: center !important;
        justify-content: center !important;
    }
    .glass-card {
        padding: 14px 12px;
    }
    .form-row {
        flex-direction: column;
        gap: 8px;
    }
    .form-row .col {
        width: 100%;
    }
}


