/* ==========================================================================
   D&F Services — Componentes UI compartidos
   ========================================================================== */

/* ============== Botones ============== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.65rem 1.4rem;
  font-size: var(--fs-15);
  font-weight: var(--fw-semibold);
  line-height: 1;
  border-radius: var(--radius-pill);
  border: 1.5px solid transparent;
  transition: background var(--t-base), color var(--t-base), border-color var(--t-base), transform var(--t-fast), box-shadow var(--t-base);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}
.btn:focus-visible { outline-offset: 3px; }
.btn:hover, .btn:focus-visible { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn--primary {
  background: var(--color-primary);
  color: var(--color-white);
}
.btn--primary:hover, .btn--primary:focus-visible {
  background: var(--color-primary-600);
  color: var(--color-white);
  box-shadow: var(--shadow-md);
}

.btn--ghost {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn--ghost:hover, .btn--ghost:focus-visible {
  background: var(--color-primary);
  color: var(--color-white);
}

.btn--light {
  background: var(--color-white);
  color: var(--color-navy);
  border-color: var(--color-border);
}
.btn--light:hover, .btn--light:focus-visible {
  background: var(--color-light);
  border-color: var(--color-gray-soft);
  color: var(--color-navy);
}

.btn--danger {
  background: var(--color-error);
  color: var(--color-white);
}
.btn--danger:hover, .btn--danger:focus-visible {
  background: #a32424;
  color: var(--color-white);
  box-shadow: var(--shadow-md);
}

.btn--sm { padding: 0.45rem 1rem; font-size: var(--fs-14); }
.btn--lg { padding: 0.85rem 1.75rem; font-size: var(--fs-16); }
.btn--full { width: 100%; }
.btn[disabled], .btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
}
.btn .icon { width: 1.1em; height: 1.1em; flex: 0 0 auto; }

/* Icon-button (cuadrado) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid transparent;
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--color-light-2);
  color: var(--color-primary);
}
.icon-btn--danger:hover, .icon-btn--danger:focus-visible {
  background: var(--color-error-bg);
  color: var(--color-error);
}
.icon-btn .icon { width: 18px; height: 18px; }

/* ============== Forms ============== */

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.form-field--row {
  flex-direction: row;
  align-items: center;
  gap: var(--space-3);
}
.form-label {
  font-size: var(--fs-14);
  font-weight: var(--fw-semibold);
  color: var(--color-navy);
}
.form-label .req { color: var(--color-error); margin-left: 2px; }
.form-help {
  font-size: var(--fs-12);
  color: var(--color-text-muted);
}
.form-error {
  font-size: var(--fs-12);
  color: var(--color-error);
  display: none;
}
.form-field.has-error .form-error { display: block; }
.form-field.has-error .form-input,
.form-field.has-error .form-select,
.form-field.has-error .form-textarea {
  border-color: var(--color-error);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: var(--fs-15);
  color: var(--color-text);
  background: var(--color-white);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-50);
}
.form-input[readonly] {
  background: var(--color-light);
  color: var(--color-text-muted);
}
.form-textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 12px 8px;
  padding-right: 2.25rem;
}

/* Input group (con botón al costado) */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}
.input-group .form-input { padding-right: 2.75rem; }
.input-group__toggle {
  position: absolute;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  background: transparent;
}
.input-group__toggle:hover, .input-group__toggle:focus-visible {
  color: var(--color-primary);
  background: var(--color-light-2);
}

