* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: #1f2933;
  background: #f4f1e8;
}

a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 58px;
  padding: 10px 26px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid #d8d1bf;
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: #31522b;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.nav a,
.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid #7a8b50;
  border-radius: 6px;
  background: #456b35;
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.nav a {
  background: transparent;
  color: #31522b;
}

.button.secondary {
  background: #fff;
  color: #31522b;
}

.hero {
  min-height: calc(100vh - 58px);
  background-image: url("../img/hero-wheat-acros.png");
  background-size: cover;
  background-position: center;
}

.hero-overlay {
  min-height: calc(100vh - 58px);
  display: flex;
  align-items: center;
  padding: 44px 7vw;
  background: linear-gradient(90deg, rgba(25, 34, 21, 0.72), rgba(25, 34, 21, 0.30), rgba(25, 34, 21, 0.08));
}

.hero-content {
  width: min(620px, 100%);
  color: #fff;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f2d77e;
}

h1, h2 { margin: 0 0 12px; }

.hero h1 {
  font-size: clamp(36px, 6vw, 72px);
  line-height: 1;
}

.lead {
  margin: 16px 0 24px;
  max-width: 560px;
  font-size: 20px;
  line-height: 1.45;
}

.login-panel,
.panel {
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 34px rgba(41, 35, 18, 0.12);
}

.login-panel {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  padding: 12px;
  color: #1f2933;
}

label span {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 700;
  color: #57606a;
}

input, select, textarea {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid #cfc7b6;
  border-radius: 6px;
  background: #fff;
  color: #1f2933;
  font: inherit;
}

textarea { resize: vertical; }

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 52px;
}

