/* ===== AgrowTech — Agricultural Trial Management Portal ===== */
/* Design: Clean, professional, mobile-first for field use */

:root {
    --teal-50: #f0f5f5;
    --teal-100: #e0ebeb;
    --teal-200: #c1d7d7;
    --teal-300: #a2c3c3;
    --teal-400: #5a8f8f;
    --teal-500: #02353B;
    --teal-600: #022a2f;
    --teal-700: #021f24;
    --teal-800: #011a1e;
    --teal-900: #010f13;

    --earth-50: #faf8f5;
    --earth-100: #f5f0e8;
    --earth-200: #e8dcc8;
    --earth-300: #d4c4a0;
    --earth-400: #bfa878;
    --earth-500: #a08a55;
    --earth-600: #8a7344;
    --earth-700: #6e5b38;
    --earth-800: #5a4b30;
    --earth-900: #4a3e2a;

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    --teal-primary: #02353B;
    --teal-dark: #03272B;
    --teal-light: #f0f5f5;
    --red-500: #ef4444;
    --red-600: #dc2626;

    --primary: var(--teal-500);
    --primary-light: var(--teal-400);
    --primary-dark: var(--teal-800);
    --accent: var(--teal-primary);
    --bg: var(--teal-light);
    --surface: #ffffff;
    --text: var(--teal-dark);
    --text-light: var(--gray-500);
    --border: var(--gray-200);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
    --radius: 10px;
    --radius-sm: 6px;
    --sidebar-w: 260px;
    --topbar-h: 56px;
    --transition: 0.2s ease;
}

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

html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* ===== SPLASH ===== */
.splash {
    position: fixed; inset: 0; z-index: 9999;
    background: linear-gradient(135deg, var(--teal-800), var(--teal-900));
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.4s ease;
}
.splash.fade-out { opacity: 0; pointer-events: none; }
.splash-content { text-align: center; color: white; }
.splash-icon { font-size: 4rem; margin-bottom: 1rem; animation: pulse 1.5s infinite; }
.splash h1 { font-size: 2.2rem; font-weight: 700; letter-spacing: -0.02em; }
.splash p { opacity: 0.7; margin-top: 0.3rem; font-size: 0.95rem; }
.splash-loader {
    width: 40px; height: 4px; background: rgba(255,255,255,0.2);
    border-radius: 2px; margin: 1.5rem auto 0; overflow: hidden;
}
.splash-loader::after {
    content: ''; display: block; width: 50%; height: 100%;
    background: var(--teal-400); border-radius: 2px;
    animation: loader 1s ease-in-out infinite;
}
@keyframes loader { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* ===== TOPBAR ===== */
.topbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--topbar-h); background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 1rem;
    z-index: 100; gap: 0.75rem;
}
.topbar-title {
    flex: 1; font-size: 1.1rem; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 0.5rem; }

.menu-btn {
    width: 36px; height: 36px; background: none; border: none;
    cursor: pointer; display: flex; flex-direction: column;
    justify-content: center; align-items: center; gap: 4px;
    padding: 6px; border-radius: var(--radius-sm);
}
.menu-btn:hover { background: var(--gray-100); }
.menu-btn span {
    width: 20px; height: 2px; background: var(--gray-700);
    border-radius: 1px; transition: var(--transition);
}

.icon-btn {
    width: 36px; height: 36px; background: none; border: none;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); color: var(--gray-600);
}
.icon-btn:hover { background: var(--gray-100); color: var(--primary); }

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed; top: 0; left: -280px; bottom: 0;
    width: var(--sidebar-w); background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 200; transition: left 0.3s ease;
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.sidebar.open { left: 0; }
.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 199; opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

.sidebar-header {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 1.25rem 1rem; border-bottom: 1px solid var(--border);
}
.sidebar-logo { font-size: 1.8rem; }
.sidebar-brand { font-weight: 700; font-size: 1.1rem; color: var(--primary); }
.sidebar-sub { font-size: 0.75rem; color: var(--text-light); }

.sidebar-nav { list-style: none; padding: 0.5rem; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 0.75rem; border-radius: var(--radius-sm);
    text-decoration: none; color: var(--gray-600);
    font-size: 0.9rem; font-weight: 500;
    transition: var(--transition);
}
.nav-link:hover { background: var(--teal-50); color: var(--primary); }
.nav-link.active { background: var(--teal-100); color: var(--primary); font-weight: 600; }
.nav-link svg { flex-shrink: 0; }

.sidebar-footer {
    padding: 0.75rem; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 0.5rem;
}
.sidebar-footer-btn {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.5rem 0.75rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: none;
    cursor: pointer; font-size: 0.8rem; color: var(--text-light);
    transition: var(--transition);
}
.sidebar-footer-btn:hover { background: var(--gray-50); color: var(--text); }
.sidebar-version { font-size: 0.7rem; color: var(--gray-400); text-align: center; padding-top: 0.25rem; }

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-top: var(--topbar-h); padding: 1rem;
    min-height: calc(100vh - var(--topbar-h));
}

