:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #166534;
    --primary-text: #ffffff;
    --secondary: #e5e7eb;
    --secondary-text: #1f2937;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --success: #14532d;
    --success-bg: #f0fdf4;
    --border: #d1d5db;
    --radius: 0.5rem;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --nav-height: 3.5rem;
    --max-width: 64rem;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Top nav */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--nav-height);
    padding: 0 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.brand {
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    font-size: 1.125rem;
    white-space: nowrap;
}

.domain-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    overflow-x: auto;
}

.nav-link {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    white-space: nowrap;
}

.nav-link:hover {
    background: var(--bg);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.lang-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.lang-btn {
    padding: 0.375rem 0.625rem;
    border: none;
    background: var(--surface);
    color: var(--text);
    font-size: 0.75rem;
    cursor: pointer;
}

.lang-btn.active {
    background: var(--primary);
    color: var(--primary-text);
}

/* Sub-header (farm switcher) */
.sub-header {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.75rem 1rem;
}

.farm-switcher {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.farm-switcher label {
    font-size: 0.875rem;
    color: var(--muted);
}

.farm-switcher select {
    min-width: 12rem;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 0.875rem;
}

/* Breadcrumbs */
.breadcrumbs {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

.breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.875rem;
    color: var(--muted);
}

.breadcrumbs li:not(:last-child)::after {
    content: "/";
    margin-left: 0.5rem;
    color: var(--border);
}

.breadcrumbs a {
    color: var(--muted);
    text-decoration: none;
}

.breadcrumbs a:hover {
    color: var(--text);
}

/* Main layout */
.app-main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.card + .card {
    margin-top: 1rem;
}

/* Wizard steps (farm creation) */
.wizard-steps {
    display: flex;
    gap: 1rem;
    margin: 1rem 0 1.5rem;
    font-size: 0.875rem;
    color: var(--muted);
}

.wizard-steps span {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
}

.wizard-steps span.active {
    font-weight: 600;
    color: var(--text);
    background: var(--bg);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-text);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--secondary-text);
    border-color: var(--border);
}

/* Forms */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--nav-height));
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 24rem;
}

.login-card h1 {
    margin: 0 0 0.25rem;
}