.page.wide { width: min(1600px, calc(100% - 24px)); }
.page.admin-page { width: calc(100% - 16px); }
.page.narrow { width: min(520px, calc(100% - 32px)); }
.page-title { margin-bottom: 18px; }
.page-title h1 { color: #284623; }

.row-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

.panel.compact { padding: 12px; }

.form {
  display: grid;
  gap: 14px;
}

.inline-form,
.filters,
.admin-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.ximiya-modal {
  width: min(560px, calc(100% - 28px));
  padding: 0;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  background: #fffdf8;
  color: #1f2933;
  box-shadow: 0 22px 70px rgba(31, 41, 51, 0.32);
}

.ximiya-modal::backdrop {
  background: rgba(24, 31, 22, 0.42);
}

.ximiya-modal-form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.ximiya-modal-form h2 {
  margin-bottom: 4px;
}

.ximiya-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.ximiya-treatment-products-editor {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #d8d1bf;
  border-radius: 6px;
  background: #f8f5ec;
}

.ximiya-treatment-products-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

.ximiya-treatment-product-rows {
  display: grid;
  gap: 8px;
}

.ximiya-treatment-product-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(90px, 120px) minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.ximiya-treatment-product-row label {
  display: grid;
  gap: 4px;
}

.ximiya-treatment-product-meta {
  display: grid;
  gap: 2px;
  min-height: 38px;
  color: #5d6657;
  font-size: 12px;
  line-height: 1.25;
}

@media (max-width: 700px) {
  .ximiya-treatment-product-row {
    grid-template-columns: 1fr;
  }
}

.inline-form input,
.filters label,
.filters .ximiya-filter-control,
.admin-form input,
.admin-form select {
  min-width: 170px;
}

.admin-form select[name="ai_access_level"] {
  min-width: 150px;
}

.ximiya-filter-control {
  position: relative;
  display: grid;
  gap: 5px;
}

.ximiya-filter-control > span {
  font-weight: 700;
}

.ximiya-check-dropdown {
  position: relative;
}

.ximiya-check-dropdown summary {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 34px 8px 12px;
  border: 1px solid #d8d1bf;
  border-radius: 6px;
  background: #fffdf8;
  color: #203a1c;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.ximiya-check-dropdown summary::-webkit-details-marker {
  display: none;
}

.ximiya-check-dropdown summary::after {
  content: "";
  position: absolute;
  right: 12px;
  width: 7px;
  height: 7px;
  border-right: 2px solid #49683f;
  border-bottom: 2px solid #49683f;
  transform: rotate(45deg);
}

.ximiya-check-dropdown[open] summary::after {
  transform: rotate(225deg);
}

.ximiya-check-filter {
  position: absolute;
  z-index: 2000;
  top: calc(100% + 4px);
  left: 0;
  display: grid;
  gap: 2px;
  max-height: 240px;
  width: 260px;
  min-width: 220px;
  max-width: 320px;
  overflow: auto;
  padding: 6px;
  border: 1px solid #d8d1bf;
  border-radius: 6px;
  background: #fffdf8;
  box-shadow: 0 10px 24px rgba(39, 57, 29, 0.16);
}

.ximiya-check-apply {
  position: sticky;
  top: 0;
  z-index: 1;
  width: 100%;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 5px;
  background: #49683f;
  color: #fff;
}

.filters .ximiya-check-filter label,
.ximiya-modal .ximiya-check-filter label {
  display: flex;
  align-items: center;
  gap: 7px;
  width: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  padding: 4px 6px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.filters .ximiya-check-filter label:hover,
.ximiya-modal .ximiya-check-filter label:hover {
  background: #f3f0e6;
}

.filters .ximiya-check-filter input[type="checkbox"],
.ximiya-modal .ximiya-check-filter input[type="checkbox"] {
  display: inline-block !important;
  flex: 0 0 14px !important;
  width: 14px !important;
  height: 14px !important;
  min-width: 14px !important;
  max-width: 14px !important;
  min-height: 14px !important;
  max-height: 14px !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 2px;
}

.filters .ximiya-check-filter label span,
.ximiya-modal .ximiya-check-filter label span {
  display: inline !important;
  margin: 0 !important;
  color: #1f2933 !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
  white-space: normal;
}

.inline-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.grid-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}

.action-card {
  display: grid;
  gap: 8px;
  min-height: 124px;
  padding: 18px;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  background: #fff;
  text-decoration: none;
}

.action-card strong { color: #31522b; }
.action-card span { color: #57606a; }

.table-wrap {
  overflow: auto;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  background: #fff;
}

.table-wrap.massive { max-height: 72vh; }

.ximiya-map {
  width: 100%;
  height: min(80vh, 806px);
  min-height: 546px;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  background: #e9ecef;
  overflow: hidden;
}

.ximiya-map-workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(420px, 1fr);
  gap: 16px;
  align-items: stretch;
  width: 100%;
  margin: 18px 0;
}

.ximiya-map-pane,
.ximiya-map-table-pane {
  min-width: 0;
}

.ximiya-map-source-table {
  display: none;
}

.ximiya-map-table-pane .ximiya-map-source-table {
  display: block;
}

.ximiya-map-table-wrap {
  max-height: min(80vh, 806px);
  overflow: auto;
}

.ximiya-map-table {
  font-size: 13px;
}

.ximiya-map-table th,
.ximiya-map-table td {
  padding: 7px 8px;
}

.ximiya-map-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.ximiya-map-table tfoot th {
  border-top: 2px solid #49683f;
  background: #f5f8ef;
  font-weight: 800;
  text-align: right;
}

.ximiya-sort-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.ximiya-sort-button[data-sort-active="asc"]::after {
  content: " ^";
}

.ximiya-sort-button[data-sort-active="desc"]::after {
  content: " v";
}

.ximiya-map-table td:nth-child(2) span {
  display: block;
  white-space: nowrap;
}

.ximiya-row-credited {
  background: #e3f4dd;
}

.ximiya-row-uncredited {
  background: #ffe3dd;
}

.ximiya-row-credited.ximiya-selected-row,
.ximiya-row-uncredited.ximiya-selected-row {
  outline: 2px solid #c48a22;
  outline-offset: -2px;
}

.ximiya-field-cell {
  min-width: 92px;
}

.ximiya-field-focus {
  padding: 0;
  border: 0;
  background: transparent;
  color: #173f82;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.ximiya-field-focus:hover {
  text-decoration: underline;
}

.ximiya-row-select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.ximiya-hidden-form {
  display: none;
}

.ximiya-map-empty {
  padding: 12px 0;
  color: #6b7280;
}

.ximiya-transport-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.ximiya-transport-map-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  margin: 18px 0;
}

.ximiya-transport-sidebar {
  align-self: stretch;
  max-height: min(96vh, 968px);
  overflow: auto;
}

.ximiya-transport-sidebar label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  font-size: 12px;
  line-height: 1.25;
}

