/* TorresHub — componentes reutilizables del portal. Complementa system.css. */

/* Cards de página */
.th-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-1);
    margin-bottom: 24px;
}
.th-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    gap: 16px;
    flex-wrap: wrap;
}
.th-card-head h2, .th-card-head h3 {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 400;
    letter-spacing: -0.01em;
    margin: 0;
}
.th-card-head .th-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* KPI grid */
.th-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}
.th-kpi {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-1);
}
.th-kpi-label {
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-400);
    margin-bottom: 12px;
}
.th-kpi-value {
    font-family: var(--font-display);
    font-size: 42px;
    font-weight: 400;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink-900);
    font-variant-numeric: tabular-nums;
}
.th-kpi-foot {
    margin-top: 12px;
    font-size: 13px;
    color: var(--ink-500);
}

/* Filtros */
.th-filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 20px;
}
.th-filters .th-input,
.th-filters select.th-input {
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    min-width: 160px;
}
.th-filters label {
    font-size: 12px;
    color: var(--ink-500);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Inputs en forma */
.th-input {
    font: inherit;
    font-size: 15px;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--ink-900);
    transition: border-color var(--dur-fast) var(--ease);
    outline: none;
    width: 100%;
}
.th-input:focus {
    border-color: var(--gold-500);
    box-shadow: var(--shadow-focus);
}
.th-input:disabled {
    background: var(--bone-100);
    color: var(--ink-400);
    cursor: not-allowed;
}
textarea.th-input {
    min-height: 120px;
    font-family: inherit;
    resize: vertical;
}
select.th-input {
    appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236D7688' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

/* Form layout */
.th-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.th-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}
@media (max-width: 640px) {
    .th-form-row { grid-template-columns: 1fr; }
}
.th-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.th-field-label {
    font-size: 12px;
    color: var(--ink-500);
    font-weight: 500;
    letter-spacing: 0.02em;
}
.th-field-help {
    font-size: 12px;
    color: var(--ink-400);
}
.th-field-error-msg {
    font-size: 12px;
    color: var(--err-500);
    min-height: 1em;
}
.th-field-error .th-input {
    border-color: var(--err-500);
}

/* Checkbox / switch */
.th-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--ink-700);
}
.th-checkbox input {
    width: 18px;
    height: 18px;
    accent-color: var(--gold-500);
}

/* Empty */
.th-empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--ink-400);
}
.th-empty h3 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 400;
    color: var(--ink-700);
    margin: 0 0 8px;
}
.th-empty p {
    margin: 0;
    font-size: 14px;
}

/* Toasts */
.th-toast-stack {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
}
.th-toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    box-shadow: var(--shadow-2);
    font-size: 14px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
    animation: thToastIn var(--dur-base) var(--ease);
}
@keyframes thToastIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.th-toast-ok { border-left: 4px solid var(--ok-500); }
.th-toast-err { border-left: 4px solid var(--err-500); }
.th-toast-info { border-left: 4px solid var(--info-500); }
.th-toast-warn { border-left: 4px solid var(--warn-500); }

/* Modal */
.th-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 24, 31, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 24px;
}
.th-modal-overlay.open {
    display: flex;
    animation: thFadeIn var(--dur-fast) var(--ease);
}
@keyframes thFadeIn {
    from { opacity: 0; } to { opacity: 1; }
}
.th-modal-card {
    width: 100%;
    max-width: 560px;
    background: var(--surface-2);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    max-height: 90vh;
    overflow: auto;
    display: flex;
    flex-direction: column;
}
.th-modal-card.lg { max-width: 800px; }
.th-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}
.th-modal-head h3 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 400;
}
.th-modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-400);
    font-size: 22px;
    cursor: pointer;
}
.th-modal-close:hover {
    background: var(--bone-100);
    color: var(--ink-900);
}
.th-modal-body { padding: 24px; }
.th-modal-foot {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface-1);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Loading */
.th-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: thSpin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes thSpin { to { transform: rotate(360deg); } }
.th-loading { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-500); }

/* Table override helpers */
.th-actions {
    display: inline-flex;
    gap: 6px;
}
.th-actions .btn-sm { height: 30px; padding: 0 10px; }
.th-tbl-wrap {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin-bottom: 24px;
}
.th-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.th-tbl thead th {
    background: var(--bone-100);
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-400);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}
.th-tbl td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--ink-700);
}
.th-tbl tbody tr:last-child td { border-bottom: 0; }
.th-tbl tbody tr:hover { background: var(--bone-100); }

/* Pagination */
.th-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface-1);
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--ink-500);
}
.th-pagination-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Badge con prefijo de ícono */
.th-badge-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--ink-500);
}
.th-badge-dot::before {
    content: "";
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: currentColor;
}

/* Detail grid (key/value) */
.th-kv-grid {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 10px 24px;
    font-size: 14px;
}
.th-kv-grid dt {
    color: var(--ink-400);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.th-kv-grid dd {
    margin: 0;
    color: var(--ink-900);
}
@media (max-width: 640px) {
    .th-kv-grid { grid-template-columns: 1fr; gap: 4px 0; }
    .th-kv-grid dd { margin-bottom: 12px; }
}

/* Utility */
.th-mb-0 { margin-bottom: 0 !important; }
.th-mt-24 { margin-top: 24px !important; }
.th-text-muted { color: var(--ink-400); }
.th-text-right { text-align: right; }
.th-hidden { display: none !important; }

/* Grids auxiliares */
.th-grid-2 {
    display: grid; gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.th-grid-3 {
    display: grid; gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

/* Tarjeta de acceso rápido (dashboards) */
.th-quick-card {
    display: flex; align-items: center; gap: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-decoration: none;
    color: inherit;
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    box-shadow: var(--shadow-1);
}
.th-quick-card:hover {
    border-color: var(--gold-500, var(--border-strong));
    box-shadow: var(--shadow-2, var(--shadow-1));
}
.th-quick-icon {
    font-size: 32px; line-height: 1;
    flex-shrink: 0;
}
.th-quick-card h3 { margin: 0 0 4px; font-size: 16px; }
.th-quick-card p { margin: 0; color: var(--ink-400); font-size: 13px; }

.th-kpi-sub {
    margin-top: 8px;
    font-size: 12px;
    color: var(--ink-400);
}

.th-inline-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.th-inline-row:last-child { border-bottom: 0; }
