:root {
  --ink: #1e2723;
  --muted: #6a756f;
  --line: #dce4dd;
  --panel: #ffffff;
  --field: #f7faf8;
  --green: #277a45;
  --green-dark: #173f2a;
  --blue: #315f84;
  --gold: #a86f13;
  --red: #b13d32;
  --shadow: 0 16px 45px rgba(29, 47, 36, .12);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #eef3ef;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  padding: 10px 14px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

button:hover { filter: brightness(.96); }

.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(12, 41, 26, .34), rgba(12, 41, 26, .3)),
    url("https://images.unsplash.com/photo-1500382017468-9049fed747ef?auto=format&fit=crop&w=1600&q=80") center / cover;
}

.login-panel {
  width: min(430px, 100%);
  background: rgba(255, 255, 255, .94);
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 8px;
  padding: 30px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 12px;
}

.login-panel h1 {
  margin: 0 0 24px;
  font-size: 31px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  background: var(--field);
  color: var(--ink);
}

textarea {
  min-height: 76px;
  resize: vertical;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 282px 1fr;
  transition: grid-template-columns .2s ease;
}

.app.menu-collapsed {
  grid-template-columns: 0 1fr;
}

.sidebar {
  background: #213629;
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  overflow: hidden;
  transition: padding .2s ease, transform .2s ease;
}

.app.menu-collapsed .sidebar {
  padding-left: 0;
  padding-right: 0;
  transform: translateX(-100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .16);
}

.mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #e7f4ea;
  color: var(--green-dark);
  font-weight: 900;
}

.brand strong, .brand small { display: block; }
.brand small { color: rgba(255, 255, 255, .68); }

.menu {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.menu-group {
  display: grid;
  gap: 4px;
}

.menu-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, .08);
  color: rgba(255, 255, 255, .62);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.menu-group-toggle:hover {
  background: rgba(255, 255, 255, .13);
}

.chevron {
  color: rgba(255, 255, 255, .8);
  font-size: 12px;
  transition: transform .15s ease;
}

.menu-group.closed .chevron {
  transform: rotate(-90deg);
}

.menu-group-items {
  display: grid;
  gap: 2px;
}

.menu-group.closed .menu-group-items {
  display: none;
}

.menu-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: rgba(255, 255, 255, .88);
  padding: 9px 10px;
}