.ximiya-transport-sidebar input[type="checkbox"] {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
}

.ximiya-transport-map-panel {
  min-width: 0;
}

.ximiya-transport-map {
  height: min(96vh, 968px);
  min-height: 655px;
}

.ximiya-transport-modal {
  width: min(1080px, calc(100% - 28px));
}

.ximiya-transport-edit-list {
  display: grid;
  gap: 8px;
  max-height: 54vh;
  overflow: auto;
  padding: 0 18px 18px;
}

.ximiya-transport-edit-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) minmax(120px, 0.8fr) minmax(120px, 0.8fr) 52px minmax(160px, 1.2fr) auto;
  gap: 8px;
  align-items: center;
}

.ximiya-transport-delete-row {
  display: flex;
  justify-content: flex-end;
  margin-top: -6px;
}

.ximiya-field-label {
  padding: 2px 6px;
  border: 1px solid rgba(49, 82, 43, 0.35);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.82);
  color: #203a1c;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16);
  pointer-events: none;
}

.ximiya-track-tooltip {
  color: #172033;
  font-size: 12px;
  line-height: 1.35;
}

.ximiya-color-chip {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  border: 1px solid #b8b09d;
  border-radius: 4px;
  vertical-align: middle;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid #e8e0cf;
  border-right: 1px solid #eee7d8;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8f4ea;
  color: #31522b;
  font-weight: 700;
}

.timesheet-edit th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.employee {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 220px;
  background: #f8f4ea;
}

.employee span {
  display: block;
  margin-top: 4px;
  color: #6b7280;
  font-size: 12px;
}

.day-cell { min-width: 190px; }
.hours-input { max-width: 76px; }

.day-block {
  margin: 0 0 22px;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.day-block-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: #f8f4ea;
  border-bottom: 1px solid #d8d1bf;
}

.day-block-head h2 {
  margin: 0;
  color: #284623;
}

.day-block-head span,
.muted {
  display: block;
  margin-top: 4px;
  color: #6b7280;
  font-size: 12px;
}

.add-worker {
  width: min(360px, 100%);
}

.day-actions {
  padding: 12px 16px;
  border-top: 1px solid #e8e0cf;
}

.add-worker-panel {
  padding: 12px 16px;
  border-top: 1px solid #e8e0cf;
  background: #fffdf8;
}

.add-worker-panel label {
  display: block;
  width: min(420px, 100%);
}

.daily-timesheet th:first-child,
.daily-timesheet td:first-child {
  width: 72px;
  text-align: center;
}

.daily-timesheet th:nth-child(2) {
  min-width: 220px;
}

.daily-timesheet th:nth-child(3) { min-width: 220px; }
.daily-timesheet th:nth-child(4) { min-width: 150px; }
.daily-timesheet th:nth-child(5) { min-width: 260px; }

.accounting-table th:nth-child(2) { min-width: 220px; }
.accounting-table th:nth-child(3),
.accounting-table th:nth-child(4) { min-width: 170px; }
.accounting-table th:nth-child(5) { min-width: 150px; }
.accounting-table th:nth-child(8) { min-width: 170px; }
.accounting-table th:nth-child(9) { min-width: 220px; }

.check-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.check-line input {
  width: auto;
  min-height: 0;
}

