/* ══════════════════════════════════════════════════════════════
   AIPA License Manager — Components
   Buttons, Forms, Badges, Tables (Azure / Fluent Design)
   ══════════════════════════════════════════════════════════════ */

/* ── Section title (cabeceras centrables en flujos de contenido) ── */
.section-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  text-align: center;
  max-width: 42rem;
  margin-left: auto;
  margin-right: auto;
}

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 0 auto 20px;
  max-width: 900px;
  width: 100%;
  box-sizing: border-box;
}
.form-grid.single {
  grid-template-columns: 1fr;
  max-width: 560px;
}

/* Admin: forms use full width (no centered column) */
.layout .main .form-grid,
.layout .main .form-grid.single {
  max-width: none;
  margin-left: 0;
  margin-right: 0;
}

.field > label {
  display: block;
  font-size: .85rem;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
}
.input-with-unit {
  display: flex;
  gap: 6px;
}
.input-with-unit input {
  flex: 1;
  min-width: 0;
}
.input-with-unit select,
.input-with-unit .fs-wrap {
  width: auto;
  min-width: 120px;
  max-width: 160px;
  flex-shrink: 0;
}

.field-hint {
  color: var(--text-3);
  font-size: .8rem;
  margin-top: 4px;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: #FAFAF9;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: .9rem;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: none;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
input:focus:not(:focus-visible), select:focus:not(:focus-visible), textarea:focus:not(:focus-visible) {
  outline: none;
}
textarea { resize: vertical; min-height: 80px; }
select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23A19F9D'%3E%3Cpath d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .1s ease, border-color .1s ease, color .1s ease;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

/* Secondary / outline: neutral border (admin + shared) */
.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--text-3);
  color: var(--text);
}

/* Sin borde, texto secundario */
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--border-light);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: #A4262C;
  border-color: #A4262C;
}

.btn-sm { padding: 3px 8px; font-size: .72rem; }
.btn-xs { padding: 2px 6px; font-size: .68rem; border-radius: var(--radius-sm); }

/* Icon-only action button (no text — tooltip via title) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background-color .1s ease, border-color .1s ease, color .1s ease;
  flex-shrink: 0;
  box-sizing: border-box;
}
.btn-icon:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text-3);
}
.btn-icon:disabled { opacity: .35; cursor: not-allowed; }
.btn-icon svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-icon.danger {
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn-icon.danger:hover:not(:disabled) {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}
.btn-icon.success {
  color: var(--success);
  border-color: rgba(16, 124, 16, 0.35);
}
.btn-icon.success:hover:not(:disabled) {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
}
.btn-icon.primary {
  color: var(--primary);
  border-color: var(--primary-light);
}
.btn-icon.primary:hover:not(:disabled) {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary);
}

/* Ghost variant: transparent border until hover */
.btn-icon.btn-ghost {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
}
.btn-icon.btn-ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-icon.btn-ghost svg { width: 14px; height: 14px; }

/* Misma caja que .btn cuando solo se usa .btn-primary / .btn-ghost / … (zona cliente) */
button.btn-primary:not(.btn):not(.btn-icon),
a.btn-primary:not(.btn):not(.btn-icon),
button.btn-outline:not(.btn):not(.btn-icon),
a.btn-outline:not(.btn):not(.btn-icon),
button.btn-ghost:not(.btn):not(.btn-icon),
a.btn-ghost:not(.btn):not(.btn-icon),
button.btn-danger:not(.btn):not(.btn-icon),
a.btn-danger:not(.btn):not(.btn-icon) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .1s ease, border-color .1s ease, color .1s ease;
  text-decoration: none;
  box-sizing: border-box;
}
a.btn-primary:not(.btn):not(.btn-icon),
a.btn-outline:not(.btn):not(.btn-icon),
a.btn-ghost:not(.btn):not(.btn-icon) {
  line-height: 1.25;
}

.actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Badges (admin + zona cliente, mismos colores) ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: .75rem;
  font-weight: 600;
  line-height: 1;
  vertical-align: middle;
}
.badge-active,
.badge-paid {
  background: var(--success-bg);
  color: var(--success);
}
.badge-pending,
.badge-draft,
.badge-pending_payment {
  background: var(--warn-bg);
  color: #8A6534;
}
.badge-expired,
.badge-overdue {
  background: var(--danger-bg);
  color: var(--danger);
}
.badge-suspended {
  background: #FFF4CE;
  color: #8A6D3B;
}
.badge-inactive,
.badge-cancelled,
.badge-revoked {
  background: var(--border-light);
  color: var(--text-2);
}
/* Semántica admin legada / extras */
.badge-posted {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ── Result Box ── */
.result {
  margin-top: 16px;
  margin-left: auto;
  margin-right: auto;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  display: none;
  max-width: 900px;
  width: 100%;
  box-sizing: border-box;
}

.layout .main .result {
  margin-left: 0;
  margin-right: 0;
  max-width: none;
}
.result.show { display: block; }
.result.success {
  background: var(--success-bg);
  border: 1px solid rgba(16, 124, 16, 0.25);
  color: #0B5A08;
}
.result.error {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: #A4262C;
}
.result pre {
  margin-top: 8px;
  padding: 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--text);
  max-height: 200px;
}
.result .dl-bar { margin-top: 8px; display: flex; gap: 8px; }
.lic-created-row {
  display: flex; align-items: center; gap: 12px;
}
.lic-created-row .btn { flex-shrink: 0; white-space: nowrap; }
.lic-created-info {
  font-size: .82rem; line-height: 1.4;
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}