.menu-item.active, .menu-item:hover {
  background: rgba(255, 255, 255, .12);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 20px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.menu-toggle {
  min-width: 72px;
  white-space: nowrap;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#userBadge {
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 700;
}

.ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.card {
  min-height: 116px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid;
  align-content: space-between;
}

.card:nth-child(3n + 1) { border-top: 4px solid var(--green); }
.card:nth-child(3n + 2) { border-top: 4px solid var(--blue); }
.card:nth-child(3n) { border-top: 4px solid var(--gold); }

.card small {
  color: var(--muted);
  font-weight: 800;
}

.card strong {
  font-size: 34px;
}

.table-view {
  display: grid;
  gap: 13px;
}

.employee-summary {
  display: grid;
  gap: 12px;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-cards article {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.summary-cards small {
  color: var(--muted);
  font-weight: 800;
}

.summary-cards strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.table-wrap.compact {
  box-shadow: none;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.toolbar input {
  max-width: 360px;
  background: #fff;
}

.table-wrap {
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f6faf7;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f7fbf8;
}

td.actions {
  width: 1%;
  text-align: right;
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.print-action {
  white-space: nowrap;
}

.row-danger {
  white-space: nowrap;
  padding: 9px 10px;
}

.receipt-page {
  color: #1e2723;
  font-family: Arial, sans-serif;
  max-width: 760px;
  margin: 0 auto;
  border: 1px solid #222;
  padding: 24px;
}

.receipt-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid #888;
  padding-bottom: 14px;
  margin-bottom: 20px;
}

.receipt-header h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.receipt-muted {
  color: #666;
  font-size: 13px;
}

.receipt-number {
  text-align: right;
  font-weight: 700;
}

.receipt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
  margin: 18px 0;
}

.receipt-field {
  border-bottom: 1px solid #bbb;
  padding-bottom: 8px;
}

.receipt-field small {
  display: block;
  color: #666;
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.receipt-amount {
  font-size: 26px;
  font-weight: 800;
}

.receipt-span-2 {
  grid-column: span 2;
}

.receipt-note {
  border: 1px solid #bbb;
  min-height: 78px;
  padding: 10px;
  margin-top: 6px;
}

.receipt-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
  margin-top: 58px;
}

.receipt-signature {
  border-top: 1px solid #222;
  text-align: center;
  padding-top: 8px;
  font-size: 13px;
}

.receipt-products {
  width: 100%;
  min-width: 0;
  margin: 18px 0;
  border-collapse: collapse;
}

.receipt-products th,
.receipt-products td {
  border: 1px solid #bbb;
  padding: 9px;
  white-space: normal;
}

.receipt-products th {
  background: #f6faf7;
  color: #555;
  font-size: 12px;
  text-transform: uppercase;
}

.receipt-preview {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(12, 22, 16, .48);
}

.receipt-preview-panel {
  width: min(860px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.receipt-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 14px;
}

dialog {
  width: min(820px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(12, 22, 16, .42);
}

#editorForm,
#recipeBaseForm {
  padding: 20px;
}

#editor header, #editor footer,
#recipeBaseEditor header, #recipeBaseEditor footer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

#editor footer,
#recipeBaseEditor footer {
  grid-template-columns: auto 1fr auto auto;
  margin-top: 18px;
}

#editor h2,
#recipeBaseEditor h2 {
  margin: 0;
}

.wide-dialog {
  width: min(1180px, calc(100vw - 28px));
}

.items-editor {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.sowing-tools {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6faf7;
  display: grid;
  gap: 12px;
}

.sowing-grid {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(130px, 1fr) minmax(130px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.sowing-grid button {
  white-space: nowrap;
  min-height: 40px;
}

.sowing-result {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  display: grid;
  align-content: center;
  gap: 4px;
}

.sowing-result small {
  color: var(--muted);
  font-weight: 800;
}

.sowing-result strong {
  font-size: 15px;
}

.items-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.items-title h3 {
  margin: 0;
}

.items-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.items-table {
  min-width: 900px;
}

.items-table input,
.items-table select {
  min-width: 120px;
  padding: 8px 9px;
}

.items-table .small-input {
  min-width: 82px;
}

.items-table .wide-input {
  min-width: 170px;
}

.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  background: #eef3ef;
  color: var(--ink);
  font-size: 24px;
}

.fields {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.span-2 {
  grid-column: span 2;
}

.span-3 {
  grid-column: span 3;
}

.danger {
  background: var(--red);
}

.error {
  min-height: 19px;
  margin: 4px 0 0;
  color: var(--red);
  font-weight: 700;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }

  .app.menu-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .app.menu-collapsed .sidebar {
    display: none;
  }

  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sowing-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 16px;
  }

  .topbar, .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .title-row {
    align-items: flex-start;
  }

  .dashboard, .fields {
    grid-template-columns: 1fr;
  }

  .sowing-grid {
    grid-template-columns: 1fr;
  }

  .span-3 {
    grid-column: span 1;
  }

  .span-2 {
    grid-column: span 1;
  }
}

@media print {
  body * {
    visibility: hidden !important;
  }

  #receiptPrintArea, #receiptPrintArea * {
    visibility: visible !important;
  }

  #receiptPrintArea {
    display: block !important;
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    padding: 0;
    background: #fff;
  }

  .receipt-page {
    border: 0;
    max-width: none;
    width: 100%;
  }

  .receipt-preview-actions {
    display: none !important;
  }
}


/* Polish pass 20260719 */
button, .btn, input, select, textarea {
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease, background-color 0.18s ease;
}

button:hover, .btn:hover {
  transform: translateY(-1px);
}

button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(34, 197, 94, 0.25);
  outline-offset: 2px;
}

.table-wrap, .panel, .card {
  box-shadow: 0 14px 35px rgba(15, 23, 42, 0.08);
}

dialog {
  max-height: min(88vh, 860px);
  overflow: auto;
}

.modal-actions, .form-actions {
  gap: 10px;
}

