/* ═══════════════════════════════════════════════════════
   Agroplex Design System — Global Styles
   ═══════════════════════════════════════════════════════ */

/* ─── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3, h4, h5, h6 { margin: 0; font-family: 'Manrope', sans-serif; }

/* ─── Material Symbols helper ────────────────────────── */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

/* ─── Page header ────────────────────────────────────── */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.page-header h1 { font-family: 'Manrope', sans-serif; font-size: 24px; font-weight: 700; margin: 0 0 4px; color: #111827; }
.page-header p  { font-size: 14px; color: #6b7280; margin: 0; }

/* ─── Status badges ──────────────────────────────────── */
.status-badge { padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.status-success { background: #dcfce7; color: #166534; }
.status-warning { background: #fef3c7; color: #92400e; }
.status-danger  { background: #fee2e2; color: #991b1b; }
.status-info    { background: #dbeafe; color: #1e40af; }
.status-primary { background: #dcfce7; color: #15803d; }
.status-neutral { background: #f3f4f6; color: #6b7280; }

/* ─── Buttons ────────────────────────────────────────── */
.btn-primary {
    padding: 10px 20px; background: #16a34a; color: white;
    border: none; border-radius: 8px; font-size: 14px; font-weight: 500;
    cursor: pointer; text-decoration: none; font-family: 'Public Sans', sans-serif;
    display: inline-flex; align-items: center; gap: 8px; transition: all .2s;
}
.btn-primary:hover:not(:disabled) { background: #15803d; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
    padding: 10px 20px; background: white; color: #374151;
    border: 1px solid #e5e7eb; border-radius: 8px; font-size: 14px;
    text-decoration: none; cursor: pointer; font-family: 'Public Sans', sans-serif;
    display: inline-flex; align-items: center; gap: 8px; transition: all .2s;
}
.btn-secondary:hover { background: #f9fafb; border-color: #d1d5db; }

.btn-danger {
    padding: 10px 20px; background: #fee2e2; color: #dc2626;
    border: 1px solid #fecaca; border-radius: 8px; font-size: 14px;
    cursor: pointer; font-family: 'Public Sans', sans-serif;
    display: inline-flex; align-items: center; gap: 8px; transition: all .2s;
}
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon { padding: 8px; border-radius: 8px; border: 1px solid #e5e7eb; background: white; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: all .15s; }
.btn-icon:hover { background: #f3f4f6; }

/* ─── Application cards ──────────────────────────────── */
.applications-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.application-card {
    background: white; border-radius: 12px; padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06); cursor: pointer;
    transition: all .2s; border: 1px solid #e8ede4;
}
.application-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); border-color: #bbf7d0; transform: translateY(-2px); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.field-info  { display: flex; flex-direction: column; gap: 4px; }
.field-name  { font-family: 'Manrope', sans-serif; font-weight: 600; font-size: 15px; }
.crop-badge  { font-size: 11px; background: #f0fdf4; color: #166534; padding: 2px 8px; border-radius: 4px; width: fit-content; }
.description { font-size: 13px; color: #6b7280; margin: 0 0 12px; line-height: 1.6; }
.card-meta   { display: flex; gap: 12px; font-size: 12px; color: #9ca3af; flex-wrap: wrap; }
.pdf-badge   { margin-top: 10px; font-size: 12px; color: #2563eb; background: #dbeafe; padding: 4px 10px; border-radius: 6px; width: fit-content; }

/* ─── Section Card ───────────────────────────────────── */
.section-card {
    background: white; border-radius: 12px; padding: 24px;
    border: 1px solid #e8ede4;
}
.section-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-card-title { font-family: 'Manrope', sans-serif; font-size: 16px; font-weight: 600; color: #111827; }

/* ─── Metric Card ────────────────────────────────────── */
.metric-card {
    background: white; border-radius: 12px; padding: 20px;
    border: 1px solid #e8ede4; display: flex; align-items: flex-start; gap: 16px;
}
.metric-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.metric-icon-green  { background: #dcfce7; color: #16a34a; }
.metric-icon-blue   { background: #dbeafe; color: #2563eb; }
.metric-icon-yellow { background: #fef3c7; color: #d97706; }
.metric-icon-red    { background: #fee2e2; color: #dc2626; }
.metric-icon-purple { background: #f3e8ff; color: #9333ea; }
.metric-value { font-family: 'Manrope', sans-serif; font-size: 28px; font-weight: 700; color: #111827; line-height: 1.2; }
.metric-label { font-size: 13px; color: #6b7280; margin-top: 2px; }
.metric-trend { font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.metric-trend-up   { color: #16a34a; }
.metric-trend-down { color: #dc2626; }

/* ─── Table ──────────────────────────────────────────── */
.table-card  { background: white; border-radius: 12px; border: 1px solid #e8ede4; overflow: hidden; }
.data-table  { width: 100%; border-collapse: collapse; }
.data-table th {
    padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600;
    color: #6b7280; background: #f8faf5; border-bottom: 1px solid #e8ede4;
    text-transform: uppercase; letter-spacing: .05em; font-family: 'Public Sans', sans-serif;
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid #f1f5ee; font-size: 14px; }
.data-table tr:last-child td { border-bottom: none; }
.clickable-row { cursor: pointer; transition: background .15s; }
.clickable-row:hover td { background: #f8faf5; }
.field-cell  { display: flex; flex-direction: column; gap: 4px; }
.crop-tag    { font-size: 11px; padding: 2px 6px; background: #dcfce7; color: #166534; border-radius: 4px; width: fit-content; }
.muted       { color: #9ca3af; font-size: 13px; }

/* ─── Filter tabs ────────────────────────────────────── */
.filter-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-tab {
    padding: 8px 16px; background: white; border: 1px solid #e5e7eb;
    border-radius: 8px; cursor: pointer; font-size: 13px;
    transition: all .15s; color: #374151; font-family: 'Public Sans', sans-serif;
}
.filter-tab:hover  { border-color: #16a34a; color: #16a34a; }
.filter-tab.active { background: #16a34a; color: white; border-color: #16a34a; }

/* ─── Loading / Empty ────────────────────────────────── */
.loading-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 80px 0; gap: 12px; color: #9ca3af; }
.spinner-large { width: 36px; height: 36px; border: 3px solid #e5e7eb; border-top-color: #16a34a; border-radius: 50%; animation: spin .8s linear infinite; }
.empty-state   { text-align: center; padding: 80px 20px; background: white; border-radius: 12px; border: 1px solid #e8ede4; }
.empty-icon    { font-size: 48px; margin-bottom: 16px; color: #9ca3af; }
.empty-state h3 { font-family: 'Manrope', sans-serif; font-size: 18px; color: #374151; margin: 0 0 8px; }
.empty-state p  { color: #9ca3af; font-size: 14px; margin: 0 0 24px; }

/* ─── Pagination ─────────────────────────────────────── */
.pagination { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 24px; }
.pagination button { padding: 8px 16px; background: white; border: 1px solid #e5e7eb; border-radius: 8px; cursor: pointer; font-size: 14px; transition: all .15s; }
.pagination button:hover:not(:disabled) { border-color: #16a34a; color: #16a34a; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination span   { font-size: 14px; color: #6b7280; }

/* ─── Section title ──────────────────────────────────── */
.section-title { font-family: 'Manrope', sans-serif; font-size: 15px; font-weight: 600; color: #14532d; margin: 0 0 14px; }

/* ─── Form ───────────────────────────────────────────── */
.form-card  { background: white; border-radius: 12px; padding: 28px; border: 1px solid #e8ede4; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 6px;
    font-family: 'Public Sans', sans-serif;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: 10px 12px; border: 1px solid #d1d5db;
    border-radius: 8px; font-size: 14px; box-sizing: border-box;
    font-family: 'Public Sans', sans-serif; transition: all .2s;
    background: white;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none; border-color: #16a34a;
    box-shadow: 0 0 0 3px rgba(22,163,74,.1);
}
.char-count  { text-align: right; font-size: 11px; color: #9ca3af; margin-top: 3px; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; padding-top: 24px; border-top: 1px solid #f1f5ee; }

/* ─── Alerts ─────────────────────────────────────────── */
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #dc2626; padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.alert-success a { color: #166534; font-weight: 600; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* ─── Modal ──────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; backdrop-filter: blur(4px); }
.modal-card {
    background: white; border-radius: 16px; padding: 28px; width: 100%; max-width: 480px;
    box-shadow: 0 20px 60px rgba(0,0,0,.15); max-height: 90vh; overflow-y: auto;
}
.modal-card h3 { font-family: 'Manrope', sans-serif; font-size: 18px; font-weight: 600; color: #111827; margin: 0 0 20px; }

/* ─── Badges (general) ───────────────────────────────── */
.badge        { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-gray   { background: #f3f4f6; color: #6b7280; }
.badge-purple { background: #f3e8ff; color: #7c3aed; }

/* ─── Search input ───────────────────────────────────── */
.search-input {
    padding: 8px 12px 8px 36px; border: 1px solid #e5e7eb;
    border-radius: 8px; font-size: 14px; font-family: 'Public Sans', sans-serif;
    background: white; transition: all .2s; width: 280px;
}
.search-input:focus { outline: none; border-color: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.1); }
.search-wrapper { position: relative; }
.search-wrapper .material-symbols-outlined {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    font-size: 20px; color: #9ca3af;
}

/* ─── Tooltip ────────────────────────────────────────── */
.tooltip { position: relative; }
.tooltip-text {
    visibility: hidden; opacity: 0; position: absolute; bottom: calc(100% + 6px);
    left: 50%; transform: translateX(-50%); background: #1f2937; color: white;
    padding: 4px 10px; border-radius: 6px; font-size: 12px; white-space: nowrap;
    transition: opacity .15s; z-index: 50;
}
.tooltip:hover .tooltip-text { visibility: visible; opacity: 1; }

/* ─── Animations ─────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.animate-fade-in { animation: fadeIn .3s ease-out; }

/* ═══════════════════════════════════════════════════════
   Responsive — Tablet (≤ 1023px) and Mobile (≤ 640px)
   ═══════════════════════════════════════════════════════ */

/* Make data tables horizontally scrollable on narrow screens */
.table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { min-width: 600px; }

@media (max-width: 1023px) {
    .page-header { flex-wrap: wrap; gap: 12px; }
    .page-header h1 { font-size: 22px; }
    .applications-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
    .form-card { padding: 20px; }
    .search-input { width: 100%; max-width: 100%; }
}

@media (max-width: 640px) {
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header h1 { font-size: 20px; }
    .page-header p { font-size: 13px; }

    .form-card { padding: 16px; border-radius: 10px; }
    .form-row { grid-template-columns: 1fr; gap: 0; }
    .form-group input,
    .form-group select,
    .form-group textarea { font-size: 16px; padding: 11px 12px; } /* 16px prevents iOS zoom on focus */

    .form-actions { flex-direction: column-reverse; gap: 8px; padding-top: 16px; margin-top: 16px; }
    .form-actions .btn-primary,
    .form-actions .btn-secondary,
    .form-actions .btn-danger { width: 100%; justify-content: center; }

    .applications-grid { grid-template-columns: 1fr; }
    .application-card { padding: 16px; }
    .application-card:hover { transform: none; }

    .section-card { padding: 16px; }
    .metric-card { padding: 16px; gap: 12px; }
    .metric-icon { width: 40px; height: 40px; }
    .metric-value { font-size: 22px; }

    .data-table th, .data-table td { padding: 10px 12px; font-size: 13px; }

    .modal-card { padding: 20px; border-radius: 14px; max-height: calc(100vh - 32px); }

    .empty-state { padding: 56px 16px; }
    .loading-state { padding: 56px 0; }

    .filter-tabs { gap: 6px; }
    .filter-tab { padding: 7px 12px; font-size: 12px; }

    .pagination button { padding: 8px 12px; font-size: 13px; }

    .btn-primary, .btn-secondary, .btn-danger { padding: 10px 16px; }
}

@media (max-width: 380px) {
    .form-card { padding: 14px; }
    .card-meta { font-size: 11px; }
}