/* Checkbox / Radio custom */
.check, .radio {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-15);
  color: var(--color-text);
}
.check input, .radio input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.check__box {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.check input:checked + .check__box {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
.check input:checked + .check__box::after {
  content: '';
  width: 12px;
  height: 7px;
  border-left: 2px solid var(--color-white);
  border-bottom: 2px solid var(--color-white);
  transform: rotate(-45deg) translate(1px, -1px);
}
.check input:focus-visible + .check__box {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.radio__dot {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: border-color var(--t-fast);
}
.radio input:checked + .radio__dot {
  border-color: var(--color-primary);
}
.radio input:checked + .radio__dot::after {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-primary);
}
.radio input:focus-visible + .radio__dot {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ============== Cards ============== */

.card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.card__header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  background: var(--color-white);
}
.card__header h2, .card__header h3 { margin: 0; }
.card__body { padding: var(--space-5) var(--space-6); }
.card__body--flush { padding: 0; }
.card__footer {
  padding: var(--space-4) var(--space-6);
  background: var(--color-light);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ============== Badges ============== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.25rem 0.65rem;
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-pill);
  background: var(--color-light-2);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  white-space: nowrap;
}
.badge--neutral { background: var(--color-light-2); color: var(--color-text-muted); }
.badge--info    { background: var(--color-info-bg); color: var(--color-primary); }
.badge--success { background: var(--color-success-bg); color: var(--color-success); }
.badge--warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge--danger  { background: var(--color-error-bg); color: var(--color-error); }

.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* ============== Alerts ============== */

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--fs-14);
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}
.alert strong { font-weight: var(--fw-semibold); }
.alert--error   { background: var(--color-error-bg);   color: var(--color-error);   border-color: #f3c4c4; }
.alert--success { background: var(--color-success-bg); color: var(--color-success); border-color: #b8e0c7; }
.alert--warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: #f1d6a1; }
.alert--info    { background: var(--color-info-bg);    color: var(--color-primary); border-color: #bcd5e7; }

/* ============== Tablas ============== */

.table-wrap {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: auto;
  box-shadow: var(--shadow-xs);
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-14);
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--color-light-2);
  text-align: left;
  font-weight: var(--fw-semibold);
  color: var(--color-navy);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--fs-12);
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  white-space: nowrap;
}
.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  color: var(--color-text);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--color-light); }
.table td.actions, .table th.actions { text-align: right; white-space: nowrap; }
.table .col-actions { display: flex; gap: var(--space-1); justify-content: flex-end; }
.table .empty {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--color-text-muted);
}

/* ============== Modal / Drawer ============== */

.modal-backdrop, .drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 17, 27, 0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.modal-backdrop.is-open, .drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  position: fixed;
  z-index: 91;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.97);
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base), transform var(--t-base);
}
.modal.is-open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.modal__title { font-size: var(--fs-18); font-weight: var(--fw-semibold); color: var(--color-navy); margin: 0; }
.modal__body { padding: var(--space-5); overflow: auto; }
.modal__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  background: var(--color-light);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

.drawer {
  position: fixed;
  z-index: 91;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(720px, 100vw);
  background: var(--color-white);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--t-base);
}
.drawer.is-open { transform: translateX(0); }
.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-white);
  position: sticky;
  top: 0;
  z-index: 2;
}
.drawer__title { font-size: var(--fs-18); font-weight: var(--fw-semibold); color: var(--color-navy); margin: 0; }
.drawer__body { flex: 1; overflow: auto; padding: var(--space-5); }
.drawer__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  background: var(--color-light);
}

/* ============== Toasts ============== */

.toast-host {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: calc(100vw - 2rem);
  pointer-events: none;
}
.toast {
  background: var(--color-navy);
  color: var(--color-white);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  pointer-events: auto;
  animation: toast-in 0.25s ease both;
  min-width: 240px;
}
.toast--success { background: var(--color-success); }
.toast--error   { background: var(--color-error); }
.toast--warning { background: var(--color-warning); }
.toast .icon { width: 18px; height: 18px; flex: 0 0 auto; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============== Skeletons ============== */
.skeleton {
  background: linear-gradient(90deg, var(--color-light-2) 0%, var(--color-light) 50%, var(--color-light-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.2s ease infinite;
  border-radius: var(--radius-sm);
  display: block;
  height: 14px;
}
@keyframes skeleton-shine {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============== Helpers de spacing ============== */
.stack > * + * { margin-top: var(--space-3); }
.stack-sm > * + * { margin-top: var(--space-2); }
.stack-lg > * + * { margin-top: var(--space-5); }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
.between { justify-content: space-between; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-sm   { font-size: var(--fs-14); }
.text-xs   { font-size: var(--fs-12); }
.fw-semibold { font-weight: var(--fw-semibold); }
.fw-bold { font-weight: var(--fw-bold); }
.uppercase { text-transform: uppercase; letter-spacing: var(--ls-wide); }

.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-4) 0;
  border: 0;
}