.admin-users-wrap table {
  font-size: 12px;
  table-layout: fixed;
  min-width: 1080px;
}

.admin-users-wrap th,
.admin-users-wrap td {
  padding: 6px 7px;
  overflow: hidden;
}

.admin-users-wrap input,
.admin-users-wrap select {
  min-height: 30px;
  padding: 5px 7px;
  border-radius: 5px;
  font-size: 12px;
}

.admin-users-wrap input,
.admin-users-wrap select {
  width: 100%;
  min-width: 0;
}

.admin-users-wrap .admin-col-name {
  width: 190px;
}

.admin-users-wrap .admin-col-login {
  width: 105px;
}

.admin-users-wrap .admin-col-role {
  width: 108px;
}

.admin-users-wrap .admin-col-ai {
  width: 145px;
}

.admin-users-wrap .admin-col-position {
  width: 120px;
}

.admin-users-wrap .admin-col-department,
.admin-users-wrap .admin-col-managed {
  width: 118px;
}

.admin-users-wrap .admin-col-transport,
.admin-users-wrap .admin-col-ximiya {
  width: 42px;
  min-width: 42px;
  text-align: center;
}

.admin-users-wrap .admin-col-save {
  width: 132px;
}

.admin-users-wrap .check-line {
  gap: 4px;
  white-space: nowrap;
}

.admin-users-wrap .compact-check {
  justify-content: center;
}

.admin-users-wrap .compact-check input {
  width: 16px;
}

.admin-save-cell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 4px;
}

.admin-save-cell button {
  min-height: 30px;
  padding: 5px 6px;
}

.sklad-page {
  width: calc(100% - 18px);
}

.sklad-topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.sklad-status {
  margin-left: auto;
  color: #667085;
  font-size: 12px;
}

.sklad-topbar .active {
  background: #456b35;
  color: #fff;
}

.sklad-ref-dropdown {
  position: relative;
  display: inline-flex;
}

.sklad-ref-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  min-width: 170px;
  padding: 6px;
  display: grid;
  gap: 4px;
  border: 1px solid #d8cdb8;
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 10px 26px rgba(34, 28, 16, 0.14);
}

.sklad-ref-menu[hidden] {
  display: none;
}

.sklad-ref-menu button {
  width: 100%;
  justify-content: flex-start;
  min-height: 30px;
  padding: 5px 8px;
}

.sklad-filters {
  display: grid;
  grid-template-columns: repeat(10, minmax(86px, 1fr));
  gap: 6px;
  align-items: end;
}

.sklad-filters label {
  min-width: 0;
}

.sklad-filters input,
.sklad-filters select {
  min-height: 32px;
  padding: 5px 7px;
  font-size: 12px;
}

.sklad-layout {
  display: block;
}

.sklad-hidden {
  display: none !important;
}

.sklad-table {
  font-size: 12px;
}

.sklad-table th,
.sklad-table td {
  padding: 7px 8px;
  vertical-align: top;
}

.sklad-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8f4ea;
}

.sklad-table .num {
  text-align: right;
  white-space: nowrap;
}

.sklad-movements-wrap,
.sklad-balances-wrap {
  max-height: calc(100vh - 210px);
}

.sklad-row {
  cursor: pointer;
}

.sklad-row:hover,
.sklad-selected-row {
  background: #fff1d6;
}

.sklad-select {
  width: 16px;
  min-height: 16px;
}

.sklad-modal {
  width: min(780px, calc(100% - 28px));
}

.sklad-modal .ximiya-modal-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.sklad-modal h2,
.sklad-modal .ximiya-modal-actions,
.sklad-modal label:last-of-type {
  grid-column: 1 / -1;
}

.sklad-transfer-balance {
  grid-column: 1 / -1;
  padding: 8px 10px;
  border: 1px solid #b7d7c0;
  border-radius: 6px;
  background: #f1fbf3;
  color: #17633a;
  font-size: 13px;
}

