* {
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f5f5f5;
}

header {
  background: #2c3e50;
  color: white;
}

.menu {
  list-style: none;
  margin: 0;
  padding: 10px;
  display: flex;
  gap: 15px;
}

.menu li {
  display: inline;
  position: relative;
}

.menu a {
  color: white;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.3s;
  display: block;
}

.menu a:hover {
  background-color: #34495e;
}

/* Estilos para dropdown */
.dropdown {
  position: relative;
}

.dropdown > a::after {
  content: " ▼";
  font-size: 10px;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  list-style: none;
  margin: 0;
  padding: 8px 0;
  background-color: #34495e;
  border-radius: 4px;
  min-width: 200px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  z-index: 1000;
}

.dropdown:hover .dropdown-menu {
  display: block;
}

.dropdown-menu li {
  display: block;
  margin: 0;
}

.dropdown-menu a {
  padding: 12px 16px;
  color: white;
  text-decoration: none;
  display: block;
  border-radius: 0;
  transition: background-color 0.3s;
}

.dropdown-menu a:hover {
  background-color: #2c3e50;
  padding-left: 20px;
}

main {
  padding: 20px;
}

/* Estilos para Login */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 32px 20px;
  box-sizing: border-box;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-page-content {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.login-heading {
  text-align: center;
  color: #ffffff;
  background: transparent;
  padding: 0;
}

.login-heading h1 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 1.8rem);
  line-height: 1.25;
  font-weight: 700;
}

.login-heading p {
  margin: 8px 0 0;
  font-size: 1rem;
  font-weight: 600;
}

.login-form {
  background: white;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
}

.login-copyright {
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.4;
}

.login-form h2 {
  text-align: center;
  color: #2c3e50;
  margin-top: 0;
}

.login-form div {
  margin-bottom: 20px;
}

.login-form label {
  display: block;
  margin-bottom: 8px;
  color: #2c3e50;
  font-weight: bold;
}

.login-form input[type="text"],
.login-form input[type="password"] {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.3s;
}

.login-form input[type="text"]:focus,
.login-form input[type="password"]:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 5px rgba(102, 126, 234, 0.5);
}

.login-form input[type="submit"] {
  width: 100%;
  padding: 12px;
  background-color: #667eea;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.3s;
}

.login-form input[type="submit"]:hover {
  background-color: #5568d3;
}

/* Mensajes Flash */
.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 20px 0;
}

.flashes li {
  padding: 12px;
  margin-bottom: 10px;
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
}

/* Estilos para Tablas */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  background-color: white;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

table thead {
  background-color: #2c3e50;
  color: white;
}

table th {
  padding: 15px;
  text-align: left;
  font-weight: bold;
  border-bottom: 2px solid #34495e;
}

table td {
  padding: 12px 15px;
  border-bottom: 1px solid #e0e0e0;
}

table tbody tr:hover {
  background-color: #f9f9f9;
  transition: background-color 0.3s;
}

table tbody tr:last-child td {
  border-bottom: none;
}

/* Estilos para enlaces */
main a {
  color: #667eea;
  text-decoration: none;
  transition: color 0.3s;
}

main a:hover {
  color: #5568d3;
  text-decoration: underline;
}

/* Estilos para botones */
.btn-primary, .btn-edit, .btn-delete, .btn-submit, .btn-cancel {
  padding: 10px 15px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.3s;
  text-decoration: none;
  display: inline-block;
  margin-right: 5px;
}

.btn-primary {
  background-color: #667eea;
  color: white;
}

.btn-primary:hover {
  background-color: #5568d3;
}

.btn-edit {
  background-color: #3498db;
  color: white;
  padding: 6px 12px;
  font-size: 12px;
}

.btn-edit:hover {
  background-color: #2980b9;
}

.btn-delete {
  background-color: #e74c3c;
  color: white;
  padding: 6px 12px;
  font-size: 12px;
}

.btn-delete:hover {
  background-color: #c0392b;
}

.btn-submit {
  background-color: #27ae60;
  color: white;
  padding: 12px 30px;
  font-size: 16px;
}

