:root {
    --tosh-blue: #0879bd;
    --tosh-blue-dark: #075a8d;
    --tosh-blue-soft: #e5f2fa;
    --tosh-gray: #636466;
    --tosh-gray-dark: #3f4143;
    --ink: #25282a;
    --muted: #636466;
    --line: #d8dde1;
    --danger: #b3261e;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
    margin: 0;
    background: linear-gradient(135deg, #f7f8f9 0%, #eaf4fa 100%);
    color: var(--ink);
    line-height: 1.5;
    overflow-x: hidden;
}

.page { display: flex; min-height: 100vh; }
.sidebar { width: 250px; flex: 0 0 250px; min-height: 100vh; background: var(--tosh-gray-dark); color: white; box-shadow: 4px 0 18px rgba(63, 65, 67, 0.18); }
.nav-header { border-bottom: 1px solid rgba(255, 255, 255, 0.14); }
.nav-header .container-fluid { padding: 0 0.75rem; }
.navbar-brand { color: white; font-weight: 600; font-size: 1.1rem; text-decoration: none; padding: 0.8rem 0.75rem; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.35rem; }
.navbar-brand span { color: #e5f2fa; font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; }
.brand-logo { display: block; width: min(100%, 220px); height: auto; }

.hamburger-menu { display: flex; align-items: center; gap: 0.65rem; margin: 0.5rem 0.75rem 0; padding: 0.7rem 0.85rem; border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 8px; color: white; background: var(--tosh-gray-dark); cursor: pointer; font-weight: 600; letter-spacing: 0.02em; font: inherit; width: calc(100% - 1.5rem); justify-content: center; appearance: none; }
.hamburger-menu:hover, .hamburger-menu:focus-visible { background: var(--tosh-blue-dark); }
.hamburger-icon, .hamburger-icon::before, .hamburger-icon::after { display: block; width: 1.2rem; height: 2px; background: currentColor; content: ""; }
.hamburger-icon { position: relative; }
.hamburger-icon::before, .hamburger-icon::after { position: absolute; left: 0; }
.hamburger-icon::before { top: -6px; }
.hamburger-icon::after { top: 6px; }
.nav-scrollable { display: block; }
.nav-scrollable.open { display: block; }
.nav-scrollable nav { padding-top: 0.5rem; }
.nav-item .nav-link { color: #f0f4f7; display: block; padding: 0.7rem 0.85rem; margin: 0.15rem 0.75rem; border-radius: 8px; text-decoration: none; transition: background 160ms ease, color 160ms ease, transform 160ms ease; }
.nav-item .nav-link.active, .nav-item .nav-link:hover { color: white; font-weight: 600; background: rgba(8, 121, 189, 0.32); transform: translateX(2px); }

main { flex: 1; min-width: 0; min-height: 100vh; }
.content { width: 100%; max-width: 1440px; margin: 0 auto; padding: clamp(1.25rem, 3vw, 2.75rem); min-width: 0; }
h1 { color: var(--tosh-gray-dark); font-family: Georgia, 'Times New Roman', serif; font-size: clamp(1.8rem, 4vw, 2.7rem); line-height: 1.1; margin: 0 0 1.25rem; overflow-wrap: anywhere; }
h1:focus { outline: none; }
h2, h3, h4 { color: var(--tosh-gray-dark); }
h2 { margin-top: 2rem; }

.toolbar { display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.search-box, .form-control { padding: 0.55rem 0.7rem; border: 1px solid #bdc7ce; border-radius: 8px; font-size: 0.95rem; max-width: 100%; min-height: 44px; background: rgba(255, 255, 255, 0.9); color: var(--ink); }
.search-box { min-width: 260px; }
.search-box:focus, .form-control:focus { outline: 3px solid rgba(8, 121, 189, 0.18); border-color: var(--tosh-blue); }
.lease-form { width: min(100%, 760px); }
.form-field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.form-field-short { max-width: 280px; }
.form-field > label, .modal-card form > label, .sign-page form > label, .form-row label { font-size: 0.9rem; font-weight: 600; }
.form-field .form-control { width: 100%; }

.btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.55rem 1rem; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; text-align: center; text-decoration: none; font-size: 0.9rem; min-height: 44px; transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(63, 65, 67, 0.16); }
.btn-primary, .btn-secondary { background: var(--tosh-blue); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-cancel { background: var(--danger); color: white; }
.btn-link { background: none; color: var(--tosh-blue-dark); text-decoration: underline; padding: 0; }
.toolbar .form-control { min-width: 160px; }
.action-group { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.table-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.table-actions.ending-soon-actions { flex-wrap: nowrap; }
.ending-soon-actions .btn { white-space: nowrap; }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; scrollbar-color: var(--tosh-blue) var(--tosh-blue-soft); }
.data-table { width: 100%; min-width: 620px; border-collapse: collapse; background: white; box-shadow: 0 8px 22px rgba(63, 65, 67, 0.1); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.data-table th, .data-table td { padding: 0.65rem 0.8rem; border-bottom: 1px solid var(--line); text-align: left; font-size: 0.92rem; }
.data-table th { background: var(--tosh-blue-soft); color: var(--tosh-gray-dark); font-weight: 700; }
.sortable-th { padding: 0; }
.sort-btn { display: flex; align-items: center; gap: 0.3rem; width: 100%; padding: 0.65rem 0.8rem; border: none; background: none; font: inherit; font-weight: 700; color: inherit; cursor: pointer; text-align: left; }
.sort-btn:hover, .sort-btn:focus-visible { color: var(--tosh-blue-dark); }
.sort-arrow { font-size: 0.7rem; }
.mobile-sort-bar { display: none; }
.status-pill { padding: 0.2rem 0.6rem; border-radius: 1rem; font-size: 0.78rem; font-weight: 600; color: white; white-space: nowrap; }
.status-Draft { background: #999; }
.status-PendingLesseeSignature { background: var(--tosh-blue); }
.status-PendingManagerApproval { background: #9a7714; }
.status-Approved { background: var(--tosh-gray); }
.status-Rejected { background: var(--danger); }
.status-Cancelled { background: #666; }
.status-Expired { background: #444; }

.stat-cards { display: flex; gap: 0.85rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat-card { background: white; border-radius: 10px; padding: 1.1rem 1.25rem; box-shadow: 0 8px 22px rgba(8, 121, 189, 0.24); min-width: 160px; flex: 1 1 180px; border-top: 4px solid var(--tosh-blue); }
.stat-value { font-size: 2rem; font-weight: 700; color: #000; line-height: 1; }
.stat-value-danger { color: var(--danger); }
.stat-value-warning { color: #9a7714; }
a.stat-value { display: inline-block; text-decoration: none; }
a.stat-value:hover, a.stat-value:focus-visible { text-decoration: underline; text-underline-offset: 0.15em; }
.stat-label { color: var(--muted); font-size: 0.85rem; margin-top: 0.4rem; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow-y: auto; z-index: 100; }
.modal-card { background: white; border-radius: 12px; padding: 1.5rem 2rem; width: 100%; max-width: 600px; box-shadow: 0 18px 45px rgba(63, 65, 67, 0.2); }
.modal-card label { display: block; margin-top: 0.75rem; }
.modal-card .form-control { width: 100%; margin-top: 0.2rem; }
.form-row { display: flex; gap: 1rem; align-items: flex-start; }
.form-row > div { display: flex; flex: 1; flex-direction: column; gap: 0.35rem; }
.modal-card form, .sign-page form { max-width: 760px; }
.modal-card form > label, .sign-page form > label { display: block; margin: 0; }
.modal-card form > .form-control, .sign-page form > .form-control { width: 100%; margin: 0 0 1rem; }
.rich-text-toolbar { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.5rem; background: #eef3f6; border: 1px solid var(--line); border-bottom: 0; }
.rich-text-toolbar .btn { min-width: 2.4rem; padding: 0.4rem 0.65rem; }
.rich-text-editor { min-height: 22rem; padding: 0.85rem; border: 1px solid var(--line); background: #fff; overflow-y: auto; line-height: 1.55; }
.rich-text-editor:focus { outline: 3px solid rgba(8, 121, 189, 0.22); outline-offset: 1px; }
.rich-text-editor h2, .rich-text-editor h3 { margin: 0.6rem 0 0.35rem; }
.rich-text-editor ul, .rich-text-editor ol { padding-left: 1.5rem; }
.form-row .form-control { width: 100%; }
.checkbox-label { display: flex !important; align-items: center; gap: 0.5rem; }
.season-checklist { display: flex; flex-direction: column; gap: 0.5rem; background: white; border: 1px solid var(--line); border-radius: 8px; padding: 0.85rem 1rem; max-height: 260px; overflow-y: auto; }
.season-checklist .checkbox-label { font-weight: 400; }
.modal-actions { margin-top: 1.25rem; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.map-title { margin: 0; }
.farm-map { width: 100%; min-height: 560px; background: #dce6f2; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.farm-map .marker-dot { width: 23px; height: 23px; border-radius: 999px; border: 3px solid #fff; box-shadow: 0 2px 10px rgba(0,0,0,.42); }
.farm-map .cluster-group { border-radius: 999px; color: #fff; font-weight: 900; border: 3px solid rgba(255,255,255,.9); display: grid; place-items: center; }
.farm-map .popup-title { font-weight: 900; }
.farm-map .popup-meta { color: var(--muted); margin-bottom: 8px; }
.farm-map .popup-actions { display: flex; gap: 7px; margin-top: 10px; }
.farm-map .popup-actions a { text-decoration: none; background: var(--tosh-blue); color: #fff; padding: 8px 10px; border-radius: 10px; font-weight: 900; }
.farm-map .popup-actions a.secondary { background: var(--tosh-blue); }
.farm-map .farm-geofence-label { white-space: nowrap; text-align: center; font-size: 12px; font-weight: 700; color: #172554; background: transparent; border: 0; box-shadow: none; text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff, 0 0 4px #fff; padding: 2px 4px; pointer-events: none; }
.farm-map:not(.geofence-labels-visible) .farm-geofence-label { display: none; }
.farm-map.geofence-editing { cursor: crosshair; }
.farm-map .geofence-vertex-wrap { background: transparent; border: 0; }
.farm-map .geofence-vertex { display: block; width: 18px; height: 18px; margin: 3px; border: 3px solid #fff; border-radius: 50%; background: #16a34a; box-shadow: 0 1px 5px rgba(0,0,0,.65); cursor: grab; }
.farm-map .geofence-vertex:active { cursor: grabbing; }
.geofence-point-count { color: var(--muted); font-weight: 700; }
.map-meta { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.75rem; color: var(--muted); }
.map-meta span { color: var(--ink); }
.lease-download { margin: 0 0 1.25rem; }
.detail-card, .signature-card { background: white; border-radius: 10px; padding: 1rem 1.25rem; box-shadow: 0 8px 22px rgba(63, 65, 67, 0.1); border: 1px solid var(--line); }
.detail-dropdown summary { cursor: pointer; font-weight: 700; color: var(--tosh-gray-dark); }
.detail-dropdown summary::marker { color: var(--tosh-blue); }
.renewal-queue-section { margin-bottom: 1rem; }
.detail-dropdown p:last-child { margin-bottom: 0; }
.renewal-card { margin: 1.25rem 0; max-width: 640px; }
.renewal-card .modal-actions { margin-top: 1rem; }
.renewal-card .checkbox-label { font-weight: 600; }
.signature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.signature-img, .license-preview { max-width: 100%; border: 1px solid #ddd; border-radius: 6px; background: white; }
.license-preview { display: block; max-height: 420px; object-fit: contain; }
.signature-pad { border: 2px dashed #89939a; border-radius: 8px; background: white; touch-action: none; max-width: 100%; width: 100%; }
.lease-terms-box { background: white; border-radius: 8px; padding: 1rem 1.25rem; white-space: pre-wrap; border: 1px solid #ddd; max-height: 320px; overflow-y: auto; }
.agreement-document { color: #18212b; font-family: Georgia, 'Times New Roman', serif; font-size: 1rem; line-height: 1.55; border-top: 8px solid var(--tosh-blue); border-bottom: 8px solid var(--tosh-blue); }
.signing-link-box { background: white; padding: 0.75rem 1rem; border-radius: 8px; display: flex; align-items: center; gap: 1rem; word-break: break-all; }
.notification-contact-fields { margin-top: 1rem; max-width: 760px; }
.history-list { list-style: none; padding: 0; }
.history-list li { padding: 0.4rem 0; border-bottom: 1px solid #e5e5e5; font-size: 0.9rem; }
.table-season-details summary { cursor: pointer; color: var(--tosh-blue-dark); font-weight: 600; }
.table-season-details .history-list { margin: 0.5rem 0 0; min-width: 190px; }
.success-panel, .info-panel, .error-panel { background: white; border-radius: 10px; padding: 1.5rem 2rem; max-width: 700px; }
.info-actions { margin-top: 0.85rem; }
.success-panel { border-left: 6px solid var(--tosh-blue); }
.info-panel { border-left: 6px solid var(--tosh-gray); }
.error-panel { border-left: 6px solid var(--danger); }
.login-panel { background: white; border-radius: 10px; padding: 1.5rem 2rem; max-width: 420px; }
.login-panel h1 { text-align: center; }
.login-panel > p { text-align: center; }
.login-panel form { text-align: center; }
.login-panel form .form-control { display: block; width: 100%; text-align: left; }
.login-panel label { display: block; margin-top: 0.9rem; font-weight: 600; }
.login-panel .btn { margin-top: 1.2rem; }
.login-submit { display: flex; justify-content: center; }
.login-divider { margin: 1rem 0 0; text-align: center; color: var(--muted); font-size: 0.85rem; }
.nav-user .nav-link { cursor: default; }
.nav-logout { background: none; border: none; width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.rejection-reason, .validation-message { color: var(--danger); font-weight: 600; }
.success-message { color: var(--tosh-blue-dark); font-weight: 600; }
.sign-page { max-width: 700px; margin: 0 auto; padding: 1rem; }
.sign-page .form-control, .sign-page .form-row, .sign-page .signature-pad, .sign-page input[type="file"] { max-width: 100%; }
button:disabled { cursor: not-allowed; opacity: 0.65; }
.busy-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem; background: rgba(20, 29, 39, 0.42); color: #fff; cursor: wait; }
.busy-overlay span { font-weight: 600; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); }
.busy-indicator { width: 2.25rem; height: 2.25rem; border: 0.25rem solid rgba(255, 255, 255, 0.45); border-top-color: #fff; border-radius: 50%; animation: busy-spin 0.8s linear infinite; }
@keyframes busy-spin { to { transform: rotate(360deg); } }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(8, 121, 189, 0.32); outline-offset: 2px; }

@media (max-width: 767px) {
    .page { flex-direction: column; }
    .sidebar { width: 100%; flex-basis: auto; min-height: auto; overflow: hidden; }
    .nav-scrollable { display: none; max-height: none; padding-bottom: 0.75rem; }
    .nav-scrollable.open { display: block; }
    .nav-item .nav-link { padding: 0.65rem 1rem; }
    .content { padding: 1rem; }
    .content h1 { font-size: 1.65rem; }
    .page > main > .top-row { display: none; }
    .toolbar { align-items: stretch; }
    .search-box, .toolbar .form-control, .toolbar .btn { width: 100%; min-width: 0; }
    .toolbar { gap: 0.55rem; }
    .stat-card { flex: 1 1 100%; min-width: 0; }
    .form-row { flex-direction: column; }
    .form-row > div { width: 100%; }
    .modal-backdrop { padding: 0; }
    .modal-card { min-height: 100vh; border-radius: 0; padding: 1rem; }
    .detail-grid, .signature-grid { grid-template-columns: minmax(0, 1fr); }
    .farm-map { min-height: 420px; }
    .detail-card, .signature-card { padding: 0.9rem 1rem; }
    .success-panel, .info-panel, .error-panel { padding: 1rem 1.15rem; }
    .signing-link-box { align-items: stretch; flex-direction: column; }
    .signing-link-box .btn { width: 100%; }
    .table-wrap { margin-right: -0.25rem; overflow: visible; }
    .data-table { min-width: 0; display: block; border: 0; background: transparent; box-shadow: none; }
    .data-table thead { display: none; }
    .data-table tbody { display: grid; gap: 0.85rem; }
    .data-table tr { display: block; background: white; border: 1px solid var(--line); border-left: 4px solid var(--tosh-blue); border-radius: 10px; box-shadow: 0 5px 14px rgba(63, 65, 67, 0.08); overflow: hidden; }
    .data-table td { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: 0.65rem 0.85rem; border-bottom: 1px solid #edf0f2; text-align: right; font-size: 0.9rem; overflow-wrap: anywhere; }
    .data-table td::before { content: attr(data-label); color: var(--muted); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-align: left; text-transform: uppercase; flex: 0 0 auto; }
    .data-table td:last-child { border-bottom: 0; }
    .data-table td.mobile-card-action { display: block; padding: 0.75rem 0.85rem; background: #f8fafb; text-align: left; }
    .data-table td.mobile-card-action::before { display: none; }
    .data-table td.mobile-card-action .btn { width: 100%; }
    .table-actions { display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; }
    .data-table td[colspan] { display: block; text-align: left; }
    .data-table td[colspan]::before { display: none; }
    .data-table .status-pill { margin-left: auto; }
    .mobile-sort-bar { display: flex; gap: 0.55rem; margin-bottom: 0.85rem; }
    .mobile-sort-bar .form-control { flex: 1; min-width: 0; }
    .mobile-sort-bar .btn-sort-dir { flex: 0 0 auto; min-width: 44px; padding: 0.55rem 0.75rem; }
}

@media (min-width: 641px) {
    .hamburger-menu { display: none; }
}