.hint {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.form-field {
    margin-bottom: 1rem;
}

.form-field label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.form-field.required label {
    font-weight: 600;
}

/* Multi-select target picker on the task form */
.target-picker {
    grid-column: 1 / -1;
}

.target-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem 1rem;
    max-height: 10rem;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.target-option {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
}

.target-option input {
    width: auto;
    margin: 0;
}

.field-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.field-hint.warning {
    color: var(--danger);
    font-weight: 500;
}

.form-legend {
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 1rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.form-inline input,
.form-inline select {
    min-width: 8rem;
}

.error-text {
    color: var(--danger);
    font-size: 0.875rem;
}

.muted {
    color: var(--muted);
    font-size: 0.875rem;
}

/* Error-code list */
.code-list {
    padding-left: 1.25rem;
}

.code-list li {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

/* Toasts */
.toast-stack {
    position: fixed;
    top: calc(var(--nav-height) + 0.5rem);
    right: 0.75rem;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 24rem;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.875rem;
    pointer-events: auto;
}

.toast-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.toast-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid #bbf7d0;
}

.toast button {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.page-actions {
    display: flex;
    gap: 0.5rem;
}

/* Filter bar */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 1rem;
    align-items: end;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filter-bar .form-field {
    margin: 0;
}

/* Data tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    margin-top: 1rem;
}

.data-table th,
.data-table td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--bg);
    font-weight: 600;
}

.data-table a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* Detail grid */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

/* Expandable admin error detail */
.error-detail-row > td {
    padding: 0.75rem 1rem;
    background: var(--secondary, #f4f4f5);
}

.error-detail-row .detail-grid {
    margin-top: 0;
}

.error-detail .detail-value {
    word-break: break-all;
}

/* Inline expandable row inside the sessions table */
.session-detail-row > td {
    padding: 0.75rem 1rem;
    background: var(--secondary, #f4f4f5);
}

.session-detail h4 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.detail-label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.detail-value {
    font-weight: 500;
    overflow-wrap: anywhere;
}

/* Stat / summary cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 0.9rem;
    box-shadow: var(--shadow);
    min-width: 0;
}

.summary-label {
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.summary-value {
    display: block;
    font-size: 1.15rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-top: 0.15rem;
    overflow-wrap: anywhere;
    overflow-wrap: anywhere;
}

.summary-card-accent {
    border-color: var(--primary);
    background: var(--success-bg);
}

.summary-card-accent .summary-value {
    color: var(--primary);
}

.summary-card-danger .summary-value {
    color: var(--danger);
}

.kpi-sections {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.kpi-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
}

.kpi-section .summary-cards {
    margin-top: 0.75rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    background: var(--secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

/* Tabs */
.tabs {
    margin-top: 0.5rem;
}

.tab-bar {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.tab-button {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.875rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab-button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-panel {
    min-height: 6rem;
}

/* Store tab navigation */
.store-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.nav-tab {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--secondary);
    color: var(--secondary-text);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
}

.nav-tab:hover {
    background: var(--bg);
}

.nav-tab.active {
    background: var(--primary);
    color: var(--primary-text);
    border-color: var(--primary);
}

.back-tab {
    background: var(--surface);
}

/* Button helpers */
.btn-small {
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
}

.btn-danger {
    background: var(--danger);
    color: var(--primary-text);
    border-color: var(--danger);
}

.button-group {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Admin management cards */
.admin-links {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.admin-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    text-decoration: none;
    color: var(--text);
    box-shadow: var(--shadow);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.admin-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.admin-card h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--primary);
}

.admin-card p {
    margin: 0;
    font-size: 0.875rem;
    flex-grow: 1;
}

.admin-card-action {
    align-self: flex-start;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary);
}

/* Genealogy tree */
.genealogy-tree {
    list-style: none;
    margin: 0;
    padding-left: 1rem;
    border-left: 2px solid var(--border);
}

.genealogy-tree:first-child {
    padding-left: 0;
    border-left: none;
}

.genealogy-node {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg);
    border-radius: var(--radius);
}

.genealogy-meta {
    font-size: 0.75rem;
    color: var(--muted);
}

/* Form grid */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 1rem;
}

.form-grid .form-field {
    margin: 0;
}

/* Daily totals */
.daily-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.total-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

/* Entry grid */
.entry-grid-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
}

.entry-grid {
    min-width: 24rem;
}

.entry-grid th,
.entry-grid td {
    padding: 0.375rem 0.5rem;
}

.qty-input {
    width: 5rem;
    padding: 0.375rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

/* Status message */
.message {
    color: var(--success);
    font-size: 0.875rem;
    margin-top: 0.75rem;
}

/* Utility */
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: var(--bg);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

/* W4 health + inventory additions */

.banner {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.875rem;
}

.banner-warning {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: #fecaca;
}

.two-column {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: 1.5rem;
}

.form-section {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.form-section h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}

.inline-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.inline-form .message {
    margin: 0;
}

/* W5 operations + dashboard additions */

.severity-critical-row {
    background: var(--danger-bg);
}

.severity-high-row {
    background: #fff7ed;
}

.severity-low-row,
.severity-normal-row {
    background: transparent;
}

/* W6 offline + feedback components */

.offline-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    border-radius: var(--radius);
    background: var(--secondary);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.offline-badge.offline {
    background: var(--danger);
    color: #fff;
}

.loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.empty-state {
    padding: 1rem 0;
    text-align: center;
}

/* Mobile bottom navigation */
.bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: space-around;
    height: 3.5rem;
    padding: 0 0.25rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.08);
}

.bottom-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    min-width: 3rem;
    padding: 0.25rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.625rem;
}