.sklad-transfer-balance.is-error {
  border-color: #f4a6a6;
  background: #fff1f1;
  color: #9f1d1d;
}

.sklad-transfer-balance[hidden] {
  display: none;
}

.sklad-refs-modal {
  width: min(900px, calc(100% - 28px));
}

.sklad-ref-editor {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(320px, 1.1fr);
  gap: 12px;
  align-items: start;
}

.sklad-ref-editor-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.sklad-ref-editor-form .ximiya-modal-actions,
.sklad-ref-editor-form .check-line {
  grid-column: 1 / -1;
}

.sklad-ref-editor-form input,
.sklad-ref-editor-form select {
  min-height: 32px;
  padding: 5px 7px;
}

.sklad-ref-list {
  display: grid;
  gap: 6px;
  max-height: 340px;
  overflow: auto;
}

.sklad-ref-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, auto) auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid #e1dac7;
  border-radius: 6px;
  background: #fff;
  cursor: context-menu;
}

.sklad-ref-row:hover {
  background: #fff7e6;
}

.sklad-ref-row strong,
.sklad-ref-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sklad-ref-row span {
  color: #667085;
  font-size: 12px;
}

.sklad-ref-row em {
  color: #9a3412;
  font-size: 12px;
  font-style: normal;
}

.sklad-ref-row.is-inactive {
  opacity: 0.62;
}

.sklad-ref-context {
  position: fixed;
  z-index: 1000;
  min-width: 150px;
  padding: 5px;
  display: grid;
  gap: 4px;
  border: 1px solid #d8cdb8;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(34, 28, 16, 0.18);
}

.sklad-ref-context[hidden] {
  display: none;
}

.sklad-ref-context button {
  width: 100%;
  justify-content: flex-start;
  min-height: 30px;
  padding: 5px 8px;
}

@media (max-width: 820px) {
  .sklad-ref-editor {
    grid-template-columns: 1fr;
  }
}

@media print {
  .sklad-no-print,
  .topbar,
  .flash {
    display: none !important;
  }
  .sklad-page {
    width: 100%;
    margin: 0;
  }
  .sklad-layout {
    display: block;
  }
  .sklad-movements-wrap,
  .sklad-balances-wrap {
    max-height: none;
    overflow: visible;
    margin-bottom: 18px;
  }
}

.summary,
.summary-list {
  margin-top: 16px;
  font-size: 18px;
}

.summary-list div {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #e8e0cf;
}

.summary-list .ximiya-total-hectares {
  padding: 12px 0;
  color: #203a1c;
  font-size: 20px;
}