.btn-submit:hover {
  background-color: #229954;
}

.btn-cancel {
  background-color: #95a5a6;
  color: white;
  padding: 10px 15px;
}

.btn-cancel:hover {
  background-color: #7f8c8d;
}

.client-search-form {
  max-width: 720px;
  margin: 20px 0;
}

.client-search-form label {
  display: block;
  margin-bottom: 8px;
  color: #2c3e50;
  font-weight: bold;
}

.client-search-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.client-search-controls input {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid #d7e1ee;
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
}

.client-search-controls input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

.client-search-empty {
  color: #667085;
  font-style: italic;
}

.clients-table .col-rut,
.clients-table .col-name {
  white-space: nowrap;
}

.clients-table .col-name {
  max-width: 32ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

.coa-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.coa-actions form {
  margin: 0;
}

.business-line-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.business-line-actions form {
  display: inline-flex;
  margin: 0;
}

@media (max-width: 768px) {
  .business-line-actions-cell {
    min-width: 150px;
  }
}

@media (max-width: 600px) {
  .client-search-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .client-search-controls input,
  .client-search-controls button,
  .client-search-controls a {
    width: 100%;
    text-align: center;
  }
}

/* Estilos para formularios */
.client-form-shell {
  max-width: 1200px;
  margin: 0 auto;
}

.client-form-shell h2 {
  margin-bottom: 20px;
  color: #1f2d3d;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.user-form {
  max-width: 1200px;
  background: linear-gradient(180deg, #ffffff 0%, #f9fbfd 100%);
  padding: 28px 28px 18px;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  border: 1px solid #e3eaf3;
}

.client-section {
  background: #f8fafc;
  border: 1px solid #e6edf5;
  border-left: 4px solid #667eea;
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 22px;
}

.client-section h3 {
  margin: 0 0 18px 0;
  color: #1f2d3d;
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.client-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 20px 24px;
}

.account-suggestions {
  position: relative;
  z-index: 5;
  max-height: 240px;
  overflow-y: auto;
}

.account-suggestion {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d7dce2;
  border-top: 0;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.account-suggestion:hover {
  background: #eef5fb;
}

.account-suggestion small {
  display: block;
  color: #5f6b76;
}

.form-group {
  margin-bottom: 20px;
}

.client-form .full-width {
  grid-column: 1 / -1;
}

.authorized-documents-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 10px;
  margin-top: 10px;
  border: 1px solid #d7e1ee;
  border-radius: 8px;
  background: #f8fafc;
}

.authorized-document-option {
  border: 1px solid #d7e1ee;
  border-radius: 7px;
  padding: 9px 10px;
  background: #ffffff;
  color: #1f2d3d;
  text-align: left;
  cursor: pointer;
}

.authorized-document-option:hover,
.authorized-document-option.is-selected {
  border-color: #27ae60;
  background: #eaf8ef;
}

.authorized-document-check {
  display: inline-flex;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  margin-right: 5px;
  border-radius: 50%;
  color: #fff;
  background: #b8c2cc;
  font-size: 12px;
}

.authorized-document-option.is-selected .authorized-document-check {
  background: #27ae60;
}

.authorized-document-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  min-height: 42px;
  box-sizing: border-box;
}

.authorized-document-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 12px;
  border-left: 3px solid #27ae60;
  background: #f2faf4;
  color: #344054;
  font-size: 13px;
  min-height: 42px;
  box-sizing: border-box;
  align-items: center;
}

.authorized-document-detail strong {
  flex-basis: 100%;
  color: #216e39;
}

@media (max-width: 768px) {
  .authorized-documents-picker {
    grid-template-columns: 1fr;
  }
}

.partners-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.economic-activities-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.economic-activity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #d7e1ee;
  border-left: 3px solid #667eea;
  border-radius: 7px;
  background: #fff;
  color: #1f2d3d;
}

.income-document-file {
  display: none;
}

.activity-remove {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: #e74c3c;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.partners-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.partners-label-row label {
  margin-bottom: 0;
}