.bottom-nav-link:hover,
.bottom-nav-link[aria-current="page"] {
    color: var(--primary);
}

.bottom-nav-icon {
    font-size: 1.25rem;
    line-height: 1;
}

/* Accessibility */

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    top: -2.5rem;
    left: 0.5rem;
    z-index: 60;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
}

.skip-link:focus {
    top: 0.5rem;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* W7 feedback + admin */

.feedback-fab {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 45;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--primary-text);
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: var(--shadow);
    cursor: pointer;
    max-width: calc(100vw - 2rem);
}

.feedback-card {
    bottom: 4rem;
}

.feedback-card {
    position: fixed;
    right: 1rem;
    bottom: 4rem;
    z-index: 45;
    width: min(24rem, calc(100vw - 2rem));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.feedback-card textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    resize: vertical;
}

.table-wrapper {
    overflow-x: auto;
}

.table-wrapper .data-table {
    min-width: 48rem;
}

/* Kanban board */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: 1rem;
    align-items: start;
}

.kanban-column {
    background: var(--surface, #f8fafc);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    min-height: 12rem;
}

.kanban-column h3 {
    font-size: 0.875rem;
    margin: 0 0 0.75rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}

.kanban-card {
    display: block;
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary, #166534);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.kanban-card-title {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-decoration: none;
    color: var(--link, #1d4ed8);
}

.kanban-card-title:hover {
    text-decoration: underline;
}

.kanban-card-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    margin-bottom: 0.2rem;
}

.kanban-card-meta .meta-label {
    color: var(--text-muted, var(--muted));
    min-width: 4.5rem;
    text-transform: capitalize;
}

.kanban-card .tag {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.kanban-card .meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.kanban-card .badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius);
    background: var(--surface);
    margin-top: 0.25rem;
}

/* Target / priority chips on the task board and table */
.target-badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    background: var(--secondary, #eef2f7);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.priority-badge {
    display: inline-block;
    font-size: 0.72rem;
    padding: 0.1rem 0.5rem;
    border-radius: 9999px;
    text-transform: capitalize;
}