.summary-list .ximiya-total-hectares strong {
  font-size: 24px;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  padding: 12px 0;
  background: linear-gradient(180deg, rgba(244, 241, 232, 0), #f4f1e8 35%);
}

.flash {
  width: min(900px, calc(100% - 32px));
  margin: 14px auto;
  padding: 12px 14px;
  border-radius: 6px;
  font-weight: 700;
}

.flash-success { background: #e7f4df; color: #31522b; }
.flash-error { background: #ffe5df; color: #8a2d1b; }
.error-box { white-space: pre-wrap; color: #8a2d1b; }
.print-page { background: #fff; }
.ximiya-field-done { color: #b42318; font-weight: 700; }
.ximiya-field-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.25;
}

.ximiya-selected-row {
  background: #fff1d6;
}

.ximiya-treatment-row {
  cursor: pointer;
}

.ximiya-treatment-row:hover {
  background: #f8f4ea;
}

.ximiya-context-menu {
  position: absolute;
  z-index: 1000;
  min-width: 210px;
  padding: 6px;
  border: 1px solid #c9bea7;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(39, 54, 31, 0.18);
}

.ximiya-context-menu button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #24351f;
  text-align: left;
  font-weight: 600;
}

.ximiya-context-menu button:hover {
  background: #f8f4ea;
}

.ximiya-context-menu button:disabled {
  color: #9ca3af;
  cursor: not-allowed;
}

.ai-page {
  min-height: calc(100vh - 118px);
}

.ai-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 680px;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  overflow: hidden;
  background: #fffdf8;
  box-shadow: 0 12px 34px rgba(41, 35, 18, 0.10);
}

.ai-sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-right: 1px solid #d8d1bf;
  background: #f8f4ea;
}

.ai-new-chat {
  width: 100%;
}

.ai-model-switch {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 6px;
}

.ai-model-switch button,
.ai-model-switch a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid #7a8b50;
  border-radius: 6px;
  background: #fffdf8;
  color: #31522b;
  font-weight: 700;
  text-decoration: none;
}

.ai-model-switch .active {
  background: #456b35;
  color: #fff;
}

.ai-model-note {
  padding: 8px 10px;
  border: 1px solid #e1dac7;
  border-radius: 6px;
  background: #fffdf8;
  color: #5f685d;
  font-size: 12px;
  line-height: 1.35;
}

.ai-model-note-hidden {
  display: none;
}

.ai-balance {
  display: grid;
  gap: 6px;
}

.ai-balance button {
  width: 100%;
}

.ai-key-form {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid #d8d1bf;
  border-radius: 6px;
  background: #fffaf0;
}

.ai-key-form label,
.ai-key-form small {
  color: #5f685d;
  font-size: 12px;
}

.ai-key-form div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.ai-key-form input,
.ai-key-form select {
  min-width: 0;
  height: 36px;
  padding: 8px 10px;
  border: 1px solid #cfc5ad;
  border-radius: 6px;
  background: #fff;
}

.ai-key-form select {
  width: 100%;
}

.ai-chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
}

.ai-chat-item {
  display: grid;
  justify-content: stretch;
  width: 100%;
  min-height: 54px;
  padding: 8px 10px;
  border-color: #d8d1bf;
  background: #fffdf8;
  color: #203a1c;
  text-align: left;
}

.ai-chat-item.active,
.ai-chat-item:hover {
  border-color: #7a8b50;
  background: #edf4e5;
}

.ai-chat-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-item small {
  color: #68736d;
  font-weight: 400;
}

.ai-main {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
}

.ai-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  overflow: auto;
}

.ai-empty {
  margin: auto;
  color: #68736d;
  text-align: center;
}

.ai-message {
  width: min(820px, 88%);
  padding: 12px 14px;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  line-height: 1.45;
  white-space: normal;
}

.ai-message-user {
  align-self: flex-end;
  background: #e7f4df;
  border-color: #b7cfa7;
}

.ai-message-assistant {
  align-self: flex-start;
  background: #fff;
}

.ai-message time {
  display: block;
  margin-top: 8px;
  color: #68736d;
  font-size: 12px;
}

.ai-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #d8d1bf;
  background: #f8f4ea;
}

.ai-form textarea {
  min-height: 58px;
  max-height: 180px;
}

.ai-file-input {
  display: none;
}

.ai-attach {
  min-width: 112px;
}

.ai-attach-status {
  grid-column: 1 / -1;
  min-height: 18px;
  color: #68736d;
  font-size: 13px;
  line-height: 1.35;
}

.ai-workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 340px;
  min-height: 720px;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  overflow: hidden;
  background: #fffdf8;
}

.ai-workspace-side,
.ai-workspace-context {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: #f8f4ea;
}

.ai-workspace-side {
  border-right: 1px solid #d8d1bf;
}

.ai-workspace-context {
  border-left: 1px solid #d8d1bf;
}

.ai-project-form {
  display: grid;
  gap: 8px;
}

.ai-project-form input,
.ai-project-form select,
.ai-workspace-context select,
.ai-workspace-context textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #cfc5ad;
  border-radius: 6px;
  background: #fff;
}

.ai-project-form input,
.ai-project-form select,
.ai-workspace-context select {
  height: 36px;
  padding: 8px 10px;
}

.ai-file-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: #5f685d;
  font-size: 13px;
}