.close-text {
  min-width: 74px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  background: #ffffff;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}
.close-text:hover {
  background: #f8fafc;
  color: #0f172a;
}


/* Ajuste botones de acciones en tablas */
td:last-child {
  white-space: nowrap;
}

td:last-child button,
td:last-child .btn {
  margin: 3px 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

td:last-child button + button,
td:last-child .btn + .btn {
  margin-left: 6px;
}

/* Acciones de tabla más prolijas */
td:last-child {
  min-width: 190px;
  white-space: normal;
}

td:last-child button {
  display: inline-block;
  min-width: 92px;
  margin: 4px 6px 4px 0;
  padding: 8px 10px;
  vertical-align: middle;
}

td:last-child button:nth-child(2) {
  margin-left: 8px;
}

/* Empleados y retiros V2 */
.withdraw-dialog { width: min(760px, calc(100vw - 24px)); }
#withdrawForm { padding: 22px; }
#withdrawForm header { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; }
#withdrawForm h2 { margin:2px 0 0; }
#withdrawForm footer { display:grid; grid-template-columns:1fr auto auto; align-items:center; gap:10px; margin-top:18px; }
.withdraw-balance { margin:18px 0; padding:18px; border:1px solid var(--line); border-radius:12px; background:linear-gradient(135deg,#f4faf6,#fff); }
.withdraw-balance small,.withdraw-balance span { display:block; color:var(--muted); font-weight:700; }
.withdraw-balance strong { display:block; font-size:34px; margin:6px 0; }
.withdraw-fields { grid-template-columns:repeat(2,minmax(0,1fr)); }
.employee-summary .table-wrap.compact { border-radius:12px; }
.employee-summary tbody tr:hover { background:#f6faf7; }
.summary-cards article { border-radius:12px; }
@media (max-width:700px){ .withdraw-fields{grid-template-columns:1fr}.withdraw-fields .span-2{grid-column:auto}.summary-cards{grid-template-columns:repeat(2,minmax(0,1fr))} }

.account-filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.account-filters button { min-height: 40px; white-space: nowrap; }

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

@media (max-width: 600px) {
  .account-filters { grid-template-columns: 1fr; }
}


/* Permisos mediante casillas */
.permission-check {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
  cursor: pointer;
}

.permission-check input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.permission-check span {
  font-weight: 750;
}

/* Matriz profesional de permisos por módulos - diseño espacioso */
#editor.permissions-dialog {
  width: min(1380px, calc(100vw - 32px));
  max-width: 1380px;
  max-height: 94vh;
}
#editor.permissions-dialog #editorForm { padding: 22px; }
#editor.permissions-dialog #fields { grid-template-columns: 1fr; }
.permissions-matrix { display: grid; gap: 18px; width: 100%; }
.permission-targets { display: grid; grid-template-columns: repeat(2, minmax(260px, 1fr)); gap: 14px; }
.permission-actions,
.permission-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbf9;
}
.permission-actions strong { margin-right: 10px; }
.permission-actions label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 700;
}
.permission-actions input,
.permission-group input,
.module-check input {
  width: 20px;
  height: 20px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--green);
}
.permission-tools { position: sticky; top: 0; z-index: 3; box-shadow: 0 8px 20px rgba(15, 23, 42, .06); }
.permission-tools input { flex: 1 1 300px; min-width: 250px; background: #fff; }
.permission-tools button { white-space: nowrap; }
.permission-groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  align-items: start;
  gap: 18px;
  max-height: 56vh;
  overflow: auto;
  padding: 3px 8px 8px 3px;
}
.permission-group {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .07);
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.permission-group:hover { transform: translateY(-1px); box-shadow: 0 12px 28px rgba(15, 23, 42, .1); }
.permission-group.is-complete { border-color: rgba(39, 122, 69, .55); }
.permission-group.is-partial { border-color: rgba(168, 111, 19, .55); }
.permission-group.filtered-out { display: none; }
.permission-group > header {
  padding: 14px 15px;
  background: #f4f7f5;
  border-bottom: 1px solid var(--line);
}
.permission-group.is-complete > header { background: #edf8f0; }
.permission-group.is-partial > header { background: #fff8e8; }
.permission-group-heading {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--ink);
}
.permission-group-title { font-size: 15px; font-weight: 850; }
.permission-group-count {
  min-width: 42px;
  padding: 4px 7px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  font-size: 11px;
  font-weight: 800;
}
.permission-group-items {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 13px;
}
.module-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: #fbfcfb;
  color: var(--ink);
  cursor: pointer;
}
.module-check:hover { background: #f1f7f3; border-color: var(--line); }
.module-check:has(input:checked) { background: #edf8f0; border-color: rgba(39, 122, 69, .28); }
.module-check span { line-height: 1.25; font-weight: 680; }
.permission-count {
  margin: 0;
  padding: 10px 2px 0;
  text-align: right;
  color: var(--muted);
  font-size: 14px;
}
.permission-count strong { color: var(--green-dark); font-size: 17px; }
@media (max-width: 1180px) {
  .permission-groups { grid-template-columns: repeat(2, minmax(260px, 1fr)); }
}
@media (max-width: 760px) {
  #editor.permissions-dialog { width: calc(100vw - 18px); }
  .permission-targets, .permission-groups { grid-template-columns: 1fr; }
  .permission-tools { position: static; }
  .permission-tools input { min-width: 100%; }
  .permission-tools button { flex: 1 1 140px; }
}