.priority-low { background: #e5e7eb; color: #374151; }
.priority-normal { background: #dbeafe; color: #1e40af; }
.priority-high { background: #fef3c7; color: #92400e; }
.priority-critical { background: #fee2e2; color: #b91c1c; }

/* Recurrence picker on the task form */
.recurrence-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.recurrence-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.recurrence-toggle input {
    width: auto;
    margin: 0;
}

.recurrence-every {
    width: 5rem;
}

.recurrence-unit {
    width: auto;
}

/* Task stock-effect (consume/add) controls */
.stock-effect-field {
    grid-column: 1 / -1;
}

.stock-effect-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 0 1rem;
    margin-top: 0.25rem;
}

/* Per-item stock movement rows on the task form */
.stock-lines {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.25rem;
    border: none;
    padding: 0;
}

.stock-lines legend {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    padding: 0;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 0 0.75rem;
    align-items: end;
}

.form-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin: 0.5rem 0 0;
}

td.num,
th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.stock-line {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 0 0.75rem;
    align-items: end;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface, #fafafa);
}

.stock-line-remove {
    margin-bottom: 1rem;
    justify-self: start;
}

.stock-effect-actions {
    margin-top: 0.5rem;
}

/* Custom-value text box shown under a combobox when "Add new" is picked */
.combobox-custom {
    margin-top: 0.375rem;
}

/* Virtual table */

.virtual-table-wrapper {
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.virtual-table-wrapper .data-table {
    margin-top: 0;
}

.virtual-table-wrapper thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Responsive tweaks */

@media (max-width: 768px) {
    .domain-nav {
        display: none;
    }

    .bottom-nav {
        display: flex;
    }

    .app-main {
        padding-bottom: 4.5rem;
    }

    .feedback-fab {
        bottom: 4.5rem;
    }

    .feedback-card {
        bottom: 8rem;
    }

    .page-header h1 {
        font-size: 1.25rem;
    }

    .page-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .card {
        padding: 1rem;
    }

    /* Touch-friendly bulk entry grids */
    .entry-grid th,
    .entry-grid td {
        padding: 0.75rem 0.5rem;
    }

    .qty-input {
        width: 6rem;
        min-height: 2.5rem;
        padding: 0.5rem;
        font-size: 1rem;
    }

    .btn,
    .nav-link,
    .bottom-nav-link {
        min-height: 2.5rem;
    }

    /* Optional carded tables: pages that add data-label to each td will
       render as stacked cards on narrow screens. Tables without data-label
       fall back to the horizontal scroll provided by .table-wrapper. */
    .data-table.carded,
    .data-table.carded tbody,
    .data-table.carded tr,
    .data-table.carded td {
        display: block;
        width: 100%;
    }

    .data-table.carded thead {
        display: none;
    }

    .data-table.carded tr {
        margin-bottom: 0.75rem;
        padding: 0.75rem;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }

    .data-table.carded td {
        display: flex;
        justify-content: space-between;
        padding: 0.375rem 0;
        border-bottom: 1px solid var(--border);
        text-align: right;
    }

    .data-table.carded td:last-child {
        border-bottom: none;
    }

    .data-table.carded td::before {
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        color: var(--text);
    }
}

/* ------------------------------------------------------------------
   Locations browser (platform admin reference data): three-column
   drill-down that collapses to a single column on narrow screens.
   ------------------------------------------------------------------ */
.locations-browser {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    align-items: start;
}

.loc-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    min-width: 0;
}

.loc-panel.loc-disabled {
    opacity: 0.65;
}

.loc-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.loc-panel-header h3 {
    margin: 0;
    font-size: 1rem;
}

.loc-context {
    font-weight: 400;
    color: var(--muted);
}

.loc-count {
    flex-shrink: 0;
    font-size: 0.8rem;
    color: var(--muted);
    background: var(--bg);
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
}

.loc-hint {
    margin: 0.25rem 0;
}

.loc-search {
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.loc-list {
    list-style: none;
    margin: 0 0 0.5rem;
    padding: 0.1rem;
    max-height: 26rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.loc-row {
    width: 100%;
    text-align: left;
    padding: 0.45rem 0.65rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
}

.loc-row:hover {
    background: var(--bg);
}

.loc-row-editor {
    border-color: var(--primary);
    cursor: default;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
}

.loc-row-editor input {
    width: 100%;
}

.loc-row-actions {
    display: flex;
    gap: 0.375rem;
}

.loc-add {
    display: flex;
    gap: 0.375rem;
    margin-top: 0.5rem;
}

.loc-add input {
    flex: 1;
    min-width: 0;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

@media (max-width: 900px) {
    .locations-browser {
        grid-template-columns: 1fr;
    }

    .loc-list {
        max-height: 20rem;
    }
}

/* User detail card on the platform admin users page. */
.user-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
}

.user-flags {
    display: flex;
    gap: 1.5rem;
    margin: 0.5rem 0 1rem;
}

/* Role permission matrix (platform defaults + per-farm overrides). */
.perm-matrix {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.15rem 1rem;
    max-height: 24rem;
    overflow-y: auto;
    margin: 0.5rem 0;
}

.perm-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem 0.35rem;
    border-radius: var(--radius);
}

.perm-row:hover {
    background: var(--bg);
}

.perm-row.perm-disabled {
    opacity: 0.55;
}

/* Animal picker: the filter row needs the full form width, not one grid cell. */
.animal-picker {
    grid-column: 1 / -1;
}

/* Live ration nutrition summary in the ration form. */
.nutrition-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 0.95rem;
}

/* Messaging: member directory + chat thread. */
.messaging-layout {
    display: grid;
    grid-template-columns: minmax(14rem, 1fr) 3fr;
    gap: 1rem;
    align-items: start;
}

@media (max-width: 768px) {
    .messaging-layout {
        grid-template-columns: 1fr;
    }
}

.loc-row-active {
    background: var(--bg);
    border-color: var(--primary);
}

.message-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 26rem;
    overflow-y: auto;
}

.message-row {
    display: flex;
}

.message-row.message-mine {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 75%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.message-bubble p {
    margin: 0.25rem 0;
}

.message-mine .message-bubble {
    background: var(--bg);
}

.message-bubble.message-invite {
    border-color: var(--primary);
}

.message-meta {
    font-size: 0.78rem;
    color: var(--muted);
}

/* Sent-invitation tracking on the Messages page. */
.sent-invite-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 1rem;
    padding: 0.45rem 0.65rem;
}

.invite-pending {
    font-size: 0.8rem;
    color: #92400e;
    background: #fef3c7;
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
}

.invite-accepted-label {
    font-size: 0.8rem;
    color: var(--primary);
    background: var(--bg);
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
}

.messages-context {
    margin: 0 0 0.5rem 0.25rem;
}

.my-rooms {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

/* Milk production dashboard panels. */
.milk-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: 1rem;
    align-items: start;
}

.milk-panel h3 {
    margin-top: 0;
}

.summary-sub {
    font-size: 0.78rem;
    color: var(--muted);
}

/* Farm enterprise domains (dashboard overview). Mobile-first: cards stack,
   then flow into a fluid grid as width allows. */
.domain-section h2 {
    margin-top: 0;
}

.domain-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.75rem;
}

