/* ═══════════════════════════════════════════════════════════════
   AgriFlow Design System — Sprint 6
   Inspired by clean white dashboard UX, AgriFlow Green Palette
    Colors: #051F20 | #163832 | #8EB69B | #DAF1DE | #FF6B6B (Coral)
═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    --c-darkest:  #051F20;
    --c-darker:   #0B2B26;
    --c-dark:     #163832;
    --c-mid:      #235347;
    --c-light:    #8EB69B;
    --c-lighteste: #DAF1DE;
    --c-coral:    #FF6B6B;
    --c-coral-dark: #EE5253;
    --c-coral-light: #FFB8B8;
    --c-white:    #FFFFFF;
    --c-bg:       #F5F7FA;
    --c-surface:  #FFFFFF;
    --c-border:   #E8EDF2;
    --c-text:     #051F20;
    --c-text-sub: #64748B;
    --c-text-muted: #94A3B8;
    --sidebar-w:  72px;
    --sidebar-expanded-w: 240px;
    --topbar-h:   64px;
    --radius-sm:  8px;
    --radius-md:  12px;
    --radius-lg:  16px;
    --radius-xl:  24px;
    --shadow-xs:  0 1px 3px rgba(5,31,32,0.04);
    --shadow-sm:  0 2px 8px rgba(5,31,32,0.07);
    --shadow-md:  0 4px 16px rgba(5,31,32,0.10);
    --shadow-lg:  0 8px 32px rgba(5,31,32,0.14);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }
* { scrollbar-width: thin; scrollbar-color: var(--c-border) transparent; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 10px; }

/* ── App Shell ─────────────────────────────────────────────── */
.af-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar (Legacy - Now handled by sidebar.css) ─────────────────────────── */
/* Sidebar rules removed to avoid conflict with sidebar.css */


/* ── Main Content Area ─────────────────────────────────────── */
.af-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    transition: margin-left 0.25s cubic-bezier(0.4,0,0.2,1);
}


/* ── Top Bar ────────────────────────────────────────────────── */
.af-topbar {
    height: var(--topbar-h);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 50;
}
.af-search {
    flex: 1;
    max-width: 380px;
    position: relative;
}
.af-search input {
    width: 100%;
    height: 38px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-xl);
    padding: 0 16px 0 40px;
    font-size: 13px;
    color: var(--c-text);
    outline: none;
    transition: border 0.2s, box-shadow 0.2s;
}
.af-search input:focus { border-color: var(--c-light); box-shadow: 0 0 0 3px rgba(142,182,155,0.15); }
.af-search input::placeholder { color: var(--c-text-muted); }
.af-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--c-text-muted); }
.af-topbar-center { flex: 1; text-align: center; }
.af-topbar-date { font-size: 12px; font-weight: 600; color: var(--c-mid); background: var(--c-lightest); padding: 4px 14px; border-radius: 20px; }
.af-topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.af-icon-btn {
    width: 36px; height: 36px;
    border-radius: var(--radius-md);
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    display: flex; align-items: center; justify-content: center;
    color: var(--c-text-sub);
    transition: all 0.18s;
    position: relative;
}
.af-icon-btn:hover { background: var(--c-lightest); border-color: var(--c-light); color: var(--c-dark); }
.af-icon-btn svg { width: 16px; height: 16px; }
.af-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--c-dark);
    color: white;
    font-size: 13px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    border: 2px solid var(--c-light);
    overflow: hidden;
    flex-shrink: 0;
}
.af-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── Page Content ───────────────────────────────────────────── */
.af-content {
    flex: 1;
    overflow-y: auto;
    padding: 28px 28px 60px;
}
.af-page-header {
    margin-bottom: 24px;
}
.af-page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--c-darkest);
    line-height: 1.2;
}
.af-page-sub {
    font-size: 13px;
    color: var(--c-text-sub);
    margin-top: 3px;
}
.af-page-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }

/* ── Cards ──────────────────────────────────────────────────── */
.af-card {
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--c-border);
    box-shadow: var(--shadow-xs);
    padding: 20px 24px;
}
.af-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--c-text-sub);
    margin-bottom: 8px;
    letter-spacing: 0.01em;
}