.ai-file-toolbar span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  min-height: 360px;
}

.ai-file-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid #e1dac7;
  border-radius: 6px;
  background: #fffdf8;
  color: #2f3b2d;
  text-align: left;
}

.ai-file-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-file-item small {
  color: #7b8177;
  font-size: 11px;
}

.ai-workspace-chat {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
}

.ai-open-file {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid #e1dac7;
  border-radius: 6px;
  background: #fffdf8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #33402f;
}

#aiFilePreview {
  min-height: 260px;
  resize: vertical;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.ai-proposal {
  display: grid;
  gap: 8px;
}

.ai-proposal span {
  color: #5f685d;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.ai-agent-page {
  width: calc(100% - 18px);
  min-height: calc(100vh - 110px);
}

.codex-embed {
  display: grid;
  grid-template-rows: auto minmax(640px, calc(100vh - 170px));
  gap: 12px;
}

.codex-embed-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.codex-embed-head h1 {
  margin: 0 0 4px;
  color: #284623;
}

.codex-embed-head p {
  margin: 0;
  color: #5f685d;
}

.codex-embed iframe {
  width: 100%;
  height: 100%;
  min-height: 640px;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  background: #fff;
}

.codex-agent-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #d9ddce;
  border-radius: 8px;
  background: #f8faf3;
}

.codex-agent-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.codex-agent-head h2 {
  margin: 0 0 3px;
  font-size: 18px;
  color: #284623;
}

.codex-agent-head p {
  margin: 0;
  color: #5f685d;
  font-size: 13px;
}

.codex-agent-status {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid #cbd6bf;
  border-radius: 999px;
  background: #fff;
  color: #33502b;
  font-size: 12px;
  font-weight: 700;
}

.codex-agent-grid {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(160px, 1fr) minmax(150px, 0.9fr) minmax(260px, 2fr);
  gap: 8px;
}

.codex-agent-grid label,
.codex-agent-prompt {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #5f685d;
  font-size: 12px;
  font-weight: 700;
}

.codex-agent-grid input,
.codex-agent-grid select,
.codex-agent-prompt textarea {
  width: 100%;
  min-width: 0;
}

.codex-agent-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.codex-agent-log {
  margin: 0;
  min-height: 160px;
  max-height: 320px;
  overflow: auto;
  padding: 10px;
  border: 1px solid #d8ddcd;
  border-radius: 6px;
  background: #151a16;
  color: #eaf1e6;
  font-size: 12px;
  white-space: pre-wrap;
}

.ai-agent-shell {
  display: grid;
  grid-template-columns: 300px minmax(460px, 1fr) 420px;
  grid-template-rows: minmax(520px, calc(100vh - 360px)) 260px;
  border: 1px solid #d8d1bf;
  border-radius: 8px;
  background: #fffdf8;
  overflow: hidden;
}

.ai-agent-files,
.ai-agent-editor,
.ai-agent-chat,
.ai-agent-bottom {
  min-width: 0;
  min-height: 0;
}

.ai-agent-files {
  display: grid;
  grid-template-rows: auto auto auto auto auto auto auto minmax(0, 1fr);
  gap: 8px;
  padding: 10px;
  border-right: 1px solid #d8d1bf;
}

.ai-agent-editor {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  padding: 10px;
}

.ai-agent-chat {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border-left: 1px solid #d8d1bf;
}

.ai-agent-bottom {
  grid-column: 1 / -1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-top: 1px solid #d8d1bf;
  background: #fff;
}

.ai-agent-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ai-agent-toolbar strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: auto;
}

.ai-agent-path,
.ai-agent-key {
  padding: 7px 9px;
  border: 1px solid #e1dac7;
  border-radius: 6px;
  background: #f8f4ea;
  color: #5f685d;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-agent-label {
  color: #5f685d;
  font-size: 12px;
  font-weight: 700;
}

#agentProjectRoot,
#agentMode {
  width: 100%;
  min-width: 0;
}