/* ── Key Box ── */
.key-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 12px auto;
  max-width: 900px;
  width: 100%;
  box-sizing: border-box;
  box-shadow: var(--shadow);
}

.layout .main .key-box {
  margin-left: 0;
  margin-right: 0;
  max-width: none;
}
.key-box pre {
  font-family: var(--mono);
  font-size: .85rem;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-2);
  margin-top: 4px;
}
.key-box .kb-label { font-weight: 600; font-size: .85rem; color: var(--text); }

/* ── Warning Banner ── */
.warn-banner {
  background: var(--warn-bg);
  border: 1px solid rgba(255, 185, 0, 0.45);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  margin-left: auto;
  margin-right: auto;
  max-width: 900px;
  width: 100%;
  box-sizing: border-box;
  font-size: .9rem;
  color: #605E5C;
}

.layout .main .warn-banner {
  margin-left: 0;
  margin-right: 0;
  max-width: none;
}
.warn-banner strong { color: var(--text); }
.warn-banner code {
  background: var(--border-light);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: .85rem;
  border: 1px solid var(--border);
}

/* ── Tables (compact) ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .78rem;
}
th, td {
  padding: 10px 12px;
  height: auto;
  min-height: 22px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  line-height: 1.35;
}
th {
  font-weight: 600;
  color: var(--text-3);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .3px;
}
thead th {
  background: transparent;
}
tr:hover { background: var(--bg); }

/* Scroll horizontal en tablas anchas (envolver con .table-scroll o .table-wrap) */
.table-scroll,
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar {
  height: 4px;
}
.table-scroll::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-sm);
}

/* ── Tablas unificadas (.aipa-table + alias .cz-table en cliente) ── */
.aipa-table,
.cz-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.aipa-table th,
.cz-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  background: transparent;
}
.aipa-table td,
.cz-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  font-size: 13px;
}
.aipa-table tbody tr:nth-child(even),
.cz-table tbody tr:nth-child(even) {
  background: transparent;
}
.aipa-table tbody tr:hover td,
.cz-table tbody tr:hover td {
  background: var(--bg);
}
.aipa-table tbody tr:last-child td,
.cz-table tbody tr:last-child td {
  border-bottom: none;
}
.aipa-table code,
.cz-table code,
table code,
.od-kv-value code,
.modal-content code {
  font-size: inherit;
  color: var(--primary, #0078D4);
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  display: inline;
}

/* ── Tarjeta y estados vacíos / carga (compartidos) ── */
.aipa-card,
.cz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
}
.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: .3;
}
.empty-state h3 {
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}
.empty-state p {
  font-size: .78rem;
  color: var(--text-2);
}

.aipa-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: aipa-spin .6s linear infinite;
}