.page { display: none; animation: fadeIn 0.2s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ===== DASHBOARD ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 1.25rem; display: flex; align-items: center; gap: 1rem;
    box-shadow: var(--shadow); border-left: 4px solid transparent;
}
.stat-green { border-left-color: var(--teal-500); }
.stat-blue { border-left-color: var(--blue-500); }
.stat-amber { border-left-color: var(--amber-500); }
.stat-purple { border-left-color: var(--purple-500); }
.stat-icon { font-size: 2rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-light); margin-top: 0.2rem; }

.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}
.quick-action-btn {
    display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
    padding: 1rem; background: var(--teal-50); border: 1px solid var(--teal-200);
    border-radius: var(--radius); cursor: pointer; transition: var(--transition);
    font-size: 0.85rem; font-weight: 500; color: var(--teal-800);
}
.quick-action-btn:hover { background: var(--teal-100); transform: translateY(-1px); box-shadow: var(--shadow); }
.qa-icon { font-size: 1.5rem; }

.time-saved { padding: 0.5rem 0; }
.time-saved-bar {
    height: 12px; background: var(--gray-100); border-radius: 6px;
    overflow: hidden; margin-bottom: 0.75rem;
}
.time-saved-fill {
    height: 100%; background: linear-gradient(90deg, var(--teal-500), var(--teal-400));
    border-radius: 6px; transition: width 1s ease;
}
.time-saved-stats {
    display: flex; justify-content: space-between; font-size: 0.85rem;
    flex-wrap: wrap; gap: 0.5rem;
}
.time-saved-target { color: var(--text-light); }

/* ===== CARDS ===== */
.card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.card-wide { grid-column: span 2; }
.card-full { grid-column: 1 / -1; }
.card-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.card-actions { display: flex; gap: 0.5rem; }

.badge {
    background: var(--teal-100); color: var(--teal-700);
    padding: 0.15rem 0.5rem; border-radius: 10px;
    font-size: 0.75rem; font-weight: 600;
}

/* ===== FORMS ===== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label {
    font-size: 0.8rem; font-weight: 600; color: var(--gray-700);
    text-transform: uppercase; letter-spacing: 0.03em;
}
.form-hint { font-size: 0.75rem; color: var(--text-light); }

input[type="text"], input[type="email"], input[type="tel"],
input[type="number"], input[type="date"], input[type="url"],
select, textarea {
    padding: 0.6rem 0.75rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 0.9rem;
    background: var(--surface); color: var(--text);
    transition: border-color var(--transition);
    font-family: inherit;
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
}
.large-select { font-size: 1rem; padding: 0.75rem; }
textarea { resize: vertical; }

.checkbox-group {
    display: flex; flex-wrap: wrap; gap: 0.5rem 1rem;
}
.checkbox {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.85rem; cursor: pointer; font-weight: 400;
    text-transform: none; letter-spacing: 0;
}
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }

.search-box {
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 0 0.75rem;
    flex: 1; max-width: 320px;
}
.search-box input {
    border: none; padding: 0.5rem 0; flex: 1;
    font-size: 0.9rem; background: transparent;
}
.search-box input:focus { outline: none; box-shadow: none; }
.search-box svg { color: var(--gray-400); flex-shrink: 0; }

/* ===== BUTTONS ===== */
.btn {
    padding: 0.55rem 1rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 0.85rem;
    font-weight: 500; cursor: pointer; transition: var(--transition);
    background: var(--surface); color: var(--text);
    display: inline-flex; align-items: center; gap: 0.4rem;
    white-space: nowrap; font-family: inherit;
}
.btn:hover { background: var(--gray-50); }
.btn-primary {
    background: var(--primary); color: white; border-color: var(--primary);
}
.btn-primary:hover { background: var(--teal-800); }
.btn-secondary { background: var(--gray-100); }
.btn-success { background: var(--teal-500); color: white; border-color: var(--teal-500); }
.btn-success:hover { background: var(--teal-600); }
.btn-danger { background: var(--red-500); color: white; border-color: var(--red-500); }
.btn-danger:hover { background: var(--red-600); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }
.btn-large { padding: 0.75rem 1.5rem; font-size: 1rem; }

.filter-group { display: flex; gap: 0.5rem; }
.filter-group select { padding: 0.45rem 0.6rem; font-size: 0.82rem; }

/* ===== PAGE TOOLBAR ===== */
.page-toolbar {
    display: flex; align-items: center; gap: 0.75rem;
    margin-bottom: 1rem; flex-wrap: wrap;
}