.ai-agent-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: auto;
}

.ai-agent-file {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  justify-content: stretch;
  gap: 8px;
  min-height: 32px;
  padding: 6px 8px;
  background: #fff;
  color: #1f2933;
  border: 1px solid #e1dac7;
}

.ai-agent-file span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.ai-agent-file small {
  color: #68736d;
  font-weight: 400;
}

#agentEditor,
#agentProposalContent {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre;
  overflow: auto;
}

.ai-agent-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.ai-agent-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 8px;
  align-items: end;
}

.ai-agent-form textarea {
  min-height: 82px;
  max-height: 180px;
}

.ai-agent-tabs {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid #e1dac7;
}

.ai-agent-tabs button {
  min-height: 30px;
  padding: 5px 10px;
}

.ai-agent-tabs .active {
  background: #456b35;
  color: #fff;
}

.ai-agent-bottom pre,
.ai-agent-proposal {
  margin: 0;
  padding: 10px;
  overflow: auto;
  min-height: 0;
  white-space: pre-wrap;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.ai-agent-proposal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

#aiProposalContent {
  min-height: 220px;
  font-family: Consolas, monospace;
  font-size: 12px;
}

@media print {
  .topbar, .nav, .button, button { display: none !important; }
  .page { width: 100%; margin: 0; }
  .table-wrap { border: 0; }

  body.ximiya-printing-map-table .topbar,
  body.ximiya-printing-map-table .nav,
  body.ximiya-printing-map-table .filters,
  body.ximiya-printing-map-table .ximiya-map-pane,
  body.ximiya-printing-map-table .ximiya-map-summary-panel,
  body.ximiya-printing-map-table .ximiya-context-menu,
  body.ximiya-printing-map-table .ximiya-map-empty,
  body.ximiya-printing-map-table .ximiya-row-select,
  body.ximiya-printing-map-table .ximiya-hidden-form {
    display: none !important;
  }

  body.ximiya-printing-map-table .page {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  body.ximiya-printing-map-table .ximiya-map-workspace {
    display: block;
    margin: 0;
  }

  body.ximiya-printing-map-table .ximiya-map-table-pane,
  body.ximiya-printing-map-table .ximiya-map-source-table {
    display: block !important;
  }

  body.ximiya-printing-map-table .ximiya-map-table-wrap {
    max-height: none;
    overflow: visible;
  }

  body.ximiya-printing-map-table .ximiya-map-table {
    width: 100%;
    font-size: 11px;
  }

  body.ximiya-printing-map-table .ximiya-map-table button {
    display: inline !important;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
  }
}

@media (max-width: 760px) {
  .topbar,
  .row-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .ximiya-map-workspace {
    grid-template-columns: 1fr;
  }

  .ximiya-transport-map-layout {
    grid-template-columns: 1fr;
  }

  .ximiya-transport-sidebar {
    max-height: 220px;
  }

  .ximiya-transport-edit-row {
    grid-template-columns: 1fr;
  }

  .ximiya-map {
    height: 560px;
  }

  .login-panel { grid-template-columns: 1fr; }

  .hero-overlay {
    align-items: flex-end;
    padding: 28px 16px;
  }

  .ai-shell {
    grid-template-columns: 1fr;
    min-height: calc(100vh - 180px);
  }

  .ai-workspace {
    grid-template-columns: 1fr;
  }

  .ai-workspace-side,
  .ai-workspace-context {
    border: 0;
    border-bottom: 1px solid #d8d1bf;
  }

  .codex-agent-head {
    flex-direction: column;
  }

  .codex-agent-grid {
    grid-template-columns: 1fr;
  }

  .ai-sidebar {
    max-height: 230px;
    border-right: 0;
    border-bottom: 1px solid #d8d1bf;
  }

  .ai-message {
    width: 100%;
  }

  .ai-form {
    grid-template-columns: 1fr;
  }

  .ai-attach-status {
    grid-column: auto;
  }

}