.domain-card {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.domain-card-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.domain-card-head h3 {
    margin: 0;
    font-size: 1rem;
}

.domain-icon {
    font-size: 1.25rem;
}

.domain-tagline {
    margin: 0;
    font-size: 0.8125rem;
}

.domain-modules {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.25rem;
}

.domain-module-link {
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.8125rem;
    white-space: nowrap;
}

.domain-module-link:hover {
    background: var(--bg);
}

.domain-card.soon {
    background: var(--bg);
    color: var(--muted);
}

.domain-card.soon .domain-card-head h3 {
    color: var(--muted);
}

.domain-badge {
    align-self: flex-start;
    margin-top: 0.25rem;
    padding: 0.1rem 0.6rem;
    border-radius: 999px;
    border: 1px dashed var(--border);
    color: var(--muted);
    font-size: 0.75rem;
}

/* ------------------------------------------------------------------
   Module navigation: top-nav active state, submodule bar, mobile
   bottom sheet, combobox, pagination bar. Mobile-first.
   ------------------------------------------------------------------ */

.nav-link.active {
    color: var(--primary);
    font-weight: 600;
    background: var(--bg);
}

/* Submodule bar: scrolls horizontally on narrow screens. */
.module-nav {
    display: flex;
    gap: 0.25rem;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.module-nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 0.8125rem;
    white-space: nowrap;
}

.module-nav-link.active {
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

/* Respect device safe areas (notches, home indicator). */
.bottom-nav {
    height: calc(3.5rem + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-link.active {
    color: var(--primary);
}

button.bottom-nav-link {
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
}

/* Bottom sheet ("More" drawer and mobile combobox panel). */
.sheet-backdrop,
.combobox-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(0, 0, 0, 0.4);
}

.bottom-sheet {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    max-height: 75vh;
    overflow-y: auto;
    padding: 0.5rem 1rem calc(1rem + env(safe-area-inset-bottom));
    background: var(--surface);
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
}

.bottom-sheet-handle {
    width: 2.5rem;
    height: 0.25rem;
    margin: 0.25rem auto 0.75rem;
    border-radius: 999px;
    background: var(--border);
}

.bottom-sheet-module {
    padding: 0.375rem 0;
    border-top: 1px solid var(--border);
}

.bottom-sheet-module:first-of-type {
    border-top: none;
}

.bottom-sheet-module-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9375rem;
}

.bottom-sheet-module-link.active {
    color: var(--primary);
}

.bottom-sheet-children {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    padding: 0.25rem 0 0.5rem 1.75rem;
}

.bottom-sheet-child {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.8125rem;
}

/* Combobox: dropdown on wide screens, bottom sheet on phones. */
.combobox {
    position: relative;
}

.combobox-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    min-height: 2.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
}

.combobox-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.combobox-caret {
    color: var(--muted);
    font-size: 0.75rem;
}

.combobox-panel {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    left: 0;
    z-index: 70;
    display: flex;
    flex-direction: column;
    max-height: 18rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.combobox-backdrop {
    display: none;
}

.combobox-search {
    margin: 0.5rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}

.combobox-panel ul {
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-y: auto;
}

.combobox-option {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
}

.combobox-option.active {
    background: var(--bg);
}

.combobox-option[aria-selected="true"] {
    color: var(--primary);
    font-weight: 600;
}

.combobox-empty {
    padding: 0.75rem;
}

/* Pagination bar: prev / position / next, touch-friendly. */
.pagination-bar {
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.pagination-bar .btn {
    min-height: 2.75rem;
}

.pagination-position {
    font-size: 0.8125rem;
}

@media (max-width: 768px) {
    /* 16px minimum input text prevents iOS auto-zoom on focus. */
    input,
    select,
    textarea {
        font-size: 16px;
    }

    .combobox-backdrop {
        display: block;
    }

    .combobox-panel {
        position: fixed;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        max-height: 70vh;
        border: none;
        border-radius: 1rem 1rem 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .app-main {
        padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
    }
}

/* Visually hidden but available to screen readers (inline combobox labels). */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Compact combobox for table cells and dense forms. */
.combobox-inline {
    margin: 0;
}

.combobox-inline .combobox-trigger {
    min-height: 2.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

/* Danger emphasis for numeric warning cells (e.g. overdue counts). */
.text-danger {
    color: var(--danger);
    font-weight: 600;
}

/* Link-styled button for drillable table cells. */
.link-button {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font: inherit;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

/* Crops module */
.card-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.crop-card-body {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border, #e2e8f0);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    gap: 0.5rem 1.5rem;
    margin: 0.75rem 0;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.detail-row dt {
    color: var(--muted, #64748b);
}

.detail-row dd {
    margin: 0;
    font-weight: 500;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0;
}

.form-card {
    margin: 1rem 0;
}

.stage-timeline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin: 0.75rem 0;
}

.stage-chip {
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    border: 1px solid var(--border, #e2e8f0);
    background: var(--surface-muted, #f1f5f9);
    font-size: 0.8125rem;
    color: var(--muted, #64748b);
}

.stage-chip.done {
    background: var(--primary-soft, #dcfce7);
    color: var(--primary, #166534);
    border-color: transparent;
}

.stage-chip.current {
    background: var(--primary, #166534);
    color: #fff;
    border-color: transparent;
    font-weight: 600;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    padding: 0.375rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border, #e2e8f0);
    background: transparent;
    font: inherit;
    cursor: pointer;
}

.chip.selected {
    background: var(--primary, #166534);
    color: #fff;
    border-color: transparent;
}

.warning-box {
    padding: 0.625rem 0.875rem;
    border-radius: 0.5rem;
    background: var(--warning-soft, #fef9c3);
    color: var(--warning, #854d0e);
    border: 1px solid var(--warning, #854d0e);
}

.warning-box ul {
    margin: 0.25rem 0 0;
    padding-left: 1.25rem;
}

.plain-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.override-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

/* Dashboard crops panel */
.badge-danger {
    background: var(--danger, #b91c1c);
    color: #fff;
}

.badge-danger + .badge-danger {
    margin-left: 0.25rem;
}

tr.overdue-row td {
    color: var(--danger, #b91c1c);
    font-weight: 500;
}

tr.overdue-row td .badge {
    margin-left: 0.5rem;
}