.partners-help {
  color: #667085;
  font-size: 0.85rem;
  font-weight: 400;
}

.partner-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(190px, 260px) auto;
  gap: 10px;
  align-items: start;
}

.partner-row .partner-rut-error {
  grid-column: 3;
  margin-top: -4px;
}

.partner-confirm,
.partner-remove {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.partner-confirm {
  background: #27ae60;
}

.partner-remove {
  background: #e74c3c;
}

@media (max-width: 768px) {
  .partner-row {
    grid-template-columns: 1fr;
  }

  .partner-row .partner-rut-error {
    grid-column: auto;
    margin-top: -6px;
  }
}

.checkbox-group {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding-top: 14px;
}

.checkbox-group input[type="checkbox"] {
  margin-right: 10px;
  width: 18px;
  height: 18px;
}

.user-form label {
  display: block;
  margin-bottom: 8px;
  color: #2c3e50;
  font-weight: bold;
}

.user-form input[type="text"],
.user-form input[type="email"],
.user-form input[type="password"],
.user-form select,
.user-form textarea,
.user-form input[type="date"],
.user-form .form-control {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #d7e1ee;
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
  background-color: #fff;
  color: #1f2d3d;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.user-form input[type="text"]:focus,
.user-form input[type="email"]:focus,
.user-form input[type="password"]:focus,
.user-form select:focus,
.user-form textarea:focus,
.user-form input[type="date"]:focus,
.user-form .form-control:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

@media (max-width: 768px) {
  .client-form-grid {
    grid-template-columns: 1fr;
  }

  .user-form {
    padding: 20px;
  }
}

.user-form input[type="checkbox"] {
  margin-right: 8px;
  cursor: pointer;
}

.form-errors {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  padding: 15px;
  margin-bottom: 20px;
}

.form-errors ul {
  margin: 0;
  padding-left: 20px;
}

.field-errors {
  color: #e74c3c;
  font-size: 12px;
  margin-top: 5px;
  margin-bottom: 0;
}

.form-errors-summary {
  background-color: #f8d7da;
  color: #721c24;
  border: 2px solid #f5c6cb;
  border-radius: 4px;
  padding: 20px;
  margin-top: 30px;
  margin-bottom: 20px;
}

.form-errors-summary h3 {
  margin-top: 0;
  margin-bottom: 15px;
}

.form-errors-summary ul {
  margin: 0;
  padding-left: 20px;
  list-style-type: disc;
}

.form-errors-summary li {
  margin-bottom: 8px;
  font-size: 14px;
}

.form-actions {
  margin-top: 30px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 10px;
  border-top: 1px solid #e6edf5;
}

.user-form .form-control {
  min-height: 42px;
  background: #ffffff;
}

.taxpayer-selection-form {
  margin-bottom: 18px;
}

.taxpayer-client-picker {
  display: flex;
  gap: 10px;
  align-items: center;
}

.taxpayer-client-picker select {
  flex: 1;
}

.taxpayer-help {
  display: block;
  margin-top: 8px;
  color: #667085;
}

.taxpayer-credentials-form-shell {
  margin-top: 0;
}

.taxpayer-client-title {
  margin: 4px 0 16px;
  color: #1f2d3d;
  font-size: 1rem;
}

.taxpayer-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.taxpayer-row {
  display: grid;
  grid-template-columns: minmax(160px, 260px) minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: start;
  background: #f8fafc;
  border: 1px solid #e6edf5;
  border-left: 3px solid #667eea;
  border-radius: 10px;
  padding: 10px;
}

.taxpayer-password-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.taxpayer-eye,
.taxpayer-save,
.taxpayer-delete {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.taxpayer-eye {
  background: #475467;
  font-size: 19px;
}

.taxpayer-save {
  background: #27ae60;
}

.taxpayer-delete {
  background: #e74c3c;
}

.taxpayer-row-status {
  grid-column: 1 / -1;
  font-size: 0.86rem;
  min-height: 18px;
}

.taxpayer-row-status.ok {
  color: #0f7a35;
}

.taxpayer-row-status.error {
  color: #c62828;
}

.taxpayer-actions-bar {
  margin-top: 14px;
}

.contract-mode-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.contract-mode-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #1f2d3d;
}

.contract-panel.is-hidden {
  display: none;
}

.is-hidden {
  display: none !important;
}

.contract-template-browser {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 6px;
}

.contract-template-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid #d7e1ee;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.contract-template-item.is-selected {
  border-color: #667eea;
  background: #f4f7ff;
}

.contract-template-item input {
  margin-bottom: 6px;
}

.contract-template-name {
  font-weight: 700;
  color: #1f2d3d;
}

.contract-template-meta {
  color: #667085;
  font-size: 0.88rem;
}

.contract-message {
  margin: 14px 0;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 700;
}

.contract-message.error {
  color: #b42318;
  background: #fef3f2;
  border: 1px solid #fecdca;
}

.contract-message.success {
  color: #027a48;
  background: #ecfdf3;
  border: 1px solid #abefc6;
}

.contract-message.info {
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.is-disabled-btn {
  opacity: 0.6;
  cursor: not-allowed;
}

.contract-fields-source {
  margin-top: 0;
  color: #344054;
}

.contract-template-count {
  margin: 0 0 10px;
  color: #1d4ed8;
  font-weight: 700;
}

.contract-fields-preview {
  margin-top: 20px;
  padding: 16px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e6edf5;
}

.contract-fields-preview h4 {
  margin: 0 0 12px;
  color: #1f2d3d;
}

.contract-fields-preview ul {
  margin: 0;
  padding-left: 20px;
}

.contract-prepare-actions-top {
  border-top: 0;
  padding-top: 0;
  margin-top: 8px;
}

.contract-preview-box {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
  border: 1px solid #e6edf5;
  border-radius: 10px;
  padding: 16px;
  max-height: 520px;
  overflow-y: auto;
  color: #1f2d3d;
  font-family: inherit;
  line-height: 1.5;
}

.contract-preview-wrapper {
  background: #ebeff5;
  border-radius: 12px;
  padding: 32px 16px;
  max-height: 720px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.contract-preview-page {
  position: relative;
  width: 21cm;
  max-width: 100%;
  min-height: 29.7cm;
  background: #ffffff;
  box-shadow: 0 4px 18px rgba(31, 45, 61, 0.18);
  padding: 2.5cm 2.5cm 3cm;
  box-sizing: border-box;
  font-family: 'Times New Roman', Georgia, serif;
  font-size: 12pt;
  line-height: 1.6;
  color: #1a1a1a;
}

.contract-preview-page-number {
  position: absolute;
  bottom: 1cm;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 9pt;
  color: #8a94a6;
}

.contract-preview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 10px;
}

.contract-preview-table td {
  border: 1px solid #cbd5e1;
  padding: 6px 8px;
  vertical-align: top;
}

.contract-preview-table p {
  margin: 0;
}

.contract-preview-page p {
  margin: 0 0 10px;
}

.contract-preview-page p.preview-empty-line {
  margin: 0 0 10px;
}

.contract-print-actions {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

@media print {
  body * {
    visibility: hidden;
  }

  .contract-preview-wrapper,
  .contract-preview-wrapper * {
    visibility: visible;
  }

  .contract-preview-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    max-height: none;
    overflow: visible;
    background: none;
    padding: 0;
    gap: 0;
  }

  .contract-preview-page {
    box-shadow: none;
    page-break-after: always;
    margin: 0 auto;
  }

  .contract-preview-page:last-child {
    page-break-after: auto;
  }

  .contract-print-actions {
    display: none;
  }
}

@media (max-width: 900px) {
  .taxpayer-row {
    grid-template-columns: 1fr;
  }

  .taxpayer-password-wrap {
    flex-direction: column;
    align-items: stretch;
  }

  .taxpayer-eye,
  .taxpayer-save,
  .taxpayer-delete {
    width: 100%;
  }

  .taxpayer-client-picker {
    flex-direction: column;
    align-items: stretch;
  }

  .taxpayer-client-picker button {
    width: 100%;
  }
}