/* ===== TRIALS LIST ===== */
.trials-list { display: flex; flex-direction: column; gap: 0.75rem; }

.trial-card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1rem 1.25rem;
    display: flex; align-items: center; gap: 1rem;
    cursor: pointer; transition: var(--transition);
    border-left: 4px solid var(--gray-300);
}
.trial-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.trial-card.status-planning { border-left-color: var(--gray-400); }
.trial-card.status-active { border-left-color: var(--teal-500); }
.trial-card.status-data-collection { border-left-color: var(--blue-500); }
.trial-card.status-analysis { border-left-color: var(--amber-500); }
.trial-card.status-complete { border-left-color: var(--purple-500); }

.trial-info { flex: 1; min-width: 0; }
.trial-name { font-weight: 600; font-size: 1rem; margin-bottom: 0.2rem; }
.trial-meta {
    display: flex; gap: 1rem; font-size: 0.8rem; color: var(--text-light);
    flex-wrap: wrap;
}
.trial-status {
    padding: 0.2rem 0.6rem; border-radius: 12px;
    font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.03em; white-space: nowrap;
}
.trial-status.planning { background: var(--gray-100); color: var(--gray-600); }
.trial-status.active { background: var(--teal-100); color: var(--teal-700); }
.trial-status.data-collection { background: #dbeafe; color: #1d4ed8; }
.trial-status.analysis { background: #fef3c7; color: #92400e; }
.trial-status.complete { background: #ede9fe; color: #6d28d9; }

.trial-card-actions {
    display: flex; gap: 0.4rem; align-items: center;
    flex-wrap: wrap; flex-shrink: 0;
}
.trial-card-actions .btn {
    padding: 0.3rem 0.7rem; font-size: 0.78rem;
}
.btn.btn-danger {
    background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
}
.btn.btn-danger:hover { background: #fee2e2; }

.trial-actions {
    display: flex; gap: 0.5rem; flex-shrink: 0;
}

/* ===== CLIENTS GRID ===== */
.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 1.25rem;
}
.client-card {
    background: var(--surface); border-radius: 10px;
    box-shadow: var(--shadow); padding: 1.5rem 1.5rem 1.25rem;
    border-top: 3px solid #02353B;
    transition: var(--transition);
    display: flex; flex-direction: column;
}
.client-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.client-name { font-weight: 700; font-size: 1.1rem; margin-bottom: 0.5rem; color: #03272B; }
.client-detail {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.85rem; color: var(--text-light); margin-bottom: 0.3rem;
}
.client-trials { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.client-trial-badge {
    display: inline-block; padding: 0.15rem 0.5rem;
    background: var(--teal-50); border-radius: 8px;
    font-size: 0.75rem; color: var(--teal-700); margin: 0.15rem;
}
.client-card-actions {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}
.client-card-actions .btn {
    padding: 0.45rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 4px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.client-card-actions .btn-primary {
    background: #02353B; color: white; border-color: #02353B;
    grid-column: 1 / -1;
}
.client-card-actions .btn-primary:hover { background: #03272B; }
.client-card-actions .btn-danger { background: transparent; color: #b91c1c; border: 1px solid #fecaca; }
.client-card-actions .btn-danger:hover { background: #fef2f2; }

/* ===== TUNNELS GRID ===== */
.tunnels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}
.tunnel-card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.25rem;
}
.tunnel-name { font-weight: 600; font-size: 1.05rem; margin-bottom: 0.25rem; }
.tunnel-dims { font-size: 0.85rem; color: var(--text-light); margin-bottom: 0.75rem; }
.tunnel-visual {
    display: grid; gap: 4px; margin: 0.75rem 0;
    background: var(--earth-100); border-radius: var(--radius-sm);
    padding: 0.75rem;
}
.tunnel-table {
    background: var(--teal-100); border: 1px solid var(--teal-300);
    border-radius: 4px; padding: 0.5rem; text-align: center;
    font-size: 0.7rem; color: var(--teal-800); min-height: 40px;
    display: flex; align-items: center; justify-content: center;
}
.tunnel-sensors {
    display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.5rem;
}
.sensor-badge {
    padding: 0.15rem 0.45rem; background: var(--blue-500);
    color: white; border-radius: 6px; font-size: 0.68rem;
}

/* ===== PRODUCTS LIST ===== */
.products-list { display: flex; flex-direction: column; gap: 0.75rem; }
.product-card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1rem 1.25rem;
    display: flex; align-items: center; gap: 1rem;
}
.product-info { flex: 1; }
.product-name { font-weight: 600; }
.product-meta { font-size: 0.82rem; color: var(--text-light); }

/* ===== RBD DESIGNER ===== */
.rbd-container { display: flex; flex-direction: column; gap: 1rem; }

.treatment-inputs { display: flex; flex-direction: column; gap: 0.5rem; }
.treatment-input {
    display: flex; align-items: center; gap: 0.5rem;
}
.treatment-input .color-dot {
    width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
}
.treatment-input input {
    flex: 1; padding: 0.45rem 0.6rem; font-size: 0.85rem;
}
.treatment-input .treatment-label {
    font-size: 0.78rem; color: var(--text-light); min-width: 20px;
}

.rbd-visual {
    display: flex; flex-direction: column; gap: 1.5rem;
}
.rbd-block {
    background: var(--earth-100); border-radius: var(--radius);
    padding: 1rem;
}
.rbd-block-title {
    font-weight: 600; font-size: 0.85rem; margin-bottom: 0.75rem;
    color: var(--gray-700);
}
.rbd-block-grid { display: grid; gap: 6px; }
.rbd-plot {
    padding: 0.6rem; border-radius: 6px; text-align: center;
    font-size: 0.78rem; font-weight: 600; color: white;
    min-height: 50px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
}
.rbd-plot-label { font-size: 0.65rem; opacity: 0.85; font-weight: 400; }

.rbd-legend {
    display: flex; flex-wrap: wrap; gap: 0.75rem; padding: 1rem 0;
}
.rbd-legend-item {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.82rem;
}
.rbd-legend-color {
    width: 14px; height: 14px; border-radius: 3px;
}

.rbd-table-view { overflow-x: auto; }
.rbd-table-view table {
    width: 100%; border-collapse: collapse; font-size: 0.82rem;
}
.rbd-table-view th, .rbd-table-view td {
    padding: 0.5rem 0.75rem; border: 1px solid var(--border);
    text-align: center;
}
.rbd-table-view th {
    background: var(--gray-50); font-weight: 600; font-size: 0.78rem;
    text-transform: uppercase; letter-spacing: 0.03em;
}

/* ===== Spatial RBD painter ===== */
.srbd-palette { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.srbd-palette button {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.6rem; font-size: 0.78rem;
    background: white; border: 1px solid var(--border); border-radius: 6px;
    cursor: pointer;
}
.srbd-palette button.active {
    border-color: var(--gray-700); box-shadow: 0 0 0 2px var(--gray-700) inset;
}
.srbd-palette .swatch { width: 14px; height: 14px; border-radius: 3px; }

.srbd-wrap {
    margin-top: 1rem; user-select: none;
    display: flex; gap: 12px; align-items: flex-start;
    overflow-x: auto;
}
.srbd-plot-block { flex: 1; min-width: 0; }
.srbd-axis-n {
    font-size: 0.7rem; color: var(--text-light);
    text-align: right; margin-left: auto;
}
.srbd-plot-title {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.78rem; color: var(--gray-700);
    margin-bottom: 0.35rem; padding: 0 0.15rem;
}
.srbd-plot-meta { color: var(--text-light); font-size: 0.72rem; margin-left: auto; }
.srbd-grid {
    display: grid; gap: 1px; padding: 3px;
    background: var(--gray-100); border-radius: 4px;
}
.srbd-cell {
    aspect-ratio: 1 / 1; border-radius: 2px; min-width: 18px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.62rem; font-weight: 700; color: white;
    cursor: pointer; transition: transform 0.05s;
}
.srbd-cell.empty { background: white; border: 1px solid var(--border); color: var(--text-light); }
.srbd-cell.empty:hover { background: var(--gray-50); }
.srbd-cell.filled:hover { transform: scale(1.06); }
.srbd-cell.locked {
    cursor: not-allowed; opacity: 0.55;
    background-image: repeating-linear-gradient(45deg,
        rgba(255,255,255,0.5) 0,
        rgba(255,255,255,0.5) 3px,
        transparent 3px,
        transparent 6px);
    background-blend-mode: overlay;
}
.srbd-cell.locked:hover { opacity: 0.75; }
.srbd-cell.srbd-table-edge { margin-left: 6px; }
.srbd-occupancy {
    margin: 0.5rem 0 1rem; padding: 0.6rem 0.9rem;
    background: #f0f5f5; border-left: 3px solid #02353B;
    border-radius: 4px; font-size: 0.85rem; color: #03272B;
}
.srbd-table-labels {
    display: grid; gap: 6px; margin-top: 0.5rem;
    font-size: 0.78rem; font-weight: 600; color: var(--gray-700);
    text-align: center;
}
.srbd-summary {
    margin-top: 1rem; padding: 0.75rem 1rem;
    background: var(--gray-50); border-radius: 6px;
    font-size: 0.82rem; color: var(--gray-700);
}
.srbd-summary .row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.srbd-summary .chip {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.2rem 0.5rem; background: white; border-radius: 4px;
    border: 1px solid var(--border);
}
.srbd-summary .swatch { width: 10px; height: 10px; border-radius: 2px; }

/* ===== DATA CAPTURE ===== */
.capture-container { display: flex; flex-direction: column; gap: 1rem; }

.capture-plot-header {
    background: var(--teal-50); padding: 0.75rem 1rem;
    border-radius: var(--radius-sm); margin-bottom: 1rem;
    display: flex; justify-content: space-between; align-items: center;
}
.capture-plot-name { font-weight: 600; font-size: 1rem; }
.capture-plot-treatment {
    font-size: 0.82rem; padding: 0.2rem 0.6rem;
    border-radius: 8px; font-weight: 500;
}

.capture-field {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0; border-bottom: 1px solid var(--gray-100);
}
.capture-field label {
    flex: 1; font-size: 0.88rem; font-weight: 500;
}
.capture-field input {
    width: 120px; text-align: right; padding: 0.45rem 0.6rem;
}
.capture-field .unit {
    font-size: 0.78rem; color: var(--text-light); min-width: 30px;
}

.capture-actions {
    display: flex; gap: 0.75rem; margin-top: 1rem; justify-content: flex-end;
}
.progress-indicator {
    font-size: 0.82rem; color: var(--text-light); font-weight: 500;
}

/* ===== REPORTS ===== */
.reports-container { display: flex; flex-direction: column; gap: 1rem; }
.report-content {
    font-family: 'Times New Roman', Georgia, serif;
    line-height: 1.6; max-width: 800px;
}
.report-content h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.report-content p { margin: 0 0 0.75rem; }
.report-content div[data-editable] + div[data-editable] { margin-top: 0.6rem; }
.report-content h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; color: var(--teal-800); border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.report-content h3 { font-size: 1rem; margin: 1rem 0 0.3rem; }
.report-content table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; font-size: 0.85rem; font-family: inherit; }
.report-content th, .report-content td { padding: 0.4rem 0.6rem; border: 1px solid var(--border); text-align: left; }
.report-content th { background: var(--gray-50); font-weight: 600; }
.report-content .report-header { text-align: center; margin-bottom: 2rem; padding-bottom: 1rem; border-bottom: 2px solid var(--teal-700); }
.report-content .report-header p { color: var(--text-light); font-size: 0.9rem; }

/* AgrowTech branded report */
.report-content .agrowtech-header {
    border-bottom: 3px solid #02353B;
    padding: 0.5rem 0 1.25rem;
    margin-bottom: 1.75rem;
}
.report-content .agrowtech-logo {
    display: block; margin: 0 auto 1rem; max-width: 160px; height: auto;
}
.report-content .agrowtech-header h1 {
    color: #03272B; font-size: 1.55rem; margin: 0 0 0.75rem;
    font-weight: 700;
}
.report-content .agrowtech-header-meta {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 0 1.25rem;
    font-size: 0.88rem; color: #03272B;
    border-top: 1px solid #d6e4e3; border-bottom: 1px solid #d6e4e3;
    padding: 0.45rem 0; margin: 0.5rem 0;
}
.report-content .agrowtech-prepared {
    color: #02353B; font-size: 0.82rem; margin: 0.5rem 0 0;
    letter-spacing: 0.02em; text-transform: uppercase;
}
.report-content h2 { color: #02353B; border-bottom-color: #d6e4e3; }
.report-content h3 { color: #03272B; }

/* ===== Report page sections & page numbers =====
   Each numbered top-level section reads as its own page. A labelled divider
   marks where one page ends and the next begins and shows the page number.
   In print, each section also starts on a fresh physical page (see @media print). */
.report-content { counter-reset: report-page; }
.report-content h2::before {
    counter-increment: report-page;
    content: "Page " counter(report-page);
    display: block;
    margin: 2.5rem -1.5rem 1.3rem;
    padding: 0.45rem 1.5rem 0.4rem 0;
    border-top: 2px dashed #b9d3d2;
    color: #02353B;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    text-align: right;
}
.report-content h2:first-of-type::before {
    border-top: none;
    margin-top: 0.5rem;
}
.report-content .report-interp {
    font-size: 0.93rem; line-height: 1.65; margin: 0.6rem 0;
    padding: 0.7rem 1rem; background: #f0f5f5;
    border-left: 3px solid #02353B; border-radius: 4px;
}
.report-content .report-caption {
    font-size: 0.86rem; color: #03272B; margin: 0.25rem 0 1.25rem;
}
/* Read mode (default + what the client sees) = looks like normal prose */
.report-content .report-discussion {
    margin: 0.6rem 0 1rem;
    padding: 0;
    background: transparent;
    border: none;
}
.report-content .report-discussion-label {
    display: none;  /* hidden in read mode — client-facing report stays clean */
}
.report-content .report-discussion-body {
    font-size: 0.95rem; line-height: 1.65; color: #1f2937;
}

/* Edit mode = show the dashed boxes + labels so Marguerite knows what's editable */
.report-content.editing .report-discussion {
    margin: 0.75rem 0 1.5rem;
    padding: 0.75rem 1rem;
    background: #f0f5f5;
    border: 1px dashed #02353B;
    border-radius: 4px;
}
.report-content.editing .report-discussion-label {
    display: block;
    font-size: 0.72rem; font-weight: 700;
    color: #02353B; letter-spacing: 0.06em;
    text-transform: uppercase; margin-bottom: 0.35rem;
}
/* Print = always treat as read mode (no edit chrome) even if user prints from edit mode */
@media print {
    .report-content .report-discussion {
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
        margin: 0.6rem 0 1rem !important;
    }
    .report-content .report-discussion-label { display: none !important; }
}

/* Edit mode for reports */
.report-edit-controls {
    display: flex; gap: 0.5rem; flex-wrap: wrap;
    padding: 0.75rem; background: #f0f5f5;
    border: 1px solid #c4d4d3; border-radius: 6px;
    margin-bottom: 1rem;
}
.report-content.editing { outline: 2px dashed #02353B; outline-offset: 4px; }
.report-content.editing [data-editable] {
    position: relative; padding-right: 1.75rem;
}
.report-content.editing [data-editable]:hover {
    background: #fef9e7; border-radius: 3px;
}
.report-content.editing [data-editable]::after {
    content: "×"; position: absolute; top: 0; right: 0.25rem;
    color: #b00020; font-size: 1.1rem; font-weight: 700;
    cursor: pointer; padding: 0 0.3rem;
    opacity: 0; transition: opacity 0.15s;
}
.report-content.editing [data-editable]:hover::after { opacity: 1; }
.report-content.editing [contenteditable="true"]:focus {
    outline: 2px solid #02353B; outline-offset: 2px;
    background: white;
}
/* Per-row delete affordance: hover a table row in edit mode to reveal a × on
   the right edge — lets Marguerite remove a single "line" from the 1.1 table. */
.report-content.editing table tr { position: relative; }
.report-content.editing table tr:hover { background: #fef9e7; }
.report-content.editing table tr:hover td:last-child::after {
    content: "×"; position: absolute; right: 4px; top: 50%;
    transform: translateY(-50%);
    color: #b00020; font-size: 1.05rem; font-weight: 700;
    cursor: pointer; padding: 0 0.25rem;
}

.dosage-preset { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.dosage-preset .btn.active { background: var(--teal-100); border-color: var(--teal-500); color: var(--teal-700); }
.dosage-inputs { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ===== CALENDAR ===== */
.calendar-container { display: flex; flex-direction: column; gap: 1rem; }
.calendar-grid {
    display: grid; grid-template-columns: repeat(7, 1fr);
    gap: 1px; background: var(--border);
}
.cal-header {
    background: var(--gray-50); padding: 0.5rem;
    text-align: center; font-size: 0.75rem; font-weight: 600;
    text-transform: uppercase; color: var(--text-light);
}
.cal-day {
    background: var(--surface); padding: 0.5rem;
    min-height: 70px; cursor: pointer; transition: var(--transition);
    position: relative;
}
.cal-day:hover { background: var(--teal-50); }
.cal-day.today { background: var(--teal-50); }
.cal-day.other-month { opacity: 0.4; }
.cal-day.selected { background: var(--teal-100); outline: 2px solid var(--teal-500); }
.cal-day-num {
    font-size: 0.82rem; font-weight: 500; margin-bottom: 0.25rem;
}
.cal-day.today .cal-day-num {
    background: var(--primary); color: white; width: 24px; height: 24px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.cal-event {
    font-size: 0.65rem; padding: 1px 4px; border-radius: 3px;
    margin-bottom: 1px; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis;
}
.cal-event.measurement { background: var(--teal-100); color: var(--teal-800); }
.cal-event.application { background: #dbeafe; color: #1d4ed8; }
.cal-event.deadline { background: #fef3c7; color: #92400e; }

/* Gantt Chart */
.gantt-chart { min-height: 120px; position: relative; }
.gantt-empty { padding: 2rem; text-align: center; color: var(--gray-500); }
.gantt-header {
    display: flex; border-bottom: 2px solid var(--gray-200); position: sticky; top: 0;
    background: #fff; z-index: 2;
}
.gantt-label-col {
    min-width: 180px; max-width: 180px; flex-shrink: 0;
    font-weight: 600; font-size: 0.78rem; color: var(--gray-600);
    padding: 0.5rem 0.75rem; border-right: 1px solid var(--gray-200);
}
.gantt-timeline-header {
    display: flex; flex: 1; overflow: hidden;
}
.gantt-month-col {
    text-align: center; font-size: 0.72rem; font-weight: 600; color: var(--gray-500);
    padding: 0.4rem 0; border-right: 1px solid var(--gray-100); box-sizing: border-box;
}
.gantt-row {
    display: flex; border-bottom: 1px solid var(--gray-50); min-height: 40px;
}
.gantt-row:hover { background: var(--teal-50); }
.gantt-row-label {
    min-width: 180px; max-width: 180px; flex-shrink: 0;
    padding: 0.5rem 0.75rem; font-size: 0.8rem; font-weight: 500;
    border-right: 1px solid var(--gray-200); display: flex; flex-direction: column;
    justify-content: center;
}
.gantt-row-label small { color: var(--gray-500); font-weight: 400; font-size: 0.7rem; }
.gantt-row-timeline {
    flex: 1; position: relative; display: flex; overflow: hidden;
}
.gantt-col {
    border-right: 1px solid var(--gray-50); box-sizing: border-box; flex-shrink: 0;
}
.gantt-col.today-col { background: #fef3c7; }
.gantt-bar {
    position: absolute; height: 22px; top: 50%; transform: translateY(-50%);
    border-radius: 4px; z-index: 1; opacity: 0.85; min-width: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.65rem; color: #fff; font-weight: 600; overflow: hidden;
    white-space: nowrap; text-overflow: ellipsis; padding: 0 4px;
}
.gantt-bar:hover { opacity: 1; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.gantt-milestone {
    position: absolute; top: 50%; transform: translate(-50%, -50%);
    width: 8px; height: 8px; border-radius: 50%; z-index: 2;
    border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}
.gantt-today-line {
    position: absolute; top: 0; bottom: 0; width: 2px;
    background: #dc2626; z-index: 3; opacity: 0.6;
}
@media (max-width: 768px) {
    .gantt-label-col, .gantt-row-label { min-width: 120px; max-width: 120px; }
}

.schedule-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.6rem 0; border-bottom: 1px solid var(--gray-100);
}
.schedule-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.schedule-info { flex: 1; }
.schedule-title { font-weight: 500; font-size: 0.9rem; }
.schedule-time { font-size: 0.78rem; color: var(--text-light); }

/* ===== MODALS ===== */
.modal {
    position: fixed; inset: 0; z-index: 300;
    background: rgba(0,0,0,0.5); display: none;
    align-items: flex-start; justify-content: center;
    padding: 2rem 1rem; overflow-y: auto;
}
.modal.open { display: flex; }
.modal-content {
    background: var(--surface); border-radius: var(--radius);
    width: 100%; max-width: 560px; box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
}
.modal-large { max-width: 720px; }
@keyframes slideUp { from { transform: translateY(10px); opacity: 0; } }

.modal-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
    width: 32px; height: 32px; border: none; background: none;
    font-size: 1.5rem; cursor: pointer; color: var(--gray-400);
    border-radius: var(--radius-sm); display: flex;
    align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--gray-100); color: var(--text); }
.modal-body { padding: 1.25rem; max-height: 60vh; overflow-y: auto; }
.modal-footer {
    padding: 1rem 1.25rem; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 0.75rem;
}

/* ===== FIELD TRIALS ===== */
.fieldtrials-grid { display: flex; flex-direction: column; gap: 1rem; }

/* ===== TOAST ===== */
.toast-container {
    position: fixed; bottom: 1rem; right: 1rem; z-index: 400;
    display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
    background: var(--gray-800); color: white; padding: 0.75rem 1rem;
    border-radius: var(--radius-sm); font-size: 0.85rem;
    box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease;
    max-width: 320px;
}
.toast.success { background: var(--teal-700); }
.toast.error { background: var(--red-600); }
.toast.warning { background: var(--amber-600); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center; padding: 2rem 1rem; color: var(--text-light);
}
.empty-state.small { padding: 1rem; }
.empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state h3 { color: var(--text); margin-bottom: 0.3rem; }
.empty-state p { margin-bottom: 1rem; font-size: 0.9rem; }
.help-text { font-size: 0.88rem; color: var(--text-light); margin-bottom: 1rem; }

/* ===== TASK ITEMS ===== */
.task-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.6rem 0; border-bottom: 1px solid var(--gray-100);
}
.task-item:last-child { border-bottom: none; }
.task-dot {
    width: 8px; height: 8px; border-radius: 50%;
    flex-shrink: 0;
}
.task-dot.urgent { background: var(--red-500); }
.task-dot.soon { background: var(--amber-500); }
.task-dot.normal { background: var(--teal-500); }
.task-info { flex: 1; }
.task-title { font-size: 0.88rem; font-weight: 500; }
.task-due { font-size: 0.75rem; color: var(--text-light); }

.activity-item {
    display: flex; gap: 0.75rem; padding: 0.5rem 0;
    border-bottom: 1px solid var(--gray-100); font-size: 0.85rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-time { color: var(--text-light); white-space: nowrap; font-size: 0.78rem; min-width: 60px; }

/* ===== RESPONSIVE ===== */
@media (min-width: 768px) {
    .sidebar { left: 0; top: 0; }
    .sidebar-overlay { display: none !important; }
    .main-content { margin-left: var(--sidebar-w); }
    .topbar { left: var(--sidebar-w); }
    .menu-btn { display: none; }
    .modal-body { max-height: 70vh; }
}

/* ===== AIRTABLE SYNC UI ===== */
.sync-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-bottom: 20px;
    border-radius: 8px;
    font-weight: 500;
}

.sync-status.status-enabled {
    background-color: #dcfce7;
    color: #15803d;
}

.sync-status.status-disabled {
    background-color: #fee2e2;
    color: #991b1b;
}

.sync-status-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: currentColor;
}

.sync-status.status-enabled .sync-status-dot {
    background-color: #02353B;
}

.sync-status.status-disabled .sync-status-dot {
    background-color: #ef4444;
}

.form-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.form-actions .btn {
    flex: 1;
    min-width: 140px;
}

.form-actions .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sync-message {
    padding: 12px;
    border-radius: 8px;
    margin-top: 16px;
    font-size: 14px;
    border-left: 4px solid transparent;
}

.sync-message.sync-message-info {
    background-color: #dbeafe;
    color: #1e40af;
    border-left-color: #02353B;
}

.sync-message.sync-message-success {
    background-color: #dcfce7;
    color: #15803d;
    border-left-color: #02353B;
}

.sync-message.sync-message-error {
    background-color: #fee2e2;
    color: #991b1b;
    border-left-color: #ef4444;
}

.sync-stats {
    margin-top: 20px;
    padding: 12px;
    background-color: #f0fdf4;
    border-radius: 8px;
    border-left: 4px solid #02353B;
}

.sync-stats h4 {
    margin: 0 0 8px 0;
    color: #15803d;
    font-size: 14px;
}

.sync-stats p {
    margin: 0;
    color: #374151;
    font-size: 13px;
    line-height: 1.5;
}

@media (max-width: 767px) {
    .card-wide { grid-column: span 1; }
    .stat-card { padding: 1rem; }
    .stat-icon { font-size: 1.5rem; }
    .stat-value { font-size: 1.4rem; }
    .filter-group { flex-wrap: wrap; }
    .trial-card { flex-direction: column; align-items: flex-start; }
    .trial-actions { width: 100%; }
    .page-toolbar { flex-direction: column; align-items: stretch; }
    .search-box { max-width: none; }
}

@media (max-width: 480px) {
    html { font-size: 14px; }
    .quick-actions { grid-template-columns: repeat(3, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr 1fr; }
}

/* ===== PRINT ===== */
@media print {
    @page { size: A4; margin: 18mm 16mm; }
    /* Force browsers to print background colors (treatment bars, callouts, brand header) */
    *, *::before, *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    body { background: white !important; }
    /* Hide all app chrome */
    .topbar, .sidebar, .sidebar-overlay, .page-toolbar,
    .quick-actions, .btn, .modal, .toast-container,
    .nav, header, footer, .card-actions,
    #reportEditControls, .report-edit-controls { display: none !important; }
    /* Hide every page except reports, and hide every card on reports except the preview */
    .page { display: none !important; }
    #page-reports { display: block !important; }
    #page-reports .card { display: none !important; }
    #page-reports #reportPreview { display: block !important; }
    .main-content { margin: 0 !important; padding: 0 !important; }
    .card, #reportPreview {
        box-shadow: none !important; border: none !important;
        background: white !important; padding: 0 !important;
    }
    .card-header { display: none !important; }
    .card-body { padding: 0 !important; }
    .report-content { max-width: none !important; font-size: 11pt; }
    .report-content h1 { font-size: 18pt; }
    /* Each numbered section starts on a fresh physical page. */
    .report-content h2 { font-size: 13pt; page-break-before: always; page-break-after: avoid; }
    .report-content h2:first-of-type { page-break-before: avoid; }
    /* The "Page N" label sits at the top of each printed page as a running number. */
    .report-content h2::before { margin: 0 0 0.9rem; padding-top: 0; border-top: none; }
    .report-content h3 { font-size: 11pt; page-break-after: avoid; }
    .report-content table { page-break-inside: avoid; font-size: 9.5pt; }
    .report-content img.agrowtech-logo { max-width: 130px; }
    .report-content .report-interp { page-break-inside: avoid; }
}