/* ── KPI cards (shared between admin and client zone) ── */
.purchases-stats-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.po-kpi {
  display: flex; align-items: center; gap: 10px;
  background: var(--card-bg, #fff); border: 1px solid var(--border-light, #EDEBE9);
  border-radius: 6px; padding: 10px 14px; flex: 1 1 150px; min-width: 130px;
}
.po-kpi-icon {
  width: 32px; height: 32px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.po-kpi-icon--revenue  { background: #E5F1FB; color: #0078D4; }
.po-kpi-icon--orders   { background: #F3F2F1; color: #605E5C; }
.po-kpi-icon--completed{ background: #DFF6DD; color: #107C10; }
.po-kpi-icon--pending  { background: #FFF4CE; color: #986F0B; }
.po-kpi-icon--failed   { background: #FDE7E9; color: #C4314B; }
.po-kpi-body { min-width: 0; }
.po-kpi-value { font-size: 1.05rem; font-weight: 700; color: var(--text-1, #323130); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.po-kpi-label { font-size: .68rem; color: var(--text-2, #605E5C); line-height: 1.3; }

/* ── KPI / métricas (panel admin): inline text style ── */
.main .stats-bar {
  width: 100%;
  max-width: none;
  margin: 0 0 12px;
  box-sizing: border-box;
}

/* ── Admin header global search ── */
.global-search {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  width: 260px;
  max-width: min(260px, 100%);
  flex-shrink: 0;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
}
.global-search:focus {
  border-color: var(--primary);
  box-shadow: none;
}
.global-search:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.global-search:focus:not(:focus-visible) {
  outline: none;
}

/* ── Dev-only blocks (e.g. reset all data); show via DevTools if needed ── */
.dev-only {
  display: none;
}


/* ── Responsive ── */
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 580px) {
  .form-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

@media (max-width: 768px) {
  .btn:not(.btn-icon) {
    min-height: 44px;
    padding: 10px 16px;
    font-size: .85rem;
  }
  .btn-sm:not(.btn-icon) {
    min-height: 44px;
    padding: 10px 14px;
  }
  .btn-icon {
    width: 28px;
    height: 28px;
  }
}

/* ── Form validation helpers ── */
.input-error {
  border-color: var(--danger) !important;
  box-shadow: none !important;
}
.input-error:focus-visible {
  outline: 2px solid var(--danger);
  outline-offset: 1px;
}
.input-hint { font-size: .7rem; color: var(--text-3); margin-top: 2px; }
.input-hint.error { color: var(--danger); }
.field-error { display: none; font-size: .72rem; color: var(--danger); margin-top: 3px; line-height: 1.35; }
.field-error-msg {
  display: none;
  font-size: 0.72rem;
  color: var(--danger);
  margin-top: 3px;
  line-height: 1.35;
  font-weight: 500;
}
.field-error-msg.show { display: block; }
.btn-loading { opacity: .7; pointer-events: none; }
.btn-loading:has(.spinner)::after { display: none; }
.btn-loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: aipa-spin .5s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}
@keyframes aipa-spin { to { transform: rotate(360deg); } }

/* ── Admin (index): bloques tipo tarjeta — alineado con spec (admin.css base) ── */
.layout .main .admin-panel-block,
.layout .main .inline-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.layout .main .chart-card,
.layout .main .timeline,
.layout .main .clients-grid {
  border-color: var(--border);
  box-shadow: var(--shadow);
  padding: 16px 20px;
}

/* Tablas en main: mismo ritmo que tablas globales / .aipa-table */
.layout .main table thead th {
  padding: 10px 12px;
  height: auto;
  min-height: 22px;
  line-height: 1.35;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-3);
  background: transparent;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.layout .main table tbody td {
  padding: 10px 12px;
  height: auto;
  min-height: 22px;
  line-height: 1.35;
  font-size: .78rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
.layout .main table tbody tr:hover {
  background: var(--bg);
}

/* ── Phone prefix input row ───────────────────────────────────────────────── */
.phone-input-row { display: flex !important; flex-direction: row !important; gap: 6px; align-items: stretch; }
.phone-input-row input[type="tel"] { flex: 1 1 auto !important; min-width: 0 !important; width: auto !important; }

/* ── Custom phone-prefix dropdown (ppd) ──────────────────────────────────── */
.ppd-wrap {
  position: relative; display: inline-flex; align-items: center;
  flex: 0 0 auto !important; width: auto !important; min-width: 0 !important;
}
.ppd-wrap > select.phone-prefix-select { display: none !important; }
.ppd-trigger {
  display: inline-flex !important; align-items: center; gap: 5px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-size: .82rem; cursor: pointer; white-space: nowrap; line-height: 1.4;
  height: 100%; width: auto !important;
}
.ppd-trigger:hover { border-color: var(--primary); }
.ppd-trigger:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.ppd-trigger .ppd-flag { border-radius: var(--radius-sm); vertical-align: middle; flex-shrink: 0; }
.ppd-list {
  display: none !important; position: absolute; top: 100%; left: 0; z-index: 9999;
  margin-top: 2px; max-height: 240px; overflow-y: auto;
  min-width: 110px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  scrollbar-width: thin;
}
.ppd-list::-webkit-scrollbar { width: 5px; }
.ppd-list::-webkit-scrollbar-thumb { background: rgba(161, 159, 157, 0.6); border-radius: var(--radius-sm); }
.ppd-wrap.ppd-open .ppd-list { display: block !important; }
.ppd-option {
  display: flex !important; align-items: center; gap: 6px;
  padding: 6px 10px; cursor: pointer; font-size: .82rem;
  white-space: nowrap; color: var(--text);
}
.ppd-option:hover { background: var(--bg); }
.ppd-option.ppd-selected { background: var(--primary-light); font-weight: 600; color: var(--primary-dark); }
.ppd-option .ppd-flag { border-radius: var(--radius-sm); vertical-align: middle; flex-shrink: 0; }

/* Filterable select trigger: .fs-display sets outline:none; restore keyboard ring */
button.fs-display:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ─── Licence expiry indicator (shared admin + client) ─────────── */
.lic-expiry-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.6875rem; font-weight: 600; padding: 2px 6px;
  border-radius: 3px; white-space: nowrap;
}
.lic-expiry-tag--ok     { background: #F0FDF4; color: #059669; }
.lic-expiry-tag--warn   { background: #FFFBEB; color: #D97706; }
.lic-expiry-tag--danger { background: #FEF2F2; color: #A4262C; }
