:root {
  --accent: #2d9a60;
  --accent-dark: #217849;
  --ink: #25313b;
  --muted: #687783;
  --line: #d9e0e5;
  --surface: #ffffff;
  --canvas: #f3f5f6;
  --sidebar: #202932;
  --guide: #b36b16;
}
* { box-sizing: border-box; letter-spacing: 0; }
html, body { min-height: 100%; margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: 230px; display: flex; flex-direction: column; background: var(--sidebar); color: #fff; }
.sidebar-brand { min-height: 75px; padding: 9px 16px; display: flex; align-items: center; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); }
.default-brand { display: flex; align-items: center; gap: 11px; }
.default-brand > span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
.default-brand b { font-size: 15px; }
.default-brand small { margin-top: 3px; color: #aeb8bf; font-size: 10px; text-transform: uppercase; }
.brand-badge { width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 14px; font-weight: 800; }
.hail-brand { display: none; width: 198px; height: 66px; object-fit: cover; object-position: center; }
.sidebar nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar nav a { min-height: 42px; padding: 10px 18px; display: flex; align-items: center; gap: 11px; color: #c5cdd3; text-decoration: none; font-size: 13px; border-left: 3px solid transparent; }
.sidebar nav a:hover, .sidebar nav a.active { color: #fff; background: rgba(255,255,255,.07); border-left-color: var(--accent); }
.sidebar nav i { width: 17px; text-align: center; }
.nav-label { display: block; padding: 14px 20px 6px; color: #7e8a93; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.sidebar-footer { padding: 15px 19px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer span { display: block; margin-bottom: 9px; color: #9eabb4; font-size: 11px; overflow-wrap: anywhere; }
.sidebar-footer a { display: flex; align-items: center; gap: 9px; color: #d2d8dc; text-decoration: none; font-size: 12px; }

main { min-height: 100vh; margin-left: 230px; }
.topbar { height: 58px; padding: 0 28px; display: flex; align-items: center; gap: 14px; background: #fff; border-bottom: 1px solid var(--line); }
.topbar-brand { flex: 0 0 auto; color: var(--ink); text-decoration: none; }
.topbar-default-brand { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.topbar-badge { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; color: #fff; background: var(--accent); font-size: 10px; font-weight: 800; }
.topbar-hail-brand { display: none; width: 154px; height: 48px; object-fit: cover; object-position: center; background: #315f36; border-radius: 4px; }
.breadcrumb { flex: 1; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb b { color: var(--ink); font-weight: 650; }
.topbar > span { color: var(--muted); font-size: 12px; }
.workspace { max-width: 1320px; margin: 0 auto; padding: 26px 34px 56px; }

.log-meta { display: grid; grid-template-columns: 1.2fr .9fr 1.4fr 1fr 150px; gap: 12px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
input, select, textarea { width: 100%; min-width: 0; padding: 8px 9px; border: 1px solid #c8d1d7; border-radius: 6px; color: var(--ink); background: #fff; }
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45,154,96,.13); }

.view-tabs { display: inline-flex; margin: 22px 0 18px; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: #e8ecef; }
.view-tab { min-height: 34px; padding: 7px 13px; display: inline-flex; align-items: center; gap: 7px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; }
.view-tab.active { color: var(--ink); background: #fff; box-shadow: 0 1px 2px rgba(24,36,45,.12); }

.sample-toolbar { min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.sample-toolbar > div { display: flex; align-items: baseline; gap: 10px; }
.sample-toolbar b { font-size: 14px; }
.sample-toolbar span { color: var(--muted); font-size: 10px; }
.primary-button, .secondary-button, .export-button, .gps-button { min-height: 38px; padding: 8px 13px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 6px; font-size: 12px; font-weight: 750; }
.primary-button, .export-button { border: 1px solid var(--accent); color: #fff; background: var(--accent); }
.primary-button:hover, .export-button:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.secondary-button, .gps-button { border: 1px solid #c8d1d7; color: var(--ink); background: #fff; }
.secondary-button:hover, .gps-button:hover { background: #f1f4f5; }
.export-button:disabled { opacity: .45; cursor: default; }

.sample-table-wrap { min-height: 220px; margin-top: 10px; position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.sample-table { width: 100%; min-width: 1040px; border-collapse: collapse; table-layout: fixed; }
.sample-table th { padding: 9px 11px; color: #53616c; background: #f6f8f9; font-size: 10px; text-align: left; text-transform: uppercase; }
.sample-table td { padding: 10px 11px; border-top: 1px solid #e6ebee; font-size: 11px; line-height: 1.4; vertical-align: top; overflow-wrap: anywhere; }
.sample-table th:nth-child(1) { width: 10%; } .sample-table th:nth-child(2) { width: 10%; } .sample-table th:nth-child(3) { width: 8%; }
.sample-table th:nth-child(4) { width: 15%; } .sample-table th:nth-child(5) { width: 30%; } .sample-table th:nth-child(6) { width: 20%; } .sample-table th:nth-child(7) { width: 7%; }
.sample-actions { display: flex; justify-content: flex-end; gap: 3px; }
.icon-button { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; color: var(--muted); background: transparent; }
.icon-button:hover { color: var(--accent-dark); background: #edf6f1; }
.icon-button.delete:hover { color: #a9292e; background: #fff1f2; }
.location-value { font-variant-numeric: tabular-nums; }
.location-value small { display: block; margin-top: 2px; color: var(--muted); }
.empty-state { min-height: 176px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #87939c; }
.empty-state i { font-size: 25px; color: #aab4bb; }
.empty-state b { font-size: 12px; }
.export-row { min-height: 62px; display: flex; align-items: center; justify-content: flex-end; gap: 14px; }
.status { flex: 1; color: var(--muted); font-size: 11px; }
.status.error { color: #a9292e; }
.status.success { color: var(--accent-dark); }

.figure-view { min-width: 0; }
.figure-toolbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.figure-toolbar > div:first-child { min-width: 210px; display: flex; flex-direction: column; gap: 4px; }
.figure-toolbar b { font-size: 14px; }
.figure-toolbar span { color: var(--muted); font-size: 10px; }
.figure-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.segmented-control { padding: 3px; display: inline-flex; border: 1px solid var(--line); border-radius: 6px; background: #e8ecef; }
.segmented-control button { min-height: 30px; padding: 5px 10px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-size: 11px; font-weight: 750; }
.segmented-control button.active { color: var(--ink); background: #fff; box-shadow: 0 1px 2px rgba(24,36,45,.12); }
.segmented-control button:disabled { opacity: .45; cursor: default; }
.icon-square { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border: 1px solid #c8d1d7; border-radius: 6px; color: var(--ink); background: #fff; }
.icon-square:hover:not(:disabled) { color: var(--accent-dark); background: #edf6f1; }
.icon-square:disabled { opacity: .4; cursor: default; }
.figure-stage { min-height: 390px; position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: 0 1px 2px rgba(23,35,43,.04); }
#soil-figure-canvas { width: 100%; height: 590px; display: block; touch-action: none; cursor: grab; }
#soil-figure-canvas.dragging { cursor: grabbing; }
.figure-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #87939c; text-align: center; pointer-events: none; }
.figure-empty i { font-size: 26px; color: #aab4bb; }
.figure-empty b { color: #66747e; font-size: 13px; }
.figure-empty span { max-width: 390px; font-size: 11px; }
.figure-footer { min-height: 54px; padding: 10px 2px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.figure-footer > span { max-width: 390px; color: var(--muted); font-size: 10px; text-align: right; }
.soil-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 13px; }
.soil-legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.soil-legend i { width: 11px; height: 11px; border: 1px solid rgba(36,49,59,.16); border-radius: 3px; }

.map-view { min-width: 0; }
.sample-map-stage { height: 590px; min-height: 390px; position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #e8ecef; }
#sample-map { width: 100%; height: 100%; }
.map-empty { position: absolute; inset: 0; z-index: 500; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #87939c; background: rgba(255,255,255,.94); text-align: center; pointer-events: none; }
.map-empty i { font-size: 26px; color: #aab4bb; }
.map-empty b { color: #66747e; font-size: 13px; }
.map-empty span { font-size: 11px; }
.map-footer { min-height: 50px; padding: 11px 2px; color: var(--muted); font-size: 10px; }
.sample-map-marker { width: 22px; height: 22px; display: grid; place-items: center; border: 3px solid #fff; border-radius: 50%; color: #fff; background: var(--guide); box-shadow: 0 2px 5px rgba(20,31,39,.35); font-size: 8px; font-weight: 800; }
.sample-map-label { padding: 3px 6px; border: 1px solid rgba(37,49,59,.2); border-radius: 3px; color: var(--ink); background: rgba(255,255,255,.94); box-shadow: 0 1px 3px rgba(20,31,39,.14); font-size: 10px; font-weight: 800; }
.leaflet-tooltip.sample-map-label::before { display: none; }
.map-popup { min-width: 180px; line-height: 1.45; }
.map-popup b { color: var(--ink); }
.map-popup small { color: var(--muted); }

.term-sequence { padding: 12px 0 18px; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; border-bottom: 1px solid var(--line); }
.term-sequence b { margin-right: 4px; font-size: 12px; }
.term-sequence span { color: var(--ink); font-size: 11px; }
.term-sequence i { width: 4px; height: 4px; border-radius: 50%; background: var(--guide); }
.guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 30px; }
.guide-grid section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.guide-grid h2 { margin: 0 0 9px; font-size: 13px; }
.guide-grid table { width: 100%; border-collapse: collapse; }
.guide-grid th, .guide-grid td { padding: 6px 8px; border-top: 1px solid #e3e8eb; font-size: 11px; text-align: left; vertical-align: top; }
.guide-grid th { width: 36%; color: var(--ink); background: #f7f8f9; }
.guide-grid td { color: var(--muted); background: #fff; }
.guide-source { padding: 18px 0; display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 11px; }
.guide-source i { color: var(--guide); }
.guide-source a { color: var(--accent-dark); font-weight: 700; }

dialog { width: min(960px, calc(100vw - 34px)); max-height: calc(100vh - 30px); padding: 0; overflow: hidden; border: 0; border-radius: 8px; color: var(--ink); background: #fff; box-shadow: 0 20px 70px rgba(13,24,32,.3); }
dialog::backdrop { background: rgba(21,31,39,.56); }
#sample-form { max-height: calc(100vh - 30px); display: flex; flex-direction: column; }
.create-log-dialog { width: min(620px, calc(100vw - 34px)); }
#log-form { display: flex; flex-direction: column; }
.create-log-body { display: grid; gap: 13px; }
.create-log-grid { grid-template-columns: 1fr 170px; }
.dialog-header { min-height: 64px; padding: 12px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 16px; }
.dialog-header span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.dialog-header button { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: transparent; }
.dialog-header button:hover { color: var(--ink); background: #edf0f2; }
.dialog-body { padding: 18px; overflow-y: auto; }
.form-grid { display: grid; gap: 12px; }
.identity-grid { grid-template-columns: 1fr 1.35fr .8fr .8fr; }
.descriptor-grid { grid-template-columns: repeat(3, 1fr); }
fieldset { min-width: 0; margin: 18px 0 0; padding: 14px; border: 1px solid var(--line); border-radius: 7px; }
legend { padding: 0 6px; color: var(--ink); font-size: 11px; font-weight: 800; }
.location-fieldset { background: #f7faf8; }
.location-row { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; }
.gps-button { min-width: 145px; }
.gps-status { min-height: 16px; margin-top: 7px; color: var(--muted); font-size: 10px; }
.gps-status.error { color: #a9292e; }
.gps-status.success { color: var(--accent-dark); }
.description-preview { margin-top: 13px; }
.description-preview textarea { color: var(--ink); background: #f7f9fa; font-weight: 650; }
.dialog-body > label:last-child { margin-top: 16px; }
.dialog-footer { min-height: 62px; padding: 11px 18px; display: flex; align-items: center; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); background: #f7f9fa; }

html[data-association="hail"] { --accent: #4d873f; --accent-dark: #315f36; }
html[data-association="hail"] .default-brand { display: none; }
html[data-association="hail"] .hail-brand { display: block; }
html[data-association="hail"] .topbar-default-brand { display: none; }
html[data-association="hail"] .topbar-hail-brand { display: block; }

@media (max-width: 980px) {
  .log-meta { grid-template-columns: 1fr 1fr; }
  .log-meta label:nth-child(3) { grid-column: span 2; }
  .descriptor-grid { grid-template-columns: 1fr 1fr; }
  .figure-toolbar { align-items: flex-start; flex-direction: column; padding: 10px 0; }
  .figure-actions { width: 100%; justify-content: flex-start; }
}
@media (max-width: 760px) {
  .sidebar { display: none; }
  main { margin-left: 0; }
  .topbar { padding: 0 14px; }
  .topbar > span { display: none; }
  .workspace { padding: 20px 14px 40px; }
  .log-meta { grid-template-columns: 1fr; }
  .log-meta label:nth-child(3) { grid-column: auto; }
  .sample-toolbar { align-items: stretch; flex-direction: column; }
  .sample-toolbar > div { justify-content: space-between; }
  .primary-button { min-height: 42px; }
  .guide-grid { grid-template-columns: 1fr; }
  .guide-source { align-items: flex-start; flex-wrap: wrap; }
  #soil-figure-canvas { height: 440px; }
  .sample-map-stage { height: 440px; }
  .figure-footer { align-items: flex-start; flex-direction: column; }
  .figure-footer > span { text-align: left; }
  #load-demo { flex: 1 1 100%; }
  dialog { width: 100vw; max-height: 100vh; border-radius: 0; }
  #sample-form { max-height: 100vh; }
  .identity-grid, .descriptor-grid, .location-row, .create-log-grid { grid-template-columns: 1fr; }
  .gps-button { width: 100%; }
  .dialog-footer button { flex: 1; }
}
@media (max-width: 520px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar-hail-brand { width: 118px; }
  .breadcrumb { min-width: 0; gap: 4px; font-size: 11px; }
  .breadcrumb b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