/* ── KPI Cards ──────────────────────────────────────────────── */
.af-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.af-kpi {
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--c-border);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: inherit;
}
.af-kpi:hover { box-shadow: var(--shadow-md); border-color: var(--c-light); transform: translateY(-1px); }
.af-kpi-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--c-text-muted); margin-bottom: 6px; }
.af-kpi-value { font-size: 26px; font-weight: 800; color: var(--c-darkest); line-height: 1; }
.af-kpi-change { font-size: 11px; font-weight: 600; margin-top: 6px; }
.af-kpi-change.up { color: #22c55e; }
.af-kpi-change.down { color: #ef4444; }
.af-kpi-icon {
    width: 44px; height: 44px; border-radius: var(--radius-md);
    background: var(--c-lightest);
    color: var(--c-dark);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.af-kpi-icon svg { width: 20px; height: 20px; }

/* ── Buttons ────────────────────────────────────────────────── */
.af-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    transition: all 0.18s;
    white-space: nowrap;
    cursor: pointer;
    border: none;
}
.af-btn svg { width: 15px; height: 15px; }
.af-btn-primary { background: var(--c-dark); color: white; }
.af-btn-primary:hover { background: var(--c-mid); }
.af-btn-secondary { background: var(--c-lightest); color: var(--c-dark); border: 1px solid var(--c-light); }
.af-btn-secondary:hover { background: var(--c-light); }
.af-btn-ghost { background: transparent; color: var(--c-text-sub); border: 1px solid var(--c-border); }
.af-btn-ghost:hover { background: var(--c-bg); color: var(--c-text); }
.af-btn-danger { background: #fee2e2; color: #ef4444; border: 1px solid #fecaca; }
.af-btn-danger:hover { background: #ef4444; color: white; }
.af-btn-sm { padding: 6px 12px; font-size: 12px; }
.af-btn-lg { padding: 13px 28px; font-size: 15px; }

/* ── Badges ─────────────────────────────────────────────────── */
.af-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.af-badge-green  { background: #dcfce7; color: #16a34a; }
.af-badge-red    { background: #fee2e2; color: #ef4444; }
.af-badge-yellow { background: #fef9c3; color: #ca8a04; }
.af-badge-blue   { background: #dbeafe; color: #2563eb; }
.af-badge-gray   { background: var(--c-bg); color: var(--c-text-sub); }
.af-badge-primary { background: var(--c-lightest); color: var(--c-dark); }

/* ── Form Elements ──────────────────────────────────────────── */
.af-input {
    width: 100%;
    height: 42px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    padding: 0 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--c-text);
    background: var(--c-surface);
    outline: none;
    transition: border 0.2s, box-shadow 0.2s;
}
.af-input:focus { border-color: var(--c-light); box-shadow: 0 0 0 3px rgba(142,182,155,0.15); }
.af-input::placeholder { color: var(--c-text-muted); font-weight: 400; }
.af-textarea { height: auto; padding: 12px 14px; resize: vertical; min-height: 90px; }
.af-select { appearance: none; cursor: pointer; }
.af-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-text-sub); margin-bottom: 6px; }
.af-form-group { display: flex; flex-direction: column; gap: 6px; }

/* ── Tables ─────────────────────────────────────────────────── */
.af-table-wrap { overflow-x: auto; }
.af-table { width: 100%; border-collapse: collapse; }
.af-table thead th {
    padding: 10px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--c-text-muted);
    background: var(--c-bg);
    border-bottom: 1px solid var(--c-border);
    white-space: nowrap;
}
.af-table tbody td {
    padding: 13px 16px;
    font-size: 13px;
    color: var(--c-text);
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}
.af-table tbody tr:hover td { background: var(--c-bg); }
.af-table tbody tr:last-child td { border-bottom: none; }

/* ── Modal ──────────────────────────────────────────────────── */
.af-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(5,31,32,0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s;
}
.af-modal-overlay.open { opacity: 1; pointer-events: all; }
.af-modal {
    background: var(--c-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(12px);
    transition: transform 0.2s;
}
.af-modal-overlay.open .af-modal { transform: translateY(0); }
.af-modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.af-modal-title { font-size: 16px; font-weight: 700; color: var(--c-darkest); }
.af-modal-close { width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--c-bg); color: var(--c-text-sub); display: flex; align-items: center; justify-content: center; transition: all 0.18s; }
.af-modal-close:hover { background: #fee2e2; color: #ef4444; }

/* ── Trial Banner ───────────────────────────────────────────── */
.af-trial-banner {
    background: linear-gradient(90deg, #fef9c3, #fef3c7);
    border: 1px solid #fde68a;
    border-radius: var(--radius-md);
    padding: 10px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 13px;
}
.af-trial-banner strong { color: #92400e; }
.af-trial-text { color: #78350f; }

/* ── Kanban ─────────────────────────────────────────────────── */
.af-kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; align-items: start; }
.af-kanban-col { background: var(--c-bg); border-radius: var(--radius-lg); padding: 12px; min-height: 200px; }
.af-kanban-col-header { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 12px; margin-bottom: 4px; }
.af-kanban-col-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-text-sub); }
.af-kanban-badge { font-size: 11px; font-weight: 700; background: var(--c-border); color: var(--c-text-muted); width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.af-deal-card {
    background: var(--c-surface);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 8px;
    border: 1px solid var(--c-border);
    box-shadow: var(--shadow-xs);
    transition: all 0.18s;
    cursor: pointer;
}
.af-deal-card:hover { box-shadow: var(--shadow-sm); border-color: var(--c-light); }
.af-deal-card-actions { display: flex; gap: 6px; margin-top: 10px; }

/* ── Filter Bar ─────────────────────────────────────────────── */
.af-filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.af-filter-select {
    height: 38px;
    padding: 0 32px 0 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    color: var(--c-text);
    background: var(--c-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E") no-repeat right 10px center / 14px;
    appearance: none;
    outline: none;
    cursor: pointer;
    transition: border 0.2s;
}
.af-filter-select:focus { border-color: var(--c-light); }
.af-filter-input {
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    color: var(--c-text);
    background: var(--c-surface);
    outline: none;
    transition: border 0.2s;
    min-width: 160px;
}
.af-filter-input:focus { border-color: var(--c-light); }

/* ── Map ────────────────────────────────────────────────────── */
#gpsMap { border-radius: var(--radius-lg); z-index: 1; }

/* ── Profile ────────────────────────────────────────────────── */
.af-avatar-upload { position: relative; display: inline-block; cursor: pointer; }
.af-avatar-upload input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.af-avatar-upload:hover .af-avatar-edit-overlay { opacity: 1; }
.af-avatar-edit-overlay {
    position: absolute; inset: 0; border-radius: 50%;
    background: rgba(5,31,32,0.5);
    display: flex; align-items: center; justify-content: center;
    color: white; opacity: 0; transition: opacity 0.2s;
    font-size: 11px; font-weight: 600;
}

/* ── Responsive Navigation (Legacy - Now handled by sidebar.css) ─────────── */
/* Responsive navigation rules removed to avoid conflict with sidebar.css */


/* ── Utilities ──────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--c-text-muted); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.uppercase { text-transform: uppercase; letter-spacing: 0.06em; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    
    .af-topbar { padding: 0 16px; }
    .af-search { display: none; } /* Hide search in topbar on mobile to save space */
    
    .af-content { padding: 16px; }
    .af-page-title { font-size: 18px; }
    
    /* Auto-stacking cards */
    .af-kpi-grid { grid-template-columns: 1fr; }
    .stats-strip { grid-template-columns: 1fr 1fr; gap: 8px; }
    
    /* Table horizontal scroll */
    .af-table-wrap {
        margin: 0 -16px;
        padding: 0 16px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .af-table { min-width: 600px; }
    
    /* Kanban horizontal scroll */
    .af-kanban {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 12px;
        padding-bottom: 12px;
        -webkit-overflow-scrolling: touch;
    }
    .af-kanban-col {
        min-width: 280px;
        flex-shrink: 0;
    }
}
/* ── Searchable Select Component (Google-style Combobox) ─────────────────── */
.af-select-search { position: relative; width: 100%; min-width: 0; }
.af-select-search-trigger { position: relative; display: flex; align-items: center; width: 100%; }
.af-select-search-main-input {
    width: 100% !important; height: 42px !important; padding: 0 40px 0 14px !important;
    border: 1px solid var(--c-border) !important; border-radius: var(--radius-md) !important;
    font-size: 13px !important; font-weight: 500 !important; outline: none !important; transition: all 0.2s !important;
    background: var(--c-surface) !important; color: var(--c-text) !important;
}
.af-select-search-main-input:focus {
    border-color: var(--c-light) !important; 
    box-shadow: 0 0 0 3px rgba(142,182,155,0.15) !important;
}
.af-select-search-lupa {
    position: absolute; right: 12px; color: var(--c-text-muted);
    pointer-events: none; display: flex; align-items: center; transition: color 0.2s;
}
.af-select-search.open .af-select-search-lupa { color: var(--c-light); }

.af-select-search-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--c-surface); border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 2000; display: none; flex-direction: column; overflow: hidden;
    animation: af-dropdown-slide 0.2s ease-out;
}
.af-select-search.open .af-select-search-dropdown { display: flex; }

@keyframes af-dropdown-slide {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.af-select-search-options { max-height: 220px; overflow-y: auto; padding: 4px; }
.af-select-search-option {
    padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.15s;
    color: var(--c-text);
}
.af-select-search-option:hover { background: var(--c-bg); color: var(--c-dark); }
.af-select-search-option.selected { background: var(--c-lightest); color: var(--c-dark); font-weight: 700; }
.af-select-search-no-results { padding: 20px; text-align: center; color: var(--c-text-muted); font-size: 12px; font-style: italic; }
