:root {
  --ink: #132c27;
  --rail: #102d29;
  --rail2: #173d38;
  --teal: #0b9487;
  --mint: #29c7a6;
  --paper: #f3f6f4;
  --line: #d7e1dc;
  --text: #15231f;
  --muted: #60716b;
  --blue: #316b8a;
  --danger: #c64c3e;
  --warning: #d8842e;
  --shadow: 0 10px 30px rgba(24, 55, 46, .09);
}
[hidden] { display: none !important; }
.dialog-note.error { color: #8f2f26; background: #fff0ed; border-left-color: #c65345; }

* { scrollbar-width: thin; scrollbar-color: #9bb1aa transparent; }
body { background: var(--paper); color: var(--text); font-family: Inter, "Segoe UI", Arial, sans-serif; }
.eyebrow, .panel-head { letter-spacing: 0; }
button, select, input { outline-color: #24a996; }
button { transition: background-color .16s ease, color .16s ease, border-color .16s ease, transform .16s ease; }
button:active { transform: translateY(1px); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid rgba(41, 199, 166, .25); outline-offset: 2px; }

.local-auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(110deg, rgba(8, 84, 73, .93), rgba(18, 55, 47, .78)), url("/kshiti-logo.jpg") center / cover; }
.local-auth[hidden], .app-shell[hidden], .local-register[hidden] { display: none !important; }
.auth-panel { width: min(430px, 100%); background: rgba(255, 255, 255, .97); border: 1px solid rgba(255, 255, 255, .8); border-radius: 8px; padding: 30px; box-shadow: 0 24px 70px rgba(4, 31, 25, .28); }
.auth-panel > img { width: 112px; height: 72px; object-fit: cover; display: block; margin-bottom: 20px; border-radius: 4px; }
.auth-panel h1 { font-size: 28px; line-height: 1.15; margin: 6px 0; letter-spacing: 0; }
.auth-panel > p { color: var(--muted); line-height: 1.5; }
.auth-tabs { display: flex; background: #e9f0ed; padding: 4px; border-radius: 6px; margin: 24px 0 18px; }
.auth-tabs button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 4px; font-weight: 750; }
.auth-tabs button.active { background: #fff; color: #087466; box-shadow: 0 2px 8px rgba(13, 53, 44, .1); }
.auth-panel label { display: block; font-size: 13px; font-weight: 750; margin: 14px 0; }
.auth-panel input { display: block; width: 100%; margin-top: 7px; padding: 11px; border: 1px solid #c7d4ce; border-radius: 5px; background: #fff; }
.auth-panel .primary { width: 100%; justify-content: center; margin-top: 18px; }
.auth-panel > small { display: block; color: var(--muted); margin-top: 18px; line-height: 1.5; }
.auth-password { position: relative; }
.auth-password input { padding-right: 45px; }
.auth-password .icon { position: absolute; right: 2px; bottom: 2px; width: 39px; height: 39px; }
#localAuthError { min-height: 20px; color: #a43143; margin: 8px 0 0; }

.app-shell { min-height: 100vh; background: var(--paper); }
.rail { width: 228px; padding: 18px 14px; gap: 12px; background: var(--rail); border-right: 1px solid rgba(255, 255, 255, .06); box-shadow: 8px 0 30px rgba(7, 24, 20, .12); z-index: 1000; }
.brand { height: 72px !important; padding: 8px !important; display: flex !important; align-items: center; gap: 10px; background: #fff !important; border-radius: 6px !important; overflow: hidden; }
.brand img { width: 100% !important; height: 100% !important; object-fit: cover !important; object-position: center 52% !important; }
.rail > .primary, .rail > .advisory { min-height: 44px; border-radius: 6px; justify-content: flex-start; }
.rail > .primary { background: var(--mint); color: #0b2d25; }
.rail > .primary:hover { background: #4ed9bb; }
.rail > .advisory { border: 1px solid #31544c; background: transparent; color: #f3fffb; }
.rail > .advisory:hover { background: #1a413a; }
.rail nav { gap: 3px; margin-top: 8px; }
.nav { min-height: 44px; border-left: 3px solid transparent; border-radius: 4px; color: #cfe1db; }
.nav.active, .nav:hover { border-left-color: var(--mint); background: #1a433c; color: #fff; }
.nav svg { width: 19px; height: 19px; }
.rail-bottom { display: none; }

.workspace header { height: 64px; padding: 0 22px; background: rgba(255, 255, 255, .96); border-bottom: 1px solid var(--line); box-shadow: none; position: sticky; top: 0; z-index: 900; }
.crumb, .header-actions { gap: 10px; }
.home, .field-pill { min-height: 40px; border-radius: 6px; padding: 9px 14px; }
.home { background: #e9f0ed; color: #26443c; }
.home:hover { background: #dce9e4; }
.field-pill { min-width: 168px; max-width: 260px; background: var(--rail2); }
.field-pill:hover { background: #205047; }
.field-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#farmerGreeting { color: #4f6760; font-size: 12px; font-weight: 750; white-space: nowrap; }
.header-actions select { height: 38px; min-width: 140px; padding: 0 34px 0 10px; border-color: #c9d6d1; }
.header-actions > .icon { display: none; }
.avatar { width: 38px; height: 38px; border: 2px solid #e3ebe7; background: var(--ink); }

.view { padding: 14px 20px 24px; }
.toolbar { height: 54px; gap: 16px; margin: -14px -20px 12px; padding: 0 20px; border-bottom: 1px solid var(--line); box-shadow: 0 3px 12px rgba(25, 53, 45, .04); }
.toolbar > span { font-size: 13px; color: #49635b; }
.toolbar > span b { color: #1c302a; }
.toolbar svg { width: 18px; height: 18px; }
.field-detail { border-radius: 5px; border-color: #cbd9d4; padding: 8px 11px; }
.field-detail:hover { border-color: var(--teal); color: #08796f; }
.text-button { padding: 8px 10px; color: #087c73; }
.text-button:hover { background: #e9f5f1; }
.text-button.danger-action { color: #a43c32; }
.text-button.danger-action:hover { background: #fff0ed; }

.map-layout { grid-template-columns: 238px minmax(0, 1fr); gap: 10px; height: calc(100vh - 144px); min-height: 590px; transition: grid-template-columns .2s ease; }
.map-layout.controls-collapsed { grid-template-columns: 0 minmax(0, 1fr); gap: 0; }
.map-layout.controls-collapsed .control-panel { opacity: 0; pointer-events: none; padding-left: 0; padding-right: 0; }
.control-panel { padding: 12px 14px; border-radius: 6px; background: var(--rail2); transition: opacity .16s ease, padding .2s ease; }
.panel-head { min-height: 28px; align-items: center; color: #adc5bd; }
.close-panel { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 4px; }
.close-panel:hover { background: rgba(255,255,255,.1); }
.control-group { padding: 15px 0; border-color: #3d5d56; }
.control-group h3 { font-size: 13px; margin-bottom: 9px; }
.segmented { border-radius: 4px; overflow: hidden; }
.segmented button { padding: 9px; }
.line-button { min-height: 40px; margin-top: 6px; padding: 9px 10px; border-color: #5b7a72; }
.line-button:hover { background: #214c45; border-color: #83a79d; }
.control-group select, .control-group input { min-height: 38px; }
.caption { margin-bottom: 0; color: #bbd0ca; }
.small-button { background: var(--teal); }
.small-button:hover { background: #08796f; }

.map-frame { border: 1px solid #c9d7d1; border-radius: 6px; box-shadow: var(--shadow); }
#map { min-height: 560px; }
.map-legend { left: 12px; bottom: 12px; border: 1px solid #d4dfda; border-radius: 5px; padding: 9px 11px; box-shadow: 0 6px 20px rgba(16,45,41,.14); }
.leaflet-control-scale { margin-left: 14px !important; margin-bottom: 72px !important; }
.leaflet-control-scale-line { border: 0 !important; border-left: 2px solid #173d38 !important; border-right: 2px solid #173d38 !important; border-bottom: 2px solid #173d38 !important; background: rgba(255,255,255,.9) !important; color: #173d38 !important; font-weight: 800; text-align: center; text-shadow: none !important; }
.field-card { top: 12px; right: 12px; width: 318px; padding: 15px; border: 1px solid rgba(205, 220, 214, .96); border-radius: 6px; background: rgba(255, 255, 255, .95); box-shadow: 0 12px 32px rgba(14, 43, 36, .2); backdrop-filter: blur(8px); }
.field-card-top strong { font-size: 21px; }
.field-card-top span { border-radius: 4px; }
.field-card p { color: #4e625c; }
.mini-grid { gap: 5px; }
.mini-grid > div { padding: 4px; border-right: 1px solid #e1e8e4; }
.mini-grid > div:last-child { border-right: 0; }
.mini-grid b { font-size: 14px; }
.field-card .small-button { min-height: 39px; }
.next-observation { font-size: 11px !important; }

.page-head { margin: 14px 0 20px; align-items: center; }
.page-head h1 { margin: 3px 0 5px; font-size: 27px; letter-spacing: 0; }
.page-head p { max-width: 680px; font-size: 13px; }
.primary { background: var(--teal); border-radius: 5px; }
.primary:hover { background: #08796f; }
.compact { min-height: 40px; }
.field-list { grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 12px; }
.field-row, .index-card, .wide-card, .report-card { border-color: var(--line); border-radius: 6px; box-shadow: 0 5px 18px rgba(24, 58, 42, .05); }
.field-row { position: relative; border-top: 3px solid var(--teal); }
.field-row h3 { font-size: 18px; }
.field-row button { width: 100%; padding: 9px; }
.field-row-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; }
.field-row-actions button { margin: 0; }
.field-row-actions .delete-row { width: auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding-inline: 12px; color: #a43c32; background: #fff; border: 1px solid #e6bbb4; }
.field-row-actions .delete-row:hover { background: #fff0ed; border-color: #c96d5f; }
.field-row-actions .delete-row svg { width: 16px; height: 16px; }
.index-board { gap: 10px; }
.index-card { border-top: 3px solid #2d7f77; padding: 15px; }
.index-card:nth-child(2) { border-top-color: var(--blue); }
.index-card:nth-child(3) { border-top-color: #b5782a; }
.index-card:nth-child(4) { border-top-color: #56844d; }
.index-card b { font-size: 30px; margin: 10px 0 4px; }
.wide-card { padding: 18px; }
.history-table { overflow-x: auto; }
.history-table table { width: 100%; border-collapse: collapse; color: #314840; }
.history-table th, .history-table td { padding: 11px 10px; text-align: left; border-bottom: 1px solid #e0e8e4; white-space: nowrap; }
.history-table th { font-size: 11px; color: #61766f; text-transform: uppercase; }

.weather-grid, .advisory-grid { gap: 12px; }
.weather-now { border-left: 4px solid var(--warning); }
.rain-bar { background: var(--blue); }
.report-card { max-width: 1100px; padding: 20px; border-top: 4px solid var(--teal); }
.report-status span, .report-status b { border-radius: 4px; }
.report-card h2 { font-size: 23px; }
.report-actions > div { padding: 4px 10px 4px 0; }
.detail-grid > div { border-radius: 5px !important; border: 1px solid #e0e8e4; background: #f6f9f7 !important; }
.spectroscopy-row { grid-template-columns: minmax(170px, 210px) minmax(180px, 1fr) 64px 135px !important; }
.spectroscopy-track, .spectroscopy-fill { border-radius: 2px !important; }

dialog { width: min(780px, 94vw); border-radius: 7px; padding: 22px; }
dialog::backdrop { background: rgba(7, 31, 26, .7); backdrop-filter: blur(3px); }
.form-grid { gap: 12px; }
.form-grid input, .form-grid select { min-height: 40px; background: #fbfdfc; }
.dialog-note#fieldLocation { padding: 10px 12px; background: #eaf5f1; border-left: 3px solid #17805f; color: #385d50; }
.secondary { border-radius: 5px; }

@media (max-width: 1120px) {
  .rail { width: 76px; padding: 14px 10px; align-items: stretch; }
  .brand { height: 54px !important; justify-content: center; padding: 4px !important; }
  .brand img { width: 52px !important; height: 46px !important; }
  .rail button span { display: none !important; }
  .rail > .primary, .rail > .advisory, .rail nav .nav { justify-content: center; padding: 10px; }
  .rail nav { width: 100%; }
  .map-layout { grid-template-columns: 220px minmax(0,1fr); }
  .toolbar > span:nth-of-type(2) { display: none; }
}

@media (max-width: 820px) {
  .app-shell { display: block; padding-bottom: 68px; }
  .rail { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: 100%; height: 68px; padding: 6px 8px; z-index: 2200; border: 0; border-top: 1px solid #35564e; box-shadow: 0 -8px 24px rgba(7,24,20,.2); }
  .brand, .rail > .primary, .rail > .advisory, .rail-bottom { display: none !important; }
  .rail nav { display: flex; align-items: stretch; justify-content: space-around; gap: 2px; width: 100%; margin: 0; }
  .rail nav .nav { flex: 1; min-width: 0; min-height: 56px; padding: 6px 3px; flex-direction: column; gap: 3px; border-left: 0; border-top: 3px solid transparent; font-size: 10px; }
  .rail nav .nav span { display: block !important; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rail nav .nav.active { border-top-color: var(--mint); border-left-color: transparent; }
  .workspace header { height: 58px; padding: 0 10px; }
  .home { display: none; }
  .field-pill { min-width: 0; max-width: 150px; padding: 8px 10px; }
  #farmerGreeting { display: none; }
  .header-actions select { display: block; min-width: 104px; max-width: 120px; }
  .avatar { width: 36px; height: 36px; }
  .view { padding: 10px; }
  .toolbar { min-height: 54px; height: auto; margin: -10px -10px 8px; padding: 7px 10px; gap: 6px; overflow-x: auto; }
  .toolbar > span { display: none; }
  .field-detail, .text-button { white-space: nowrap; }
  .toolbar-spacer { min-width: 4px; }
  .map-layout, .map-layout.controls-collapsed { display: flex; flex-direction: column; height: auto; min-height: 0; gap: 8px; }
  .control-panel, .map-layout.controls-collapsed .control-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; opacity: 1; pointer-events: auto; padding: 10px 12px; max-height: none; overflow: visible; }
  .panel-head { grid-column: 1 / -1; }
  .control-group { padding: 10px 0; }
  .control-group:last-child { grid-column: 1 / -1; }
  .control-panel .caption { display: none; }
  .close-panel { display: none; }
  .map-frame, #map { height: 570px; min-height: 570px; }
  .field-card { left: 10px; right: 10px; top: 10px; width: auto; padding: 12px; }
  .field-card > p { display: none; }
  .field-card .advice { display: block; max-height: 42px; overflow: hidden; }
  .map-legend { max-width: calc(100% - 20px); }
  .page-head { align-items: flex-start; gap: 10px; }
  .page-head h1 { font-size: 23px; }
  .index-board { grid-template-columns: 1fr 1fr; }
  .weather-grid, .advisory-grid, .report-actions, .detail-grid { grid-template-columns: 1fr !important; }
  .spectroscopy-row { grid-template-columns: 1fr 58px !important; }
  .spectroscopy-row .spectroscopy-track { grid-column: 1 / 3; }
  .spectroscopy-row small { display: none; }
}

@media (max-width: 520px) {
  .header-actions { gap: 6px; }
  .header-actions select { width: 94px; min-width: 94px; }
  .field-pill { max-width: 128px; }
  .control-panel { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .control-panel .line-button { min-height: 42px; padding: 7px; font-size: 12px; }
  .control-panel .control-group:last-child, .control-panel .panel-head { grid-column: 1 / -1; }
  .map-frame, #map { height: 535px; min-height: 535px; }
  .mini-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .mini-grid span { font-size: 9px; }
  .mini-grid b { font-size: 13px; }
  .index-board { grid-template-columns: 1fr 1fr; gap: 8px; }
  .index-card { padding: 12px; }
  .index-card b { font-size: 25px; }
  .form-grid { grid-template-columns: 1fr; }
  dialog { padding: 18px; }
  .auth-panel { padding: 22px; }
}
